@@ -15,7 +15,7 @@ import {
15
15
import { IAssignmentLogger } from '../assignment-logger' ;
16
16
import { IConfigurationStore } from '../configuration-store/configuration-store' ;
17
17
import { MemoryOnlyConfigurationStore } from '../configuration-store/memory.store' ;
18
- import { MAX_EVENT_QUEUE_SIZE , POLL_INTERVAL_MS , POLL_JITTER_PCT } from '../constants' ;
18
+ import { MAX_EVENT_QUEUE_SIZE , DEFAULT_POLL_INTERVAL_MS , POLL_JITTER_PCT } from '../constants' ;
19
19
import { Flag , ObfuscatedFlag , VariationType } from '../interfaces' ;
20
20
21
21
import EppoClient , { FlagConfigurationRequestParameters , checkTypeMatch } from './eppo-client' ;
@@ -554,7 +554,7 @@ describe('EppoClient E2E test', () => {
554
554
const subject = 'alice' ;
555
555
const pi = 3.1415926 ;
556
556
557
- const maxRetryDelay = POLL_INTERVAL_MS * POLL_JITTER_PCT ;
557
+ const maxRetryDelay = DEFAULT_POLL_INTERVAL_MS * POLL_JITTER_PCT ;
558
558
559
559
beforeAll ( async ( ) => {
560
560
global . fetch = jest . fn ( ( ) => {
@@ -630,6 +630,38 @@ describe('EppoClient E2E test', () => {
630
630
expect ( variation ) . toBe ( pi ) ;
631
631
} ) ;
632
632
633
+ describe ( 'Poll after successful start' , ( ) => {
634
+ it ( 'Continues to poll when cache has not expired' , async ( ) => {
635
+ class MockStore < T > extends MemoryOnlyConfigurationStore < T > {
636
+ public static expired = false ;
637
+
638
+ async isExpired ( ) : Promise < boolean > {
639
+ return MockStore . expired ;
640
+ }
641
+ }
642
+
643
+ client = new EppoClient ( new MockStore ( ) , undefined , undefined , {
644
+ ...requestConfiguration ,
645
+ pollAfterSuccessfulInitialization : true ,
646
+ } ) ;
647
+ client . setIsGracefulFailureMode ( false ) ;
648
+ // no configuration loaded
649
+ let variation = client . getNumericAssignment ( flagKey , subject , { } , 0.0 ) ;
650
+ expect ( variation ) . toBe ( 0.0 ) ;
651
+
652
+ // have client fetch configurations; cache is not expired so assignment stays
653
+ await client . fetchFlagConfigurations ( ) ;
654
+ variation = client . getNumericAssignment ( flagKey , subject , { } , 0.0 ) ;
655
+ expect ( variation ) . toBe ( 0.0 ) ;
656
+
657
+ // Expire the cache and advance time until a reload should happen
658
+ MockStore . expired = true ;
659
+ await jest . advanceTimersByTimeAsync ( DEFAULT_POLL_INTERVAL_MS * 1.5 ) ;
660
+
661
+ variation = client . getNumericAssignment ( flagKey , subject , { } , 0.0 ) ;
662
+ expect ( variation ) . toBe ( pi ) ;
663
+ } ) ;
664
+ } ) ;
633
665
it ( 'Does not fetch configurations if the configuration store is unexpired' , async ( ) => {
634
666
class MockStore < T > extends MemoryOnlyConfigurationStore < T > {
635
667
async isExpired ( ) : Promise < boolean > {
@@ -698,7 +730,7 @@ describe('EppoClient E2E test', () => {
698
730
expect ( variation ) . toBe ( pi ) ;
699
731
expect ( callCount ) . toBe ( 2 ) ;
700
732
701
- await jest . advanceTimersByTimeAsync ( POLL_INTERVAL_MS ) ;
733
+ await jest . advanceTimersByTimeAsync ( DEFAULT_POLL_INTERVAL_MS ) ;
702
734
// By default, no more polling
703
735
expect ( callCount ) . toBe ( pollAfterSuccessfulInitialization ? 3 : 2 ) ;
704
736
} ) ;
@@ -760,7 +792,7 @@ describe('EppoClient E2E test', () => {
760
792
expect ( client . getNumericAssignment ( flagKey , subject , { } , 10.0 ) ) . toBe ( 10.0 ) ;
761
793
762
794
// Advance timers so a post-init poll can take place
763
- await jest . advanceTimersByTimeAsync ( POLL_INTERVAL_MS * 1.5 ) ;
795
+ await jest . advanceTimersByTimeAsync ( DEFAULT_POLL_INTERVAL_MS * 1.5 ) ;
764
796
765
797
// if pollAfterFailedInitialization = true, we will poll later and get a config, otherwise not
766
798
expect ( callCount ) . toBe ( pollAfterFailedInitialization ? 2 : 1 ) ;
0 commit comments