swadhinbiswas

[email protected]
2026-02-16 01:52:49 +0600 committed NaN years ago
7e25bd4
commit 7e25bd4
1 file changed
+3 -8
Showing 1 changed file+3-8
▼tests/distributed-lock.test.ts
+3-8
19
19
expect(released).toBe(true);
20
20
});
21
21
22
- it("should prevent acquiring an held lock", async () => {
22
+ it("should prevent acquiring a held lock", async () => {
23
23
const key = "test-lock-2";
24
24
// Acquire first lock
25
25
const lock1 = await acquireLock(key);
26
26
expect(lock1).toBeDefined();
27
27
28
- // Try to acquire same lock (should fail immediately if we set retries to 0 for speed)
29
- // Default has retries, so it will wait. Let's set short timeout/retries.
30
- const start = Date.now();
31
- const lock2 = await acquireLock(key, { retryCount: 1, retryDelayMs: 10 });
32
- const end = Date.now();
28
+ // Try to acquire same lock with no retries to avoid timing-based flakiness.
29
+ const lock2 = await acquireLock(key, { retryCount: 0 });
33
30
34
31
expect(lock2).toBeNull();
35
- // Should have waited at least 10ms
36
- expect(end - start).toBeGreaterThanOrEqual(10);
37
32
38
33
await lock1?.release();
39
34
});
40
35