-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3248 from OpenNeuroOrg/cache-miss-exception
fix(server): Prevent doNotCache error when an exception occurs during a cache miss
- Loading branch information
Showing
2 changed files
with
36 additions
and
2 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
packages/openneuro-server/src/cache/__tests__/item.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import CacheItem from "../item" | ||
import { CacheType } from "../types" | ||
|
||
const redisMock = vi.fn(() => ({ | ||
getBuffer: vi.fn(), | ||
setex: vi.fn(), | ||
set: vi.fn(), | ||
})) | ||
|
||
describe("CacheItem", () => { | ||
it("should succeed when the cache miss sets doNotCache but throws an exception", async () => { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const item = new CacheItem(redisMock() as any, CacheType.commitFiles, [ | ||
"ds000001", | ||
"12345678", | ||
]) | ||
let fail = true | ||
expect( | ||
await item.get(async (doNotCache) => { | ||
// On the first try | ||
if (fail) { | ||
fail = false | ||
doNotCache(true) | ||
throw new Error("expected failure") | ||
} else { | ||
doNotCache(false) | ||
return true | ||
} | ||
}), | ||
).toBe(true) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters