Adjust endpoints tests (#9113)

This commit is contained in:
Jaco 2023-03-06 07:20:00 +02:00 committed by GitHub
parent 74072b9bfd
commit 266d931665
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 11 deletions

View File

@ -4,7 +4,7 @@ on:
- cron: '50 0/12 * * *' - cron: '50 0/12 * * *'
jobs: jobs:
types: endpoints:
if: github.repository == 'polkadot-js/apps' if: github.repository == 'polkadot-js/apps'
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:

View File

@ -19,6 +19,10 @@ interface DnsResponse {
const TIMEOUT = 60_000; const TIMEOUT = 60_000;
function noopHandler () {
// ignore
}
describe('check endpoints', (): void => { describe('check endpoints', (): void => {
const checks = createWsEndpoints() const checks = createWsEndpoints()
.filter(({ isDisabled, isUnreachable, value }) => .filter(({ isDisabled, isUnreachable, value }) =>
@ -39,34 +43,34 @@ describe('check endpoints', (): void => {
let websocket: WebSocket | null = null; let websocket: WebSocket | null = null;
afterEach((): void => { afterEach((): void => {
completed++;
if (websocket) { if (websocket) {
websocket.onclose = null; websocket.onclose = noopHandler;
websocket.onerror = null; websocket.onerror = noopHandler;
websocket.onopen = null; websocket.onopen = noopHandler;
websocket.onmessage = null; websocket.onmessage = noopHandler;
try { try {
websocket.close(); websocket.close();
} catch { } catch (e) {
// ignore console.error((e as Error).message);
} }
websocket = null; websocket = null;
} }
completed++;
if (completed === checks.length) { if (completed === checks.length) {
process.exit(errored); process.exit(errored);
} }
}); });
for (const { name, ws: endpoint } of checks) { for (const { name, ws: endpoint } of checks) {
it(`${name} @ ${endpoint}`, async (): Promise<unknown> => { it(`${name} @ ${endpoint}`, async (): Promise<void> => {
const [,, hostWithPort] = endpoint.split('/'); const [,, hostWithPort] = endpoint.split('/');
const [host] = hostWithPort.split(':'); const [host] = hostWithPort.split(':');
return fetchJson<DnsResponse>(`https://dns.google/resolve?name=${host}`) await fetchJson<DnsResponse>(`https://dns.google/resolve?name=${host}`)
.then((json) => .then((json) =>
assert(json && json.Answer, 'No DNS entry') assert(json && json.Answer, 'No DNS entry')
) )