|  | 
|  | 1 | +import { strict as assert } from 'node:assert'; | 
|  | 2 | +import testUtils, { GLOBAL } from '../test-utils'; | 
|  | 3 | +import LATENCY_RESET, { LATENCY_EVENTS } from './LATENCY_RESET'; | 
|  | 4 | +import { parseArgs } from './generic-transformers'; | 
|  | 5 | + | 
|  | 6 | +describe('LATENCY RESET', function () { | 
|  | 7 | + | 
|  | 8 | + | 
|  | 9 | +    it('transformArguments with no events', () => { | 
|  | 10 | +        assert.deepEqual( | 
|  | 11 | +            parseArgs(LATENCY_RESET), | 
|  | 12 | +            [ | 
|  | 13 | +                'LATENCY', | 
|  | 14 | +                'RESET' | 
|  | 15 | +            ] | 
|  | 16 | +        ); | 
|  | 17 | +    }); | 
|  | 18 | + | 
|  | 19 | +    it('transformArguments with one event', () => { | 
|  | 20 | +        assert.deepEqual( | 
|  | 21 | +            parseArgs(LATENCY_RESET, LATENCY_EVENTS.COMMAND), | 
|  | 22 | +            [ | 
|  | 23 | +                'LATENCY', | 
|  | 24 | +                'RESET', | 
|  | 25 | +                'command' | 
|  | 26 | +            ] | 
|  | 27 | +        ); | 
|  | 28 | +    }); | 
|  | 29 | + | 
|  | 30 | +    it('transformArguments with multiple events', () => { | 
|  | 31 | +        assert.deepEqual( | 
|  | 32 | +            parseArgs(LATENCY_RESET, LATENCY_EVENTS.COMMAND, LATENCY_EVENTS.FORK), | 
|  | 33 | +            [ | 
|  | 34 | +                'LATENCY', | 
|  | 35 | +                'RESET', | 
|  | 36 | +                'command', | 
|  | 37 | +                'fork' | 
|  | 38 | +            ] | 
|  | 39 | +        ); | 
|  | 40 | +    }); | 
|  | 41 | + | 
|  | 42 | + | 
|  | 43 | +    testUtils.testWithClient('client.latencyReset', async client => { | 
|  | 44 | + | 
|  | 45 | +        await client.configSet('latency-monitor-threshold', '1'); | 
|  | 46 | + | 
|  | 47 | + | 
|  | 48 | +        await client.sendCommand(['DEBUG', 'SLEEP', '0.1']); | 
|  | 49 | + | 
|  | 50 | + | 
|  | 51 | +        const latestLatencyBeforeReset = await client.latencyLatest(); | 
|  | 52 | +        assert.ok(latestLatencyBeforeReset.length > 0, 'Expected latency events to be recorded before first reset.'); | 
|  | 53 | +        assert.equal(latestLatencyBeforeReset[0][0], 'command', 'Expected "command" event to be recorded.'); | 
|  | 54 | +        assert.ok(Number(latestLatencyBeforeReset[0][2]) >= 100, 'Expected latest latency for "command" to be at least 100ms.'); | 
|  | 55 | + | 
|  | 56 | + | 
|  | 57 | +        const replyAll = await client.latencyReset(); | 
|  | 58 | + | 
|  | 59 | +        assert.equal(typeof replyAll, 'number'); | 
|  | 60 | +        assert.ok(replyAll >= 0); | 
|  | 61 | + | 
|  | 62 | + | 
|  | 63 | +        const latestLatencyAfterAllReset = await client.latencyLatest(); | 
|  | 64 | +        assert.deepEqual(latestLatencyAfterAllReset, [], 'Expected no latency events after resetting all.'); | 
|  | 65 | + | 
|  | 66 | + | 
|  | 67 | +        await client.sendCommand(['DEBUG', 'SLEEP', '0.05']); | 
|  | 68 | +        const latestLatencyBeforeSpecificReset = await client.latencyLatest(); | 
|  | 69 | +        assert.ok(latestLatencyBeforeSpecificReset.length > 0, 'Expected latency events before specific reset.'); | 
|  | 70 | + | 
|  | 71 | + | 
|  | 72 | +        const replySpecific = await client.latencyReset(LATENCY_EVENTS.COMMAND); | 
|  | 73 | +        assert.equal(typeof replySpecific, 'number'); | 
|  | 74 | +        assert.ok(replySpecific >= 0); | 
|  | 75 | + | 
|  | 76 | + | 
|  | 77 | +        const latestLatencyAfterSpecificReset = await client.latencyLatest(); | 
|  | 78 | +        assert.deepEqual(latestLatencyAfterSpecificReset, [], 'Expected no latency events after specific reset of "command".'); | 
|  | 79 | + | 
|  | 80 | + | 
|  | 81 | +        await client.sendCommand(['DEBUG', 'SLEEP', '0.02']); | 
|  | 82 | + | 
|  | 83 | + | 
|  | 84 | +        const latestLatencyBeforeMultipleReset = await client.latencyLatest(); | 
|  | 85 | +        assert.ok(latestLatencyBeforeMultipleReset.length > 0, 'Expected latency events before multiple reset.'); | 
|  | 86 | + | 
|  | 87 | + | 
|  | 88 | +        const replyMultiple = await client.latencyReset(LATENCY_EVENTS.COMMAND, LATENCY_EVENTS.FORK); | 
|  | 89 | +        assert.equal(typeof replyMultiple, 'number'); | 
|  | 90 | +        assert.ok(replyMultiple >= 0); | 
|  | 91 | + | 
|  | 92 | +        const latestLatencyAfterMultipleReset = await client.latencyLatest(); | 
|  | 93 | +        assert.deepEqual(latestLatencyAfterMultipleReset, [], 'Expected no latency events after multiple specified resets.'); | 
|  | 94 | + | 
|  | 95 | +    }, { | 
|  | 96 | + | 
|  | 97 | +        ...GLOBAL.SERVERS.OPEN, | 
|  | 98 | +        clientOptions: { | 
|  | 99 | +            socket: { | 
|  | 100 | +                connectTimeout: 300000 | 
|  | 101 | +            } | 
|  | 102 | +        } | 
|  | 103 | +    }); | 
|  | 104 | +}); | 
0 commit comments