@@ -17,7 +17,7 @@ import { IAssignmentLogger } from '../assignment-logger';
17
17
import ConfigurationRequestor from '../configuration-requestor' ;
18
18
import { IConfigurationStore } from '../configuration-store/configuration-store' ;
19
19
import { MemoryOnlyConfigurationStore } from '../configuration-store/memory.store' ;
20
- import { MAX_EVENT_QUEUE_SIZE , POLL_INTERVAL_MS , POLL_JITTER_PCT } from '../constants' ;
20
+ import { MAX_EVENT_QUEUE_SIZE , DEFAULT_POLL_INTERVAL_MS , POLL_JITTER_PCT } from '../constants' ;
21
21
import FetchHttpClient from '../http-client' ;
22
22
import { Flag , ObfuscatedFlag , VariationType } from '../interfaces' ;
23
23
@@ -576,7 +576,7 @@ describe('EppoClient E2E test', () => {
576
576
const subject = 'alice' ;
577
577
const pi = 3.1415926 ;
578
578
579
- const maxRetryDelay = POLL_INTERVAL_MS * POLL_JITTER_PCT ;
579
+ const maxRetryDelay = DEFAULT_POLL_INTERVAL_MS * POLL_JITTER_PCT ;
580
580
581
581
beforeAll ( async ( ) => {
582
582
global . fetch = jest . fn ( ( ) => {
@@ -652,6 +652,38 @@ describe('EppoClient E2E test', () => {
652
652
expect ( variation ) . toBe ( pi ) ;
653
653
} ) ;
654
654
655
+ describe ( 'Poll after successful start' , ( ) => {
656
+ it ( 'Continues to poll when cache has not expired' , async ( ) => {
657
+ class MockStore < T > extends MemoryOnlyConfigurationStore < T > {
658
+ public static expired = false ;
659
+
660
+ async isExpired ( ) : Promise < boolean > {
661
+ return MockStore . expired ;
662
+ }
663
+ }
664
+
665
+ client = new EppoClient ( new MockStore ( ) , undefined , undefined , {
666
+ ...requestConfiguration ,
667
+ pollAfterSuccessfulInitialization : true ,
668
+ } ) ;
669
+ client . setIsGracefulFailureMode ( false ) ;
670
+ // no configuration loaded
671
+ let variation = client . getNumericAssignment ( flagKey , subject , { } , 0.0 ) ;
672
+ expect ( variation ) . toBe ( 0.0 ) ;
673
+
674
+ // have client fetch configurations; cache is not expired so assignment stays
675
+ await client . fetchFlagConfigurations ( ) ;
676
+ variation = client . getNumericAssignment ( flagKey , subject , { } , 0.0 ) ;
677
+ expect ( variation ) . toBe ( 0.0 ) ;
678
+
679
+ // Expire the cache and advance time until a reload should happen
680
+ MockStore . expired = true ;
681
+ await jest . advanceTimersByTimeAsync ( DEFAULT_POLL_INTERVAL_MS * 1.5 ) ;
682
+
683
+ variation = client . getNumericAssignment ( flagKey , subject , { } , 0.0 ) ;
684
+ expect ( variation ) . toBe ( pi ) ;
685
+ } ) ;
686
+ } ) ;
655
687
it ( 'Does not fetch configurations if the configuration store is unexpired' , async ( ) => {
656
688
class MockStore < T > extends MemoryOnlyConfigurationStore < T > {
657
689
async isExpired ( ) : Promise < boolean > {
@@ -720,7 +752,7 @@ describe('EppoClient E2E test', () => {
720
752
expect ( variation ) . toBe ( pi ) ;
721
753
expect ( callCount ) . toBe ( 2 ) ;
722
754
723
- await jest . advanceTimersByTimeAsync ( POLL_INTERVAL_MS ) ;
755
+ await jest . advanceTimersByTimeAsync ( DEFAULT_POLL_INTERVAL_MS ) ;
724
756
// By default, no more polling
725
757
expect ( callCount ) . toBe ( pollAfterSuccessfulInitialization ? 3 : 2 ) ;
726
758
} ) ;
@@ -782,7 +814,7 @@ describe('EppoClient E2E test', () => {
782
814
expect ( client . getNumericAssignment ( flagKey , subject , { } , 10.0 ) ) . toBe ( 10.0 ) ;
783
815
784
816
// Advance timers so a post-init poll can take place
785
- await jest . advanceTimersByTimeAsync ( POLL_INTERVAL_MS * 1.5 ) ;
817
+ await jest . advanceTimersByTimeAsync ( DEFAULT_POLL_INTERVAL_MS * 1.5 ) ;
786
818
787
819
// if pollAfterFailedInitialization = true, we will poll later and get a config, otherwise not
788
820
expect ( callCount ) . toBe ( pollAfterFailedInitialization ? 2 : 1 ) ;
0 commit comments