Skip to content

Commit

Permalink
feat: calculate number of responses dynamically
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-yarmosh committed Mar 27, 2024
1 parent 70f4809 commit f7455bd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 21 deletions.
3 changes: 1 addition & 2 deletions test/e2e/cases/adopted-probes.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import got from 'got';
import { expect } from 'chai';
import { client } from '../../../src/lib/sql/client.js';
import { ADOPTED_PROBES_TABLE } from '../../../src/lib/adopted-probes.js';
import { waitProbeInCity } from '../utils.js';

const ADOPTED_PROBES_TABLE = 'gp_adopted_probes';

describe('adopted probe', () => {
before(async function () {
this.timeout(80000);
Expand Down
26 changes: 8 additions & 18 deletions test/e2e/utils.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import config from 'config';
import got, { type RequestError } from 'got';
import _ from 'lodash';
import { setTimeout } from 'timers/promises';
import { scopedLogger } from '../../src/lib/logger.js';

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

const processes = config.get<number>('server.processes');
logger.info(`There are ${processes} workers running.`);

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

for (;;) {
try {
responses = await Promise.all([
got<any>('http://localhost:80/v1/probes', { responseType: 'json' }),
got<any>('http://localhost:80/v1/probes', { responseType: 'json' }),
got<any>('http://localhost:80/v1/probes', { responseType: 'json' }),
got<any>('http://localhost:80/v1/probes', { responseType: 'json' }),
]);
responses = await Promise.all(_.times(processes * 2, (() => got<any>('http://localhost:80/v1/probes', { responseType: 'json' }))));
} catch (err) {
logger.info((err as RequestError).code);
await setTimeout(1000);
Expand All @@ -34,12 +34,7 @@ export const waitProbeToConnect = async () => {

for (;;) {
try {
responses = await Promise.all([
got<any>('http://localhost:80/v1/probes', { responseType: 'json' }),
got<any>('http://localhost:80/v1/probes', { responseType: 'json' }),
got<any>('http://localhost:80/v1/probes', { responseType: 'json' }),
got<any>('http://localhost:80/v1/probes', { responseType: 'json' }),
]);
responses = await Promise.all(_.times(processes * 2, (() => got<any>('http://localhost:80/v1/probes', { responseType: 'json' }))));
} catch (err) {
logger.info((err as RequestError).code);
await setTimeout(1000);
Expand All @@ -59,12 +54,7 @@ export const waitProbeInCity = async (city: string) => {

for (;;) {
try {
responses = await Promise.all([
got<any>('http://localhost:80/v1/probes', { responseType: 'json' }),
got<any>('http://localhost:80/v1/probes', { responseType: 'json' }),
got<any>('http://localhost:80/v1/probes', { responseType: 'json' }),
got<any>('http://localhost:80/v1/probes', { responseType: 'json' }),
]);
responses = await Promise.all(_.times(processes * 2, (() => got<any>('http://localhost:80/v1/probes', { responseType: 'json' }))));
} catch (err) {
logger.info((err as RequestError).code);
throw err;
Expand Down
1 change: 0 additions & 1 deletion wallaby.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export default function wallaby () {
'public/v1/*',
'public/**/*.yaml',
'test/plugins/**/*',
'test/e2e/client.ts',
'test/e2e/setup.ts',
'test/e2e/utils.ts',
'test/e2e/docker.ts',
Expand Down

0 comments on commit f7455bd

Please sign in to comment.