Skip to content
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
2 changes: 1 addition & 1 deletion graphify-out/graph.json

Large diffs are not rendered by default.

18 changes: 11 additions & 7 deletions lib/hosts/uploads.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -598,22 +598,26 @@ test("a resumed upload waits for the failed attempt's file cleanup", async (t) =
assert.deepEqual(new Uint8Array(readFileSync(join(dir, `${id}.part`))), bytes);
});

test("resuming an open upload clears pending old progress before adopting its next attempt", async () => {
test("resuming an open upload never relabels pending old progress as its next attempt", async (t) => {
// The progress timer fires only when the test says so, however long the start's sweep takes.
t.mock.timers.enable({ apis: ["setTimeout"] });
const { staged, acks } = staging();
const id = randomUUID();
const oldAttempt = randomUUID();
const newAttempt = randomUUID();
const args = { id, name: "pending.bin", size: 3, type: "" };
await staged.start({ ...args, attempt: oldAttempt });
staged.write(id, new Uint8Array(1));
await staged.open.get(id).chain;
await staged.open.get(id).chain; // the old attempt's progress ack is now pending
assert.deepEqual(await staged.start({ ...args, attempt: newAttempt }), { received: 1, done: false });
await sleep(40);
assert.deepEqual(acks, [], "old coalesced progress is cancelled, not relabelled as the new attempt");
t.mock.timers.tick(1000);
// Main drops acks of a superseded attempt; only old progress relabelled as the new attempt would be wrong.
const newAcks = () => acks.filter((ack) => ack.attempt === newAttempt);
assert.deepEqual(newAcks(), [], "old coalesced progress is not relabelled as the new attempt");
const upload = staged.open.get(id);
staged.write(id, new Uint8Array(2));
await until(() => acks.length === 1, "the final ack");
assert.equal(acks[0].attempt, newAttempt);
assert.equal(acks[0].done, true);
await upload.chain;
assert.deepEqual(newAcks().map(({ received, done }) => ({ received, done })), [{ received: 3, done: true }]);
});

test("sanitizeUploadName caps bytes, renames Windows device names, strips trailing dots, spaces and bidi controls", () => {
Expand Down
Loading