-
-
Notifications
You must be signed in to change notification settings - Fork 987
test: add scanner update rate override for testing #3241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,29 @@ | ||||||||||||||||||||||||||||||||||||||||
| import { mock } from 'node:test'; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| export async function runWithMockTimers<T>( | ||||||||||||||||||||||||||||||||||||||||
| runPromise: Promise<T>, | ||||||||||||||||||||||||||||||||||||||||
| tickMs = 4000 | ||||||||||||||||||||||||||||||||||||||||
| ): Promise<T> { | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+3
to
+6
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Takes an already-invoked Promise instead of a factory. Its fine as it is for now since |
||||||||||||||||||||||||||||||||||||||||
| mock.timers.enable({ apis: ['setTimeout'] }); | ||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||
| let settled = false; | ||||||||||||||||||||||||||||||||||||||||
| runPromise | ||||||||||||||||||||||||||||||||||||||||
| .catch(() => undefined) | ||||||||||||||||||||||||||||||||||||||||
| .finally(() => { | ||||||||||||||||||||||||||||||||||||||||
| settled = true; | ||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||
| const maxTicks = 100000; | ||||||||||||||||||||||||||||||||||||||||
| for (let i = 0; i < maxTicks && !settled; i++) { | ||||||||||||||||||||||||||||||||||||||||
| await new Promise((resolve) => setImmediate(resolve)); | ||||||||||||||||||||||||||||||||||||||||
| mock.timers.tick(tickMs); | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| if (!settled) { | ||||||||||||||||||||||||||||||||||||||||
| throw new Error( | ||||||||||||||||||||||||||||||||||||||||
| `runWithMockTimers: promise did not settle after ${maxTicks} ticks` | ||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+16
to
+24
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- file ---'
cat -n server/test/runWithMockTimers.ts
printf '%s\n' '--- references ---'
rg -n --glob '!node_modules' 'runWithMockTimers|mock\.timers\.tick|setImmediate' server package.jsonRepository: seerr-team/seerr Length of output: 5464 🏁 Script executed: #!/bin/bash
set -eu
node --input-type=commonjs <<'JS'
const { mock } = require('node:test');
async function probe(runPromise, maxTicks = 3, tickMs = 1) {
mock.timers.enable({ apis: ['setTimeout'] });
try {
let settled = false;
runPromise
.catch(() => undefined)
.finally(() => {
settled = true;
});
for (let i = 0; i < maxTicks && !settled; i++) {
await new Promise((resolve) => setImmediate(resolve));
mock.timers.tick(tickMs);
if (i === maxTicks - 1) {
console.log('immediately after final tick:', settled);
}
}
console.log('guard sees settled:', settled);
return settled;
} finally {
mock.timers.reset();
}
}
let release;
const runPromise = new Promise((resolve) => {
release = resolve;
});
setTimeout(() => release('done'), 3);
probe(runPromise).then(() => {
setImmediate(() => console.log('after one additional setImmediate:', true));
});
JSRepository: seerr-team/seerr Length of output: 256 Flush promise callbacks before applying the guard. If the final 🤖 Prompt for AI Agents
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @michaelhthomas can you add one more flush before the check?
Comment on lines
+16
to
+24
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||
| return await runPromise; | ||||||||||||||||||||||||||||||||||||||||
| } finally { | ||||||||||||||||||||||||||||||||||||||||
| mock.timers.reset(); | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sonarr was being imported before the
getTvShowmock which caused it to not work. Moved it here so the mock actually applies.