Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5f7b786dda |
@@ -289,6 +289,10 @@ export const runBackup = async (
|
|||||||
collection: string,
|
collection: string,
|
||||||
err: unknown,
|
err: unknown,
|
||||||
): void => {
|
): void => {
|
||||||
|
// Count at most one attempt per file per run: a file whose original
|
||||||
|
// and thumbnail both fail this run must not double its attempt count
|
||||||
|
// or appear twice in errors.
|
||||||
|
if (failedThisRun.has(file.id)) return;
|
||||||
const error = errorMessage(err);
|
const error = errorMessage(err);
|
||||||
errors.push({
|
errors.push({
|
||||||
fileID: file.id,
|
fileID: file.id,
|
||||||
|
|||||||
+22
-1
@@ -111,6 +111,7 @@ class MockClient {
|
|||||||
// told to fail one fileID's original, to exercise per-file resilience.
|
// told to fail one fileID's original, to exercise per-file resilience.
|
||||||
interface StubSource extends ContentSource {
|
interface StubSource extends ContentSource {
|
||||||
failID?: number;
|
failID?: number;
|
||||||
|
failThumbID?: number;
|
||||||
originalCalls: number;
|
originalCalls: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,7 +125,8 @@ const stubSource = (): StubSource => {
|
|||||||
writeFileSync(destination, Buffer.alloc(size));
|
writeFileSync(destination, Buffer.alloc(size));
|
||||||
return { bytesWritten: size };
|
return { bytesWritten: size };
|
||||||
},
|
},
|
||||||
thumbnail: async ({ destination }) => {
|
thumbnail: async ({ file: f, destination }) => {
|
||||||
|
if (s.failThumbID === f.id) throw new Error("HTTP 500 from server");
|
||||||
writeFileSync(destination, Buffer.alloc(5));
|
writeFileSync(destination, Buffer.alloc(5));
|
||||||
return { bytesWritten: 5 };
|
return { bytesWritten: 5 };
|
||||||
},
|
},
|
||||||
@@ -454,4 +456,23 @@ describe("lib.backup", () => {
|
|||||||
expect(existsSync(join(outDir, "thumbnails", "200.jpg"))).toBe(true);
|
expect(existsSync(join(outDir, "thumbnails", "200.jpg"))).toBe(true);
|
||||||
lib.close();
|
lib.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("counts one attempt when a file fails both its original and thumbnail in a run", async () => {
|
||||||
|
const source = stubSource();
|
||||||
|
source.failID = 101;
|
||||||
|
source.failThumbID = 101;
|
||||||
|
const lib = await openLibrary(source);
|
||||||
|
const outDir = join(root, "backup");
|
||||||
|
|
||||||
|
const result = await lib.backup({
|
||||||
|
downloadDirectory: outDir,
|
||||||
|
includeThumbnails: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Both kinds fail for 101, but the run counts it once.
|
||||||
|
const errs = result.errors.filter((e) => e.fileID === 101);
|
||||||
|
expect(errs.length).toBe(1);
|
||||||
|
expect(readLedger(outDir).files["101"]!.attempts).toBe(1);
|
||||||
|
lib.close();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user