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 * * *'
jobs:
types:
endpoints:
if: github.repository == 'polkadot-js/apps'
runs-on: ubuntu-latest
steps:

View File

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