Skip to content

Commit

Permalink
Added poller to a resumable task store test to increase reliability (#…
Browse files Browse the repository at this point in the history
…778)

For test run using external store implementation (ie. SQL)
  • Loading branch information
thehenrytsai authored Jul 2, 2024
1 parent edf2021 commit f70442c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tbd54566975/dwn-sdk-js",
"version": "0.4.0",
"version": "0.4.1",
"description": "A reference implementation of https://identity.foundation/decentralized-web-node/spec/",
"repository": {
"type": "git",
Expand Down
16 changes: 11 additions & 5 deletions tests/features/resumable-tasks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import chai, { expect } from 'chai';
import { DataStream } from '../../src/utils/data-stream.js';
import { Dwn } from '../../src/dwn.js';
import { Jws } from '../../src/utils/jws.js';
import { Poller } from '../utils/poller.js';
import { RecordsRead } from '../../src/interfaces/records-read.js';
import { RecordsWrite } from '../../src/interfaces/records-write.js';
import { TestDataGenerator } from '../utils/test-data-generator.js';
Expand Down Expand Up @@ -367,14 +368,17 @@ export function testResumableTasks(): void {
await clock.tickAsync(ResumableTaskManager.timeoutExtensionFrequencyInSeconds * 2 * 1000); // advancing time up to 2 extension cycles
// IMPORTANT: This call ensures all scheduled timers are executed
// In theory calling `tickAsync()` or `runToLastAsync()` alone should execute all scheduled timers
// but for some reason this behavior does not happen ONLY in Safari. I found 2o workarounds:
// but for some reason this behavior does not happen ONLY in Safari. I found 2 workarounds:
// 1. call BOTH `tickAsync()` and `runToLastAsync()`.
// 2. call `tickAsync()` with a longer time.
// Chose the first workaround because it is should be the more reliable of the two.
await clock.runToLastAsync();

let latestResumableTaskState = await resumableTaskStore.read(initialResumableTaskState.id);
expect(latestResumableTaskState!.timeout).to.be.greaterThan(initialResumableTaskState.timeout);
let latestResumableTaskState;
await Poller.pollUntilSuccessOrTimeout(async () => {
latestResumableTaskState = await resumableTaskStore.read(initialResumableTaskState.id);
expect(latestResumableTaskState!.timeout).to.be.greaterThan(initialResumableTaskState.timeout);
});

// 5. Signal the mocked code to complete the `RecordsDelete`.
completeDeleteSignal.emit('complete-delete');
Expand All @@ -387,8 +391,10 @@ export function testResumableTasks(): void {
expect(clearTimeoutExtensionTimerSpy.calledOnce).to.be.true;

// 7. Verify that the resumable task is deleted.
latestResumableTaskState = await resumableTaskStore.read(initialResumableTaskState.id);
expect(latestResumableTaskState).to.be.undefined;
await Poller.pollUntilSuccessOrTimeout(async () => {
latestResumableTaskState = await resumableTaskStore.read(initialResumableTaskState.id);
expect(latestResumableTaskState).to.be.undefined;
});
});
});
}

0 comments on commit f70442c

Please sign in to comment.