@@ -15,7 +15,7 @@ import {
1515import { IAssignmentLogger } from '../assignment-logger' ;
1616import { IConfigurationStore } from '../configuration-store/configuration-store' ;
1717import { 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' ;
1919import { Flag , ObfuscatedFlag , VariationType } from '../interfaces' ;
2020
2121import EppoClient , { FlagConfigurationRequestParameters , checkTypeMatch } from './eppo-client' ;
@@ -554,7 +554,7 @@ describe('EppoClient E2E test', () => {
554554 const subject = 'alice' ;
555555 const pi = 3.1415926 ;
556556
557- const maxRetryDelay = POLL_INTERVAL_MS * POLL_JITTER_PCT ;
557+ const maxRetryDelay = DEFAULT_POLL_INTERVAL_MS * POLL_JITTER_PCT ;
558558
559559 beforeAll ( async ( ) => {
560560 global . fetch = jest . fn ( ( ) => {
@@ -630,6 +630,38 @@ describe('EppoClient E2E test', () => {
630630 expect ( variation ) . toBe ( pi ) ;
631631 } ) ;
632632
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+ } ) ;
633665 it ( 'Does not fetch configurations if the configuration store is unexpired' , async ( ) => {
634666 class MockStore < T > extends MemoryOnlyConfigurationStore < T > {
635667 async isExpired ( ) : Promise < boolean > {
@@ -698,7 +730,7 @@ describe('EppoClient E2E test', () => {
698730 expect ( variation ) . toBe ( pi ) ;
699731 expect ( callCount ) . toBe ( 2 ) ;
700732
701- await jest . advanceTimersByTimeAsync ( POLL_INTERVAL_MS ) ;
733+ await jest . advanceTimersByTimeAsync ( DEFAULT_POLL_INTERVAL_MS ) ;
702734 // By default, no more polling
703735 expect ( callCount ) . toBe ( pollAfterSuccessfulInitialization ? 3 : 2 ) ;
704736 } ) ;
@@ -760,7 +792,7 @@ describe('EppoClient E2E test', () => {
760792 expect ( client . getNumericAssignment ( flagKey , subject , { } , 10.0 ) ) . toBe ( 10.0 ) ;
761793
762794 // 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 ) ;
764796
765797 // if pollAfterFailedInitialization = true, we will poll later and get a config, otherwise not
766798 expect ( callCount ) . toBe ( pollAfterFailedInitialization ? 2 : 1 ) ;
0 commit comments