Skip to content

Commit 0a0d5c8

Browse files
authored
Update LATENCY_RESET.spec.ts
1 parent dfdef8d commit 0a0d5c8

File tree

1 file changed

+22
-36
lines changed

1 file changed

+22
-36
lines changed

packages/client/lib/commands/LATENCY_RESET.spec.ts

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
import { strict as assert } from 'node:assert';
22
import testUtils, { GLOBAL } from '../test-utils';
33
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';
55

66
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
107

11-
// --- Unit Tests for transformArguments ---
12-
// These tests ensure the command arguments are correctly transformed
13-
// before being sent to the Redis server.
148

159
it('transformArguments with no events', () => {
1610
assert.deepEqual(
@@ -45,73 +39,65 @@ describe('LATENCY RESET', function () {
4539
);
4640
});
4741

48-
// --- Integration Test for client.latencyReset ---
49-
// This test interacts with a real Redis server to verify end-to-end functionality.
42+
5043
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+
5345
await client.configSet('latency-monitor-threshold', '1');
5446

55-
// 2. Generate a clear latency event for the 'command' type.
56-
// Sleeping for 100ms ensures it exceeds the 1ms threshold.
47+
5748
await client.sendCommand(['DEBUG', 'SLEEP', '0.1']);
5849

59-
// Optional: Verify latency was recorded before the first reset.
60-
// This helps confirm the test setup is working.
50+
6151
const latestLatencyBeforeReset = await client.latencyLatest();
6252
assert.ok(latestLatencyBeforeReset.length > 0, 'Expected latency events to be recorded before first reset.');
6353
assert.equal(latestLatencyBeforeReset[0][0], 'command', 'Expected "command" event to be recorded.');
6454
assert.ok(Number(latestLatencyBeforeReset[0][2]) >= 100, 'Expected latest latency for "command" to be at least 100ms.');
6555

66-
// 3. Execute LATENCY RESET command without arguments (resets all events).
56+
6757
const replyAll = await client.latencyReset();
68-
// The command returns the number of events reset (usually 1 for 'command' event).
58+
6959
assert.equal(typeof replyAll, 'number');
70-
assert.ok(replyAll >= 0); // Should be 1 if 'command' was reset.
60+
assert.ok(replyAll >= 0);
7161

72-
// 4. Verify that LATENCY LATEST returns an empty array after resetting all events.
62+
7363
const latestLatencyAfterAllReset = await client.latencyLatest();
7464
assert.deepEqual(latestLatencyAfterAllReset, [], 'Expected no latency events after resetting all.');
7565

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']);
7868
const latestLatencyBeforeSpecificReset = await client.latencyLatest();
7969
assert.ok(latestLatencyBeforeSpecificReset.length > 0, 'Expected latency events before specific reset.');
8070

81-
// 6. Execute LATENCY RESET with a specific event ('command').
71+
8272
const replySpecific = await client.latencyReset(LATENCY_EVENTS.COMMAND);
8373
assert.equal(typeof replySpecific, 'number');
84-
assert.ok(replySpecific >= 0); // Should be 1 if 'command' was reset.
74+
assert.ok(replySpecific >= 0);
8575

86-
// 7. Verify that the specific event is reset.
76+
8777
const latestLatencyAfterSpecificReset = await client.latencyLatest();
8878
assert.deepEqual(latestLatencyAfterSpecificReset, [], 'Expected no latency events after specific reset of "command".');
8979

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+
9583

9684
const latestLatencyBeforeMultipleReset = await client.latencyLatest();
9785
assert.ok(latestLatencyBeforeMultipleReset.length > 0, 'Expected latency events before multiple reset.');
9886

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+
10188
const replyMultiple = await client.latencyReset(LATENCY_EVENTS.COMMAND, LATENCY_EVENTS.FORK);
10289
assert.equal(typeof replyMultiple, 'number');
103-
assert.ok(replyMultiple >= 0); // Should be 1 if 'command' was reset.
90+
assert.ok(replyMultiple >= 0);
10491

105-
// 10. Verify that all specified events are reset.
10692
const latestLatencyAfterMultipleReset = await client.latencyLatest();
10793
assert.deepEqual(latestLatencyAfterMultipleReset, [], 'Expected no latency events after multiple specified resets.');
10894

10995
}, {
110-
// These options are passed to testUtils.testWithClient for setting up the Redis server and client.
96+
11197
...GLOBAL.SERVERS.OPEN,
112-
clientOptions: { // Configure the client created by testWithClient
98+
clientOptions: {
11399
socket: {
114-
connectTimeout: 300000 // Set client connection timeout to 5 minutes (300000ms)
100+
connectTimeout: 300000
115101
}
116102
}
117103
});

0 commit comments

Comments
 (0)