@@ -12,6 +12,7 @@ describe("Snowflake with default configuration", () => {
12
12
} ) ;
13
13
14
14
it ( "should return timestamp of creation" , ( ) => {
15
+ const ERROR_MARGIN = 2 ;
15
16
const uid = new UniqueID ( ) ;
16
17
17
18
const before = Date . now ( ) ; // Before calling
@@ -20,7 +21,7 @@ describe("Snowflake with default configuration", () => {
20
21
21
22
const ts = uid . getTimestampFromID ( id ) ;
22
23
23
- expect ( ts ) . to . be . greaterThanOrEqual ( before ) . and . lessThanOrEqual ( after ) ;
24
+ expect ( ts ) . to . be . greaterThanOrEqual ( before - ERROR_MARGIN ) . and . lessThanOrEqual ( after + ERROR_MARGIN ) ;
24
25
} ) ;
25
26
26
27
it ( "should return machine id" , ( ) => {
@@ -62,6 +63,7 @@ describe("Snowflake with custom machine ID configuration", () => {
62
63
} ) ;
63
64
64
65
it ( "should return timestamp of creation" , ( ) => {
66
+ const ERROR_MARGIN = 2
65
67
const uid = new UniqueID ( { machineID : 1000 } ) ;
66
68
67
69
const before = Date . now ( ) ; // Before calling
@@ -70,7 +72,7 @@ describe("Snowflake with custom machine ID configuration", () => {
70
72
71
73
const ts = uid . getTimestampFromID ( id ) ;
72
74
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 ) ;
74
76
} ) ;
75
77
76
78
it ( "should return current machine's id from the generated id" , ( ) => {
0 commit comments