Skip to content

Commit 800cd10

Browse files
committed
fix isInRollout test
1 parent c4ad352 commit 800cd10

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

src/__tests__/isInRollout.test.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ mock.module('../core', () => {
1313
};
1414
});
1515

16+
// Use a monotonic counter instead of Date.now() to avoid cache collisions
17+
// when two dynamic imports happen within the same millisecond.
18+
let importCounter = 0;
19+
1620
import { murmurhash3_32_gc } from '../isInRollout';
1721

1822
describe('murmurhash3_32_gc', () => {
@@ -47,39 +51,39 @@ describe('murmurhash3_32_gc', () => {
4751
describe('isInRollout', () => {
4852
it('should return true when the rollout is greater than the hash modulo', async () => {
4953
mockUuid = 'test1';
50-
const { isInRollout } = await import(`../isInRollout?id=${Date.now()}`);
54+
const { isInRollout } = await import(`../isInRollout?id=${++importCounter}`);
5155
expect(isInRollout(25)).toBe(true);
5256
});
5357

5458
it('should return false when the rollout is equal to the hash modulo', async () => {
5559
mockUuid = 'test1';
56-
const { isInRollout } = await import(`../isInRollout?id=${Date.now()}`);
60+
const { isInRollout } = await import(`../isInRollout?id=${++importCounter}`);
5761
expect(isInRollout(24)).toBe(false);
5862
});
5963

6064
it('should return false when the rollout is less than the hash modulo', async () => {
6165
mockUuid = 'test1';
62-
const { isInRollout } = await import(`../isInRollout?id=${Date.now()}`);
66+
const { isInRollout } = await import(`../isInRollout?id=${++importCounter}`);
6367
expect(isInRollout(23)).toBe(false);
6468
});
6569

6670
it('should evaluate correctly for a different uuid', async () => {
6771
mockUuid = 'test3';
68-
const { isInRollout } = await import(`../isInRollout?id=${Date.now()}`);
72+
const { isInRollout } = await import(`../isInRollout?id=${++importCounter}`);
6973
expect(isInRollout(1)).toBe(true);
7074
expect(isInRollout(0)).toBe(false);
7175
expect(isInRollout(-1)).toBe(false);
7276
});
7377

7478
it('should always return false for 0% rollout', async () => {
7579
mockUuid = 'test1';
76-
const { isInRollout } = await import(`../isInRollout?id=${Date.now()}`);
80+
const { isInRollout } = await import(`../isInRollout?id=${++importCounter}`);
7781
expect(isInRollout(0)).toBe(false);
7882
});
7983

8084
it('should always return true for 100% rollout', async () => {
8185
mockUuid = 'test1';
82-
const { isInRollout } = await import(`../isInRollout?id=${Date.now()}`);
86+
const { isInRollout } = await import(`../isInRollout?id=${++importCounter}`);
8387
expect(isInRollout(100)).toBe(true);
8488
});
8589
});

0 commit comments

Comments
 (0)