|
1 | 1 | import { strict as assert } from 'node:assert';
|
2 | 2 | import testUtils, { GLOBAL } from '../test-utils';
|
3 | 3 | import LATENCY_RESET, { LATENCY_EVENTS } from './LATENCY_RESET';
|
4 |
| -import { parseArgs } from './generic-transformers'; // Re-import parseArgs for unit tests |
| 4 | +import { parseArgs } from './generic-transformers'; |
5 | 5 |
|
6 | 6 | describe('LATENCY RESET', function () {
|
7 |
| - // Set a generous timeout for the entire test suite. |
8 |
| - // This is crucial for the Docker container to spin up and client to connect reliably. |
9 |
| - this.timeout(300000); // 5 minutes |
10 | 7 |
|
11 |
| - // --- Unit Tests for transformArguments --- |
12 |
| - // These tests ensure the command arguments are correctly transformed |
13 |
| - // before being sent to the Redis server. |
14 | 8 |
|
15 | 9 | it('transformArguments with no events', () => {
|
16 | 10 | assert.deepEqual(
|
@@ -45,73 +39,65 @@ describe('LATENCY RESET', function () {
|
45 | 39 | );
|
46 | 40 | });
|
47 | 41 |
|
48 |
| - // --- Integration Test for client.latencyReset --- |
49 |
| - // This test interacts with a real Redis server to verify end-to-end functionality. |
| 42 | + |
50 | 43 | testUtils.testWithClient('client.latencyReset', async client => {
|
51 |
| - // 1. Set a latency monitor threshold to ensure events are logged. |
52 |
| - // Setting it to 1ms ensures even small delays are captured. |
| 44 | + |
53 | 45 | await client.configSet('latency-monitor-threshold', '1');
|
54 | 46 |
|
55 |
| - // 2. Generate a clear latency event for the 'command' type. |
56 |
| - // Sleeping for 100ms ensures it exceeds the 1ms threshold. |
| 47 | + |
57 | 48 | await client.sendCommand(['DEBUG', 'SLEEP', '0.1']);
|
58 | 49 |
|
59 |
| - // Optional: Verify latency was recorded before the first reset. |
60 |
| - // This helps confirm the test setup is working. |
| 50 | + |
61 | 51 | const latestLatencyBeforeReset = await client.latencyLatest();
|
62 | 52 | assert.ok(latestLatencyBeforeReset.length > 0, 'Expected latency events to be recorded before first reset.');
|
63 | 53 | assert.equal(latestLatencyBeforeReset[0][0], 'command', 'Expected "command" event to be recorded.');
|
64 | 54 | assert.ok(Number(latestLatencyBeforeReset[0][2]) >= 100, 'Expected latest latency for "command" to be at least 100ms.');
|
65 | 55 |
|
66 |
| - // 3. Execute LATENCY RESET command without arguments (resets all events). |
| 56 | + |
67 | 57 | const replyAll = await client.latencyReset();
|
68 |
| - // The command returns the number of events reset (usually 1 for 'command' event). |
| 58 | + |
69 | 59 | assert.equal(typeof replyAll, 'number');
|
70 |
| - assert.ok(replyAll >= 0); // Should be 1 if 'command' was reset. |
| 60 | + assert.ok(replyAll >= 0); |
71 | 61 |
|
72 |
| - // 4. Verify that LATENCY LATEST returns an empty array after resetting all events. |
| 62 | + |
73 | 63 | const latestLatencyAfterAllReset = await client.latencyLatest();
|
74 | 64 | assert.deepEqual(latestLatencyAfterAllReset, [], 'Expected no latency events after resetting all.');
|
75 | 65 |
|
76 |
| - // 5. Generate another latency event to test specific reset. |
77 |
| - await client.sendCommand(['DEBUG', 'SLEEP', '0.05']); // Sleep for 50ms |
| 66 | + |
| 67 | + await client.sendCommand(['DEBUG', 'SLEEP', '0.05']); |
78 | 68 | const latestLatencyBeforeSpecificReset = await client.latencyLatest();
|
79 | 69 | assert.ok(latestLatencyBeforeSpecificReset.length > 0, 'Expected latency events before specific reset.');
|
80 | 70 |
|
81 |
| - // 6. Execute LATENCY RESET with a specific event ('command'). |
| 71 | + |
82 | 72 | const replySpecific = await client.latencyReset(LATENCY_EVENTS.COMMAND);
|
83 | 73 | assert.equal(typeof replySpecific, 'number');
|
84 |
| - assert.ok(replySpecific >= 0); // Should be 1 if 'command' was reset. |
| 74 | + assert.ok(replySpecific >= 0); |
85 | 75 |
|
86 |
| - // 7. Verify that the specific event is reset. |
| 76 | + |
87 | 77 | const latestLatencyAfterSpecificReset = await client.latencyLatest();
|
88 | 78 | assert.deepEqual(latestLatencyAfterSpecificReset, [], 'Expected no latency events after specific reset of "command".');
|
89 | 79 |
|
90 |
| - // 8. Generate multiple types of latency events (hypothetically, if more were possible via DEBUG). |
91 |
| - // For simplicity, we'll just generate 'command' again and assert its reset. |
92 |
| - await client.sendCommand(['DEBUG', 'SLEEP', '0.02']); // Generate another 'command' latency |
93 |
| - // In a real scenario, you might have other DEBUG commands to generate 'fork' or 'aof-fsync-always' |
94 |
| - // For this example, we'll just use 'command' again for simplicity. |
| 80 | + |
| 81 | + await client.sendCommand(['DEBUG', 'SLEEP', '0.02']); |
| 82 | + |
95 | 83 |
|
96 | 84 | const latestLatencyBeforeMultipleReset = await client.latencyLatest();
|
97 | 85 | assert.ok(latestLatencyBeforeMultipleReset.length > 0, 'Expected latency events before multiple reset.');
|
98 | 86 |
|
99 |
| - // 9. Execute LATENCY RESET with multiple specific events (e.g., 'command', 'fork'). |
100 |
| - // Even if 'fork' wasn't generated, calling reset on it should still work. |
| 87 | + |
101 | 88 | const replyMultiple = await client.latencyReset(LATENCY_EVENTS.COMMAND, LATENCY_EVENTS.FORK);
|
102 | 89 | assert.equal(typeof replyMultiple, 'number');
|
103 |
| - assert.ok(replyMultiple >= 0); // Should be 1 if 'command' was reset. |
| 90 | + assert.ok(replyMultiple >= 0); |
104 | 91 |
|
105 |
| - // 10. Verify that all specified events are reset. |
106 | 92 | const latestLatencyAfterMultipleReset = await client.latencyLatest();
|
107 | 93 | assert.deepEqual(latestLatencyAfterMultipleReset, [], 'Expected no latency events after multiple specified resets.');
|
108 | 94 |
|
109 | 95 | }, {
|
110 |
| - // These options are passed to testUtils.testWithClient for setting up the Redis server and client. |
| 96 | + |
111 | 97 | ...GLOBAL.SERVERS.OPEN,
|
112 |
| - clientOptions: { // Configure the client created by testWithClient |
| 98 | + clientOptions: { |
113 | 99 | socket: {
|
114 |
| - connectTimeout: 300000 // Set client connection timeout to 5 minutes (300000ms) |
| 100 | + connectTimeout: 300000 |
115 | 101 | }
|
116 | 102 | }
|
117 | 103 | });
|
|
0 commit comments