Skip to content

Commit

Permalink
test: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-yarmosh committed Apr 9, 2024
1 parent a8f0c79 commit ff6dc9c
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 19 deletions.
13 changes: 2 additions & 11 deletions src/lib/probe-override.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
import type { Knex } from 'knex';
import { getIndex } from '../probe/builder.js';
import type { Probe } from '../probe/types.js';
import { AdoptedProbes } from './adopted-probes.js';
import type { fetchRawProbes as serverFetchRawProbes } from './ws/server.js';
import type { AdoptedProbes } from './adopted-probes.js';

export class ProbeOverride {
private readonly adoptedProbes: AdoptedProbes;

constructor (
private readonly sql: Knex,
private readonly fetchRawProbes: typeof serverFetchRawProbes,
) {
this.adoptedProbes = new AdoptedProbes(this.sql, this.fetchRawProbes);
}
constructor (private readonly adoptedProbes: AdoptedProbes) {}

async syncDashboardData () {
await this.adoptedProbes.syncDashboardData();
Expand Down
5 changes: 4 additions & 1 deletion src/lib/ws/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { SyncedProbeList } from './synced-probe-list.js';
import { client } from '../sql/client.js';
import { ProbeOverride } from '../probe-override.js';
import { ProbeIpLimit } from './helper/probe-ip-limit.js';
import { AdoptedProbes } from '../adopted-probes.js';

export type SocketData = {
probe: Probe;
Expand Down Expand Up @@ -91,6 +92,8 @@ export const fetchRawProbes = async (): Promise<Probe[]> => {
return syncedProbeList.getRawProbes();
};

export const probeOverride = new ProbeOverride(client, fetchRawProbes);
export const adoptedProbes = new AdoptedProbes(client, fetchRawProbes);

export const probeOverride = new ProbeOverride(adoptedProbes);

export const probeIpLimit = new ProbeIpLimit(fetchProbes, fetchRawSockets);
8 changes: 4 additions & 4 deletions test/tests/integration/measurement/create-measurement.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ import nock from 'nock';
import type { Socket } from 'socket.io-client';
import nockGeoIpProviders from '../../../utils/nock-geo-ip.js';
import { client } from '../../../../src/lib/sql/client.js';
import type { AdoptedProbes } from '../../../../src/lib/adopted-probes.js';
import type { ProbeOverride } from '../../../../src/lib/probe-override.js';
import { waitForProbesUpdate } from '../../../utils/server.js';

describe('Create measurement', () => {
let addFakeProbe: () => Promise<Socket>;
let deleteFakeProbes: () => Promise<void>;
let getTestServer;
let requestAgent: Agent;
let adoptedProbes: AdoptedProbes;
let probeOverride: ProbeOverride;
let ADOPTED_PROBES_TABLE: string;

before(async () => {
await td.replaceEsm('../../../../src/lib/ip-ranges.ts', { getRegion: () => 'gcp-us-west4', populateMemList: () => Promise.resolve() });
({ getTestServer, addFakeProbe, deleteFakeProbes } = await import('../../../utils/server.js'));
({ ADOPTED_PROBES_TABLE } = await import('../../../../src/lib/adopted-probes.js'));
({ adoptedProbes } = await import('../../../../src/lib/ws/server.js'));
({ probeOverride } = await import('../../../../src/lib/ws/server.js'));
const app = await getTestServer();
requestAgent = request(app);
});
Expand Down Expand Up @@ -666,7 +666,7 @@ describe('Create measurement', () => {
asn: 61004,
});

await adoptedProbes.syncDashboardData();
await probeOverride.syncDashboardData();
await waitForProbesUpdate();
});

Expand Down
4 changes: 2 additions & 2 deletions test/tests/integration/probes/get-probes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import request, { type Agent } from 'supertest';
import { getTestServer, addFakeProbe, deleteFakeProbes, waitForProbesUpdate } from '../../../utils/server.js';
import nockGeoIpProviders from '../../../utils/nock-geo-ip.js';
import { ADOPTED_PROBES_TABLE } from '../../../../src/lib/adopted-probes.js';
import { adoptedProbes } from '../../../../src/lib/ws/server.js';
import { probeOverride } from '../../../../src/lib/ws/server.js';
import { client } from '../../../../src/lib/sql/client.js';

describe('Get Probes', () => {
Expand Down Expand Up @@ -290,7 +290,7 @@ describe('Get Probes', () => {
asn: 61004,
});

await adoptedProbes.syncDashboardData();
await probeOverride.syncDashboardData();
});

after(async () => {
Expand Down
4 changes: 3 additions & 1 deletion test/tests/unit/ws/synced-probe-list.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { type AdoptedProbe, AdoptedProbes } from '../../../../src/lib/adopted-pr
import type { Probe } from '../../../../src/probe/types.js';
import { getRegionByCountry } from '../../../../src/lib/location/location.js';
import { getRedisClient } from '../../../../src/lib/redis/client.js';
import { ProbeOverride } from '../../../../src/lib/probe-override.js';

describe('SyncedProbeList', () => {
const sandbox = sinon.createSandbox();
Expand Down Expand Up @@ -35,6 +36,7 @@ describe('SyncedProbeList', () => {
} as unknown as WsServerNamespace;

const adoptedProbes = sandbox.createStubInstance(AdoptedProbes);
const probeOverride = new ProbeOverride(adoptedProbes);

let syncedProbeList: SyncedProbeList;

Expand All @@ -46,7 +48,7 @@ describe('SyncedProbeList', () => {
adoptedProbes.getUpdatedLocation.callThrough();
adoptedProbes.getUpdatedTags.callThrough();

syncedProbeList = new SyncedProbeList(redisClient, ioNamespace, adoptedProbes);
syncedProbeList = new SyncedProbeList(redisClient, ioNamespace, probeOverride);
});

afterEach(() => {
Expand Down

0 comments on commit ff6dc9c

Please sign in to comment.