@@ -70,6 +70,7 @@ describe('OpenFeature Remote Config and Exposure Events Integration', () => {
7070 it ( 'should generate exposure events with manual flush' , ( done ) => {
7171 const configId = 'org-42-env-test'
7272 const exposureEvents = [ ]
73+ let receivedAckUpdate = false
7374
7475 // Listen for exposure events
7576 agent . on ( 'exposures' , ( { payload, headers } ) => {
@@ -101,23 +102,22 @@ describe('OpenFeature Remote Config and Exposure Events Integration', () => {
101102 validateExposureEvent ( stringEvent , 'test-string-flag' , 'test-user-456' ,
102103 { user : 'test-user-456' , tier : 'enterprise' } )
103104
104- done ( )
105+ endIfDone ( )
105106 } catch ( error ) {
106107 done ( error )
107108 }
108109 }
109110 } )
110111
111- // Deliver UFC config via Remote Config
112- agent . addRemoteConfig ( {
113- product : RC_PRODUCT ,
114- id : configId ,
115- config : ufcPayloads . testBooleanAndStringFlags
116- } )
112+ agent . on ( 'remote-config-ack-update' , async ( id , _version , state ) => {
113+ if ( state === UNACKNOWLEDGED ) return
114+
115+ if ( id !== configId ) return
117116
118- // Wait for RC delivery then evaluate flags
119- setTimeout ( async ( ) => {
120117 try {
118+ assert . strictEqual ( state , ACKNOWLEDGED )
119+ receivedAckUpdate = true
120+
121121 const response = await fetch ( `${ proc . url } /evaluate-flags` )
122122 assert . equal ( response . status , 200 )
123123 const data = await response . json ( )
@@ -128,7 +128,18 @@ describe('OpenFeature Remote Config and Exposure Events Integration', () => {
128128 } catch ( error ) {
129129 done ( error )
130130 }
131- } , 1000 )
131+ } )
132+
133+ // Deliver UFC config via Remote Config
134+ agent . addRemoteConfig ( {
135+ product : RC_PRODUCT ,
136+ id : configId ,
137+ config : ufcPayloads . testBooleanAndStringFlags
138+ } )
139+
140+ function endIfDone ( ) {
141+ if ( receivedAckUpdate && exposureEvents . length === 2 ) done ( )
142+ }
132143 } )
133144 } )
134145
@@ -189,24 +200,28 @@ describe('OpenFeature Remote Config and Exposure Events Integration', () => {
189200 }
190201 } )
191202
192- agent . addRemoteConfig ( {
193- product : RC_PRODUCT ,
194- id : configId ,
195- config : ufcPayloads . testBooleanAndStringFlags
196- } )
197-
198- setTimeout ( async ( ) => {
203+ agent . on ( 'remote-config-ack-update' , async ( id , _version , state ) => {
204+ if ( state === UNACKNOWLEDGED ) return
205+ if ( id !== configId ) return
199206 try {
207+ assert . strictEqual ( state , ACKNOWLEDGED )
208+
200209 const response = await fetch ( `${ proc . url } /evaluate-multiple-flags` )
201210 assert . equal ( response . status , 200 )
202211 const data = await response . json ( )
203212 assert . equal ( data . evaluationsCompleted , 6 )
204213
205- // No manual flush - let automatic flush handle it (default 1s interval)
214+ // No manual flush - let automatic flush handle it (default 1s interval)
206215 } catch ( error ) {
207216 done ( error )
208217 }
209- } , 1500 )
218+ } )
219+
220+ agent . addRemoteConfig ( {
221+ product : RC_PRODUCT ,
222+ id : configId ,
223+ config : ufcPayloads . testBooleanAndStringFlags
224+ } )
210225 } )
211226 } )
212227 } )
@@ -261,10 +276,7 @@ describe('OpenFeature Remote Config and Exposure Events Integration', () => {
261276 } )
262277
263278 // Trigger request to start remote config polling
264- fetch ( `${ proc . url } /` ) . then ( ( ) => {
265- // Wait for remote config processing
266- setTimeout ( endIfDone , 200 )
267- } ) . catch ( done )
279+ fetch ( `${ proc . url } /` ) . catch ( done )
268280
269281 let testCompleted = false
270282 function endIfDone ( ) {
0 commit comments