Skip to content

Commit 83f2a2a

Browse files
committed
add error margins
Signed-off-by: Utkarsh Srivastava <srivastavautkarsh8097@gmail.com>
1 parent a2cbd46 commit 83f2a2a

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

tests/generateUniqueID.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ describe("Snowflake with default configuration", () => {
1212
});
1313

1414
it("should return timestamp of creation", () => {
15+
const ERROR_MARGIN = 2;
1516
const uid = new UniqueID();
1617

1718
const before = Date.now(); // Before calling
@@ -20,7 +21,7 @@ describe("Snowflake with default configuration", () => {
2021

2122
const ts = uid.getTimestampFromID(id);
2223

23-
expect(ts).to.be.greaterThanOrEqual(before).and.lessThanOrEqual(after);
24+
expect(ts).to.be.greaterThanOrEqual(before - ERROR_MARGIN).and.lessThanOrEqual(after + ERROR_MARGIN);
2425
});
2526

2627
it("should return machine id", () => {
@@ -62,6 +63,7 @@ describe("Snowflake with custom machine ID configuration", () => {
6263
});
6364

6465
it("should return timestamp of creation", () => {
66+
const ERROR_MARGIN = 2
6567
const uid = new UniqueID({ machineID: 1000 });
6668

6769
const before = Date.now(); // Before calling
@@ -70,7 +72,7 @@ describe("Snowflake with custom machine ID configuration", () => {
7072

7173
const ts = uid.getTimestampFromID(id);
7274

73-
expect(ts).to.be.greaterThanOrEqual(before - 1).and.lessThanOrEqual(after + 1);
75+
expect(ts).to.be.greaterThanOrEqual(before - ERROR_MARGIN).and.lessThanOrEqual(after + ERROR_MARGIN);
7476
});
7577

7678
it("should return current machine's id from the generated id", () => {

0 commit comments

Comments
 (0)