Skip to content

Commit

Permalink
Update unit test for RequestTracker
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeLane committed Feb 9, 2024
1 parent 921c7ba commit 6d339a6
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions packages/core/core/test/RequestTracker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,33 @@ describe('RequestTracker', () => {
);
});

it('should stop writing to cache when the abort controller aborts', async () => {
it('should write cache to disk and store index', async () => {
let tracker = new RequestTracker({farm, options});

await tracker.runRequest({
id: 'abc',
type: 7,
run: async ({api}: {api: RunAPI<string | void>, ...}) => {
let result = await Promise.resolve();
api.storeResult(result);
},
input: null,
});

await tracker.writeToCache();

assert(tracker.cachedRequests.size > 0);
});

it('should not write to cache when the abort controller aborts', async () => {
let tracker = new RequestTracker({farm, options});

const abortController = new AbortController();
abortController.abort();

// $FlowFixMe[prop-missing] Rejects is missing on assert type
await assert.rejects(tracker.writeToCache(abortController.signal));
await tracker.writeToCache(abortController.signal);

assert(tracker.cachedRequests.size === 0);
});

it('should not requeue requests if the previous request is still running', async () => {
Expand Down

0 comments on commit 6d339a6

Please sign in to comment.