@@ -15,7 +15,7 @@ import { isWeakRefAvailable, setupPolyfills } from "#lib/Polyfills";
15
15
import { Config , IConfig , ProjectConfig , SettingValue , SettingValueContainer } from "#lib/ProjectConfig" ;
16
16
import { EvaluateContext , IEvaluateResult , IEvaluationDetails , IRolloutEvaluator } from "#lib/RolloutEvaluator" ;
17
17
import { User } from "#lib/User" ;
18
- import { delay } from "#lib/Utils" ;
18
+ import { delay , getMonotonicTimeMs } from "#lib/Utils" ;
19
19
import "./helpers/ConfigCatClientCacheExtensions" ;
20
20
21
21
describe ( "ConfigCatClient" , ( ) => {
@@ -195,7 +195,7 @@ describe("ConfigCatClient", () => {
195
195
196
196
const key = "notexists" ;
197
197
const defaultValue = false ;
198
- const timestamp = new Date ( ) . getTime ( ) ;
198
+ const timestamp = ProjectConfig . generateTimestamp ( ) ;
199
199
200
200
const configFetcherClass = FakeConfigFetcherWithTwoKeys ;
201
201
const cachedPc = new ProjectConfig ( configFetcherClass . configJson , Config . deserialize ( configFetcherClass . configJson ) , timestamp , "etag" ) ;
@@ -238,7 +238,7 @@ describe("ConfigCatClient", () => {
238
238
239
239
const key = "debug" ;
240
240
const defaultValue = false ;
241
- const timestamp = new Date ( ) . getTime ( ) ;
241
+ const timestamp = ProjectConfig . generateTimestamp ( ) ;
242
242
243
243
const configFetcherClass = FakeConfigFetcherWithTwoKeys ;
244
244
const cachedPc = new ProjectConfig ( configFetcherClass . configJson , Config . deserialize ( configFetcherClass . configJson ) , timestamp , "etag" ) ;
@@ -281,7 +281,7 @@ describe("ConfigCatClient", () => {
281
281
282
282
const key = "debug" ;
283
283
const defaultValue = "N/A" ;
284
- const timestamp = new Date ( ) . getTime ( ) ;
284
+ const timestamp = ProjectConfig . generateTimestamp ( ) ;
285
285
286
286
const configFetcherClass = FakeConfigFetcherWithRules ;
287
287
const cachedPc = new ProjectConfig ( configFetcherClass . configJson , Config . deserialize ( configFetcherClass . configJson ) , timestamp , "etag" ) ;
@@ -327,7 +327,7 @@ describe("ConfigCatClient", () => {
327
327
328
328
const key = "string25Cat25Dog25Falcon25Horse" ;
329
329
const defaultValue = "N/A" ;
330
- const timestamp = new Date ( ) . getTime ( ) ;
330
+ const timestamp = ProjectConfig . generateTimestamp ( ) ;
331
331
332
332
const configFetcherClass = FakeConfigFetcherWithPercentageOptions ;
333
333
const cachedPc = new ProjectConfig ( configFetcherClass . configJson , Config . deserialize ( configFetcherClass . configJson ) , timestamp , "etag" ) ;
@@ -372,7 +372,7 @@ describe("ConfigCatClient", () => {
372
372
373
373
const key = "debug" ;
374
374
const defaultValue = false ;
375
- const timestamp = new Date ( ) . getTime ( ) ;
375
+ const timestamp = ProjectConfig . generateTimestamp ( ) ;
376
376
377
377
const configFetcherClass = FakeConfigFetcherWithTwoKeys ;
378
378
const cachedPc = new ProjectConfig ( configFetcherClass . configJson , Config . deserialize ( configFetcherClass . configJson ) , timestamp , "etag" ) ;
@@ -427,7 +427,7 @@ describe("ConfigCatClient", () => {
427
427
428
428
// Arrange
429
429
430
- const timestamp = new Date ( ) . getTime ( ) ;
430
+ const timestamp = ProjectConfig . generateTimestamp ( ) ;
431
431
432
432
const configFetcherClass = FakeConfigFetcherWithTwoKeys ;
433
433
const cachedPc = new ProjectConfig ( configFetcherClass . configJson , Config . deserialize ( configFetcherClass . configJson ) , timestamp , "etag" ) ;
@@ -479,7 +479,7 @@ describe("ConfigCatClient", () => {
479
479
480
480
// Arrange
481
481
482
- const timestamp = new Date ( ) . getTime ( ) ;
482
+ const timestamp = ProjectConfig . generateTimestamp ( ) ;
483
483
484
484
const configFetcherClass = FakeConfigFetcherWithTwoKeys ;
485
485
const cachedPc = new ProjectConfig ( configFetcherClass . configJson , Config . deserialize ( configFetcherClass . configJson ) , timestamp , "etag" ) ;
@@ -585,13 +585,13 @@ describe("ConfigCatClient", () => {
585
585
const configCatKernel = createKernel ( { configFetcher : new FakeConfigFetcher ( 500 ) } ) ;
586
586
const options : AutoPollOptions = createAutoPollOptions ( "APIKEY" , { maxInitWaitTimeSeconds } , configCatKernel ) ;
587
587
588
- const startDate : number = new Date ( ) . getTime ( ) ;
588
+ const startTime : number = getMonotonicTimeMs ( ) ;
589
589
const client : IConfigCatClient = new ConfigCatClient ( options , configCatKernel ) ;
590
590
const actualValue = await client . getValueAsync ( "debug" , false ) ;
591
- const elapsedMilliseconds : number = new Date ( ) . getTime ( ) - startDate ;
591
+ const elapsedMilliseconds : number = getMonotonicTimeMs ( ) - startTime ;
592
592
593
593
assert . isAtLeast ( elapsedMilliseconds , 500 - 25 ) ; // 25 ms for tolerance
594
- assert . isAtMost ( elapsedMilliseconds , maxInitWaitTimeSeconds * 1000 + 75 ) ; // 75 ms for tolerance
594
+ assert . isAtMost ( elapsedMilliseconds , maxInitWaitTimeSeconds * 1000 + 100 ) ; // 100 ms for tolerance
595
595
assert . equal ( actualValue , true ) ;
596
596
597
597
client . dispose ( ) ;
@@ -609,13 +609,13 @@ describe("ConfigCatClient", () => {
609
609
const configCatKernel = createKernel ( { configFetcher } ) ;
610
610
const options : AutoPollOptions = createAutoPollOptions ( "APIKEY" , { maxInitWaitTimeSeconds } , configCatKernel ) ;
611
611
612
- const startDate : number = new Date ( ) . getTime ( ) ;
612
+ const startTime : number = getMonotonicTimeMs ( ) ;
613
613
const client : IConfigCatClient = new ConfigCatClient ( options , configCatKernel ) ;
614
614
const actualDetails = await client . getValueDetailsAsync ( "debug" , false ) ;
615
- const elapsedMilliseconds : number = new Date ( ) . getTime ( ) - startDate ;
615
+ const elapsedMilliseconds : number = getMonotonicTimeMs ( ) - startTime ;
616
616
617
617
assert . isAtLeast ( elapsedMilliseconds , 500 - 25 ) ; // 25 ms for tolerance
618
- assert . isAtMost ( elapsedMilliseconds , configFetchDelay * 2 + 75 ) ; // 75 ms for tolerance
618
+ assert . isAtMost ( elapsedMilliseconds , configFetchDelay * 2 + 100 ) ; // 100 ms for tolerance
619
619
assert . equal ( actualDetails . isDefaultValue , true ) ;
620
620
assert . equal ( actualDetails . value , false ) ;
621
621
@@ -630,13 +630,13 @@ describe("ConfigCatClient", () => {
630
630
const configCatKernel = createKernel ( { configFetcher : new FakeConfigFetcherWithNullNewConfig ( 10000 ) } ) ;
631
631
const options : AutoPollOptions = createAutoPollOptions ( "APIKEY" , { maxInitWaitTimeSeconds } , configCatKernel ) ;
632
632
633
- const startDate : number = new Date ( ) . getTime ( ) ;
633
+ const startTime : number = getMonotonicTimeMs ( ) ;
634
634
const client : IConfigCatClient = new ConfigCatClient ( options , configCatKernel ) ;
635
635
const actualValue = await client . getValueAsync ( "debug" , false ) ;
636
- const elapsedMilliseconds : number = new Date ( ) . getTime ( ) - startDate ;
636
+ const elapsedMilliseconds : number = getMonotonicTimeMs ( ) - startTime ;
637
637
638
638
assert . isAtLeast ( elapsedMilliseconds , ( maxInitWaitTimeSeconds * 1000 ) - 25 ) ; // 25 ms for tolerance
639
- assert . isAtMost ( elapsedMilliseconds , ( maxInitWaitTimeSeconds * 1000 ) + 75 ) ; // 75 ms for tolerance
639
+ assert . isAtMost ( elapsedMilliseconds , ( maxInitWaitTimeSeconds * 1000 ) + 100 ) ; // 100 ms for tolerance
640
640
assert . equal ( actualValue , false ) ;
641
641
642
642
client . dispose ( ) ;
@@ -671,13 +671,13 @@ describe("ConfigCatClient", () => {
671
671
const configCatKernel = createKernel ( { configFetcher } ) ;
672
672
const options : AutoPollOptions = createAutoPollOptions ( "APIKEY" , { maxInitWaitTimeSeconds } , configCatKernel ) ;
673
673
674
- const startDate : number = new Date ( ) . getTime ( ) ;
674
+ const startTime : number = getMonotonicTimeMs ( ) ;
675
675
const client : IConfigCatClient = new ConfigCatClient ( options , configCatKernel ) ;
676
676
const state = await client . waitForReady ( ) ;
677
- const elapsedMilliseconds : number = new Date ( ) . getTime ( ) - startDate ;
677
+ const elapsedMilliseconds : number = getMonotonicTimeMs ( ) - startTime ;
678
678
679
679
assert . isAtLeast ( elapsedMilliseconds , ( maxInitWaitTimeSeconds * 1000 ) - 25 ) ; // 25 ms for tolerance
680
- assert . isAtMost ( elapsedMilliseconds , ( maxInitWaitTimeSeconds * 1000 ) + 75 ) ; // 75 ms for tolerance
680
+ assert . isAtMost ( elapsedMilliseconds , ( maxInitWaitTimeSeconds * 1000 ) + 100 ) ; // 100 ms for tolerance
681
681
682
682
assert . equal ( state , ClientCacheState . NoFlagData ) ;
683
683
@@ -704,13 +704,13 @@ describe("ConfigCatClient", () => {
704
704
cache : new FakeExternalCacheWithInitialData ( 120_000 ) ,
705
705
} , configCatKernel ) ;
706
706
707
- const startDate : number = new Date ( ) . getTime ( ) ;
707
+ const startTime : number = getMonotonicTimeMs ( ) ;
708
708
const client : IConfigCatClient = new ConfigCatClient ( options , configCatKernel ) ;
709
709
const state = await client . waitForReady ( ) ;
710
- const elapsedMilliseconds : number = new Date ( ) . getTime ( ) - startDate ;
710
+ const elapsedMilliseconds : number = getMonotonicTimeMs ( ) - startTime ;
711
711
712
712
assert . isAtLeast ( elapsedMilliseconds , ( maxInitWaitTimeSeconds * 1000 ) - 25 ) ; // 25 ms for tolerance
713
- assert . isAtMost ( elapsedMilliseconds , ( maxInitWaitTimeSeconds * 1000 ) + 75 ) ; // 75 ms for tolerance
713
+ assert . isAtMost ( elapsedMilliseconds , ( maxInitWaitTimeSeconds * 1000 ) + 100 ) ; // 100 ms for tolerance
714
714
715
715
assert . equal ( state , ClientCacheState . HasCachedFlagDataOnly ) ;
716
716
@@ -948,7 +948,7 @@ describe("ConfigCatClient", () => {
948
948
949
949
const configFetcher = new FakeConfigFetcher ( 500 ) ;
950
950
const configJson = "{\"f\": { \"debug\": { \"v\": { \"b\": false }, \"i\": \"abcdefgh\", \"t\": 0, \"p\": [], \"r\": [] } } }" ;
951
- const configCache = new FakeCache ( new ProjectConfig ( configJson , Config . deserialize ( configJson ) , new Date ( ) . getTime ( ) - 10000000 , "etag2" ) ) ;
951
+ const configCache = new FakeCache ( new ProjectConfig ( configJson , Config . deserialize ( configJson ) , ProjectConfig . generateTimestamp ( ) - 10000000 , "etag2" ) ) ;
952
952
const configCatKernel = createKernel ( { configFetcher, defaultCacheFactory : ( ) => configCache } ) ;
953
953
const options : AutoPollOptions = createAutoPollOptions ( "APIKEY" , { maxInitWaitTimeSeconds : 10 } , configCatKernel ) ;
954
954
const client : IConfigCatClient = new ConfigCatClient ( options , configCatKernel ) ;
@@ -963,7 +963,7 @@ describe("ConfigCatClient", () => {
963
963
964
964
const configFetcher = new FakeConfigFetcher ( 500 ) ;
965
965
const configJson = "{\"f\": { \"debug\": { \"v\": { \"b\": false }, \"i\": \"abcdefgh\", \"t\": 0, \"p\": [], \"r\": [] } } }" ;
966
- const configCache = new FakeCache ( new ProjectConfig ( configJson , Config . deserialize ( configJson ) , new Date ( ) . getTime ( ) - 10000000 , "etag2" ) ) ;
966
+ const configCache = new FakeCache ( new ProjectConfig ( configJson , Config . deserialize ( configJson ) , ProjectConfig . generateTimestamp ( ) - 10000000 , "etag2" ) ) ;
967
967
const configCatKernel = createKernel ( { configFetcher, defaultCacheFactory : ( ) => configCache } ) ;
968
968
const options : AutoPollOptions = createAutoPollOptions ( "APIKEY" , { maxInitWaitTimeSeconds : 10 } , configCatKernel ) ;
969
969
const client : IConfigCatClient = new ConfigCatClient ( options , configCatKernel ) ;
0 commit comments