Skip to content

Commit

Permalink
feat: send adoption status to the probe
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-yarmosh committed Oct 30, 2024
1 parent f474aaa commit 5ea5123
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/lib/ws/gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { handleStatusUpdate } from '../../probe/handler/status.js';
import { handleDnsUpdate } from '../../probe/handler/dns.js';
import { handleStatsReport } from '../../probe/handler/stats.js';
import { scopedLogger } from '../logger.js';
import { probeOverride, getWsServer, PROBES_NAMESPACE, ServerSocket } from './server.js';
import { probeOverride, getWsServer, PROBES_NAMESPACE, ServerSocket, adoptedProbes } from './server.js';
import { probeMetadata } from './middleware/probe-metadata.js';
import { errorHandler } from './helper/error-handler.js';
import { subscribeWithHandler } from './helper/subscribe-handler.js';
Expand All @@ -23,6 +23,7 @@ io
.on('connect', errorHandler(async (socket: ServerSocket) => {
const probe = socket.data.probe;
const location = probeOverride.getUpdatedLocation(probe);
const isAdopted = !!adoptedProbes.getByIp(probe.ipAddress);

socket.emit('api:connect:alt-ips-token', {
token: await getAltIpsClient().generateToken(socket),
Expand All @@ -31,6 +32,7 @@ io
});

socket.emit('api:connect:location', location);
socket.emit('api:connect:adoption', { isAdopted });
logger.info(`ws client ${socket.id} connected from ${location.city}, ${location.country} [${probe.ipAddress} - ${location.network}]`);

// Handlers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('Create measurement request', () => {

const sandbox = sinon.createSandbox();
const locationHandlerStub = sandbox.stub();
const adoptionHandlerStub = sandbox.stub();
const requestHandlerStub = sandbox.stub();
const cryptoRandomString = sandbox.stub().returns('measurementid');

Expand All @@ -34,6 +35,7 @@ describe('Create measurement request', () => {

probe = await addFakeProbe({
'api:connect:location': locationHandlerStub,
'api:connect:adoption': adoptionHandlerStub,
'probe:measurement:request': requestHandlerStub,
});
});
Expand Down Expand Up @@ -75,6 +77,9 @@ describe('Create measurement request', () => {
network: 'The Constant Company LLC',
normalizedNetwork: 'the constant company llc',
}]);

expect(adoptionHandlerStub.callCount).to.equal(1);
expect(adoptionHandlerStub.firstCall.args).to.deep.equal([{ isAdopted: false }]);
});

it('should send and handle proper events during measurement request', async () => {
Expand Down

0 comments on commit 5ea5123

Please sign in to comment.