Skip to content

Commit

Permalink
fix: add wait for disconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-yarmosh committed Mar 14, 2024
1 parent a31071d commit f946bae
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
3 changes: 3 additions & 0 deletions test-e2e/tests/mtr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ describe('mtr mesurement', () => {
} }).json();

const response = await waitMesurementFinish(id);
console.log('response');
console.log(response);
console.log(response.body.results[0].result);

expect(response.body.status).to.equal('finished');
expect(response.body.results[0].result.status).to.equal('finished');
Expand Down
6 changes: 2 additions & 4 deletions test-e2e/tests/offline-probes.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import got from 'got';
import { expect } from 'chai';

import { waitMesurementFinish, waitProbeToConnect } from '../utils.js';
import { waitMesurementFinish, waitProbeToConnect, waitProbeToDisconnect } from '../utils.js';
import { docker } from '../docker.js';

describe('api', () => {
Expand All @@ -22,18 +22,16 @@ describe('api', () => {
} }).json();

await docker.stopProbeContainer();
await waitProbeToDisconnect();

const { id } = await got.post('http://localhost:80/v1/measurements', { json: {
target: 'www.jsdelivr.com',
type: 'ping',
locations: locationId,
} }).json();

console.log('measurement id:', id, new Date());
const response = await waitMesurementFinish(id);

console.log(1, new Date());
console.log('response.body', response.body, new Date());
expect(response.body.status).to.equal('finished');
expect(response.body.results[0].result.status).to.equal('offline');
expect(response).to.matchApiSchema();
Expand Down
23 changes: 20 additions & 3 deletions test-e2e/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,26 @@ import { scopedLogger } from '../src/lib/logger.js';

const logger = scopedLogger('e2e-utils');

export const waitProbeToDisconnect = async () => {
let response;

for (;;) {
try {
response = await got<any>('http://localhost:80/v1/probes', { responseType: 'json' });
} catch (err) {
logger.info((err as RequestError).code);
await setTimeout(1000);
continue;
}

if (response.body.length === 0) {
return;
}

await setTimeout(1000);
}
};

export const waitProbeToConnect = async () => {
let response;

Expand Down Expand Up @@ -47,9 +67,6 @@ export const waitMesurementFinish = async (id: string) => {
for (;;) {
const response = await got<any>(`http://localhost:80/v1/measurements/${id}`, { responseType: 'json' });

console.log('id', id, new Date());
console.log('response.body.status', response.body.status, new Date());

if (response.body.status !== 'in-progress') {
logger.info('return');
return response;
Expand Down

0 comments on commit f946bae

Please sign in to comment.