@@ -12,6 +12,7 @@ import chai, { expect } from 'chai';
1212import { DataStream } from '../../src/utils/data-stream.js' ;
1313import { Dwn } from '../../src/dwn.js' ;
1414import { Jws } from '../../src/utils/jws.js' ;
15+ import { Poller } from '../utils/poller.js' ;
1516import { RecordsRead } from '../../src/interfaces/records-read.js' ;
1617import { RecordsWrite } from '../../src/interfaces/records-write.js' ;
1718import { TestDataGenerator } from '../utils/test-data-generator.js' ;
@@ -367,14 +368,17 @@ export function testResumableTasks(): void {
367368 await clock . tickAsync ( ResumableTaskManager . timeoutExtensionFrequencyInSeconds * 2 * 1000 ) ; // advancing time up to 2 extension cycles
368369 // IMPORTANT: This call ensures all scheduled timers are executed
369370 // In theory calling `tickAsync()` or `runToLastAsync()` alone should execute all scheduled timers
370- // but for some reason this behavior does not happen ONLY in Safari. I found 2o workarounds:
371+ // but for some reason this behavior does not happen ONLY in Safari. I found 2 workarounds:
371372 // 1. call BOTH `tickAsync()` and `runToLastAsync()`.
372373 // 2. call `tickAsync()` with a longer time.
373374 // Chose the first workaround because it is should be the more reliable of the two.
374375 await clock . runToLastAsync ( ) ;
375376
376- let latestResumableTaskState = await resumableTaskStore . read ( initialResumableTaskState . id ) ;
377- expect ( latestResumableTaskState ! . timeout ) . to . be . greaterThan ( initialResumableTaskState . timeout ) ;
377+ let latestResumableTaskState ;
378+ await Poller . pollUntilSuccessOrTimeout ( async ( ) => {
379+ latestResumableTaskState = await resumableTaskStore . read ( initialResumableTaskState . id ) ;
380+ expect ( latestResumableTaskState ! . timeout ) . to . be . greaterThan ( initialResumableTaskState . timeout ) ;
381+ } ) ;
378382
379383 // 5. Signal the mocked code to complete the `RecordsDelete`.
380384 completeDeleteSignal . emit ( 'complete-delete' ) ;
@@ -387,8 +391,10 @@ export function testResumableTasks(): void {
387391 expect ( clearTimeoutExtensionTimerSpy . calledOnce ) . to . be . true ;
388392
389393 // 7. Verify that the resumable task is deleted.
390- latestResumableTaskState = await resumableTaskStore . read ( initialResumableTaskState . id ) ;
391- expect ( latestResumableTaskState ) . to . be . undefined ;
394+ await Poller . pollUntilSuccessOrTimeout ( async ( ) => {
395+ latestResumableTaskState = await resumableTaskStore . read ( initialResumableTaskState . id ) ;
396+ expect ( latestResumableTaskState ) . to . be . undefined ;
397+ } ) ;
392398 } ) ;
393399 } ) ;
394400}
0 commit comments