Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added poller to a resumable task store test to increase reliability #778

Merged
merged 2 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
});
});
});
}