Skip to content

Commit 7b10745

Browse files
authored
Merge branch 'v2' into upgrade-napi-rs
2 parents 217bcd7 + 4556b5c commit 7b10745

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

packages/core/core/src/RequestTracker.js

+2
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,8 @@ export class RequestGraph extends ContentGraph<
332332
this.optionNodeIds.add(nodeId);
333333
}
334334

335+
this.removeCachedRequestChunkForNode(nodeId);
336+
335337
return nodeId;
336338
}
337339

packages/core/core/test/RequestTracker.test.js

+85
Original file line numberDiff line numberDiff line change
@@ -307,4 +307,89 @@ describe('RequestTracker', () => {
307307
assert.strictEqual(cachedResult, 'b');
308308
assert.strictEqual(called, false);
309309
});
310+
311+
it('should write new nodes to cache', async () => {
312+
let tracker = new RequestTracker({farm, options});
313+
314+
tracker.graph.addNode({
315+
type: 0,
316+
id: 'test-file',
317+
});
318+
await tracker.writeToCache();
319+
assert.equal(tracker.graph.nodes.length, 1);
320+
321+
tracker.graph.addNode({
322+
type: 0,
323+
id: 'test-file-2',
324+
});
325+
await tracker.writeToCache();
326+
assert.equal(tracker.graph.nodes.length, 2);
327+
328+
// Create a new tracker from cache
329+
tracker = await RequestTracker.init({farm, options});
330+
331+
await tracker.writeToCache();
332+
assert.equal(tracker.graph.nodes.length, 2);
333+
});
334+
335+
it('should write updated nodes to cache', async () => {
336+
let tracker = new RequestTracker({farm, options});
337+
338+
let contentKey = 'abc';
339+
await tracker.runRequest({
340+
id: contentKey,
341+
type: 7,
342+
run: async ({api}: {api: RunAPI<string | void>, ...}) => {
343+
let result = await Promise.resolve('a');
344+
api.storeResult(result);
345+
},
346+
input: null,
347+
});
348+
assert.equal(await tracker.getRequestResult(contentKey), 'a');
349+
await tracker.writeToCache();
350+
351+
await tracker.runRequest(
352+
{
353+
id: contentKey,
354+
type: 7,
355+
run: async ({api}: {api: RunAPI<string | void>, ...}) => {
356+
let result = await Promise.resolve('b');
357+
api.storeResult(result);
358+
},
359+
input: null,
360+
},
361+
{force: true},
362+
);
363+
assert.equal(await tracker.getRequestResult(contentKey), 'b');
364+
await tracker.writeToCache();
365+
366+
// Create a new tracker from cache
367+
tracker = await RequestTracker.init({farm, options});
368+
369+
assert.equal(await tracker.getRequestResult(contentKey), 'b');
370+
});
371+
372+
it('should write invalidated nodes to cache', async () => {
373+
let tracker = new RequestTracker({farm, options});
374+
375+
let contentKey = 'abc';
376+
await tracker.runRequest({
377+
id: contentKey,
378+
type: 7,
379+
run: () => {},
380+
input: null,
381+
});
382+
let nodeId = tracker.graph.getNodeIdByContentKey(contentKey);
383+
assert.equal(tracker.graph.getNode(nodeId)?.invalidateReason, 0);
384+
await tracker.writeToCache();
385+
386+
tracker.graph.invalidateNode(nodeId, 1);
387+
assert.equal(tracker.graph.getNode(nodeId)?.invalidateReason, 1);
388+
await tracker.writeToCache();
389+
390+
// Create a new tracker from cache
391+
tracker = await RequestTracker.init({farm, options});
392+
393+
assert.equal(tracker.graph.getNode(nodeId)?.invalidateReason, 1);
394+
});
310395
});

0 commit comments

Comments
 (0)