-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: set expire to gp:test-to-probe hSet
- Loading branch information
1 parent
f28a6f6
commit 9230710
Showing
7 changed files
with
73 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import type { Probe } from '../../probe/types.js'; | ||
import type { MeasurementProgressMessage } from '../types.js'; | ||
import { getMeasurementRunner } from '../runner.js'; | ||
import { probeValidator } from '../../lib/probe-validator.js'; | ||
import { getProbeValidator } from '../../lib/probe-validator.js'; | ||
|
||
const runner = getMeasurementRunner(); | ||
|
||
export const handleMeasurementProgress = (probe: Probe) => async (data: MeasurementProgressMessage): Promise<void> => { | ||
await probeValidator.validateProbe(data.measurementId, data.testId, probe.uuid); | ||
await getProbeValidator().validateProbe(data.measurementId, data.testId, probe.uuid); | ||
await runner.recordProgress(data); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import type { Probe } from '../../probe/types.js'; | ||
import type { MeasurementResultMessage } from '../types.js'; | ||
import { getMeasurementRunner } from '../runner.js'; | ||
import { probeValidator } from '../../lib/probe-validator.js'; | ||
import { getProbeValidator } from '../../lib/probe-validator.js'; | ||
|
||
const runner = getMeasurementRunner(); | ||
|
||
export const handleMeasurementResult = (probe: Probe) => async (data: MeasurementResultMessage): Promise<void> => { | ||
await probeValidator.validateProbe(data.measurementId, data.testId, probe.uuid); | ||
await getProbeValidator().validateProbe(data.measurementId, data.testId, probe.uuid); | ||
await runner.recordResult(data); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,41 @@ | ||
import { expect } from 'chai'; | ||
import { probeValidator } from '../../../src/lib/probe-validator.js'; | ||
import * as sinon from 'sinon'; | ||
import { ProbeValidator } from '../../../src/lib/probe-validator.js'; | ||
import { RedisCluster } from '../../../src/lib/redis/shared.js'; | ||
|
||
describe('ProbeValidator', () => { | ||
const sandbox = sinon.createSandbox(); | ||
const redis = { hGet: sandbox.stub() }; | ||
const probeValidator = new ProbeValidator(redis as unknown as RedisCluster); | ||
|
||
beforeEach(() => { | ||
redis.hGet.resolves(undefined); | ||
}); | ||
|
||
it('should pass through valid probe id', async () => { | ||
probeValidator.addValidIds('measurement-id', 'test-id', 'probe-uuid'); | ||
probeValidator.validateProbe('measurement-id', 'test-id', 'probe-uuid'); | ||
await probeValidator.validateProbe('measurement-id', 'test-id', 'probe-uuid'); | ||
}); | ||
|
||
it('should throw for invalid probe id', async () => { | ||
probeValidator.addValidIds('measurement-id', 'test-id', 'probe-uuid'); | ||
expect(() => probeValidator.validateProbe('measurement-id', 'test-id', 'invalid-probe-uuid')).to.throw(); | ||
const error = await probeValidator.validateProbe('measurement-id', 'test-id', 'invalid-probe-uuid').catch(err => err); | ||
expect(error.message).to.equal('Probe ID is wrong for key measurement-id_test-id. Expected: probe-uuid, actual: invalid-probe-uuid'); | ||
}); | ||
|
||
it('should throw for missing key', async () => { | ||
expect(() => probeValidator.validateProbe('missing-measurement-id', 'test-id', 'probe-uuid')).to.throw(); | ||
const error = await probeValidator.validateProbe('missing-measurement-id', 'test-id', 'probe-uuid').catch(err => err); | ||
expect(error.message).to.equal('Probe ID not found for key missing-measurement-id_test-id'); | ||
}); | ||
|
||
it('should search key in redis if not found locally', async () => { | ||
redis.hGet.resolves('probe-uuid'); | ||
await probeValidator.validateProbe('only-redis-measurement-id', 'test-id', 'probe-uuid'); | ||
}); | ||
|
||
it('should throw if redis probe id is different', async () => { | ||
redis.hGet.resolves('different-probe-uuid'); | ||
const error = await probeValidator.validateProbe('only-redis-measurement-id', 'test-id', 'probe-uuid').catch(err => err); | ||
expect(error.message).to.equal('Probe ID is wrong for key only-redis-measurement-id_test-id. Expected: different-probe-uuid, actual: probe-uuid'); | ||
}); | ||
}); |