Skip to content

Commit f70442c

Browse files
authored
Added poller to a resumable task store test to increase reliability (#778)
For test run using external store implementation (ie. SQL)
1 parent edf2021 commit f70442c

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tbd54566975/dwn-sdk-js",
3-
"version": "0.4.0",
3+
"version": "0.4.1",
44
"description": "A reference implementation of https://identity.foundation/decentralized-web-node/spec/",
55
"repository": {
66
"type": "git",

tests/features/resumable-tasks.spec.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import chai, { expect } from 'chai';
1212
import { DataStream } from '../../src/utils/data-stream.js';
1313
import { Dwn } from '../../src/dwn.js';
1414
import { Jws } from '../../src/utils/jws.js';
15+
import { Poller } from '../utils/poller.js';
1516
import { RecordsRead } from '../../src/interfaces/records-read.js';
1617
import { RecordsWrite } from '../../src/interfaces/records-write.js';
1718
import { 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

Comments
 (0)