-
-
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 1 commit
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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -59,8 +59,8 @@ export interface ProcessableSeason { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class BaseScanner<T> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private bundleSize; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private updateRate; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| protected bundleSize; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| protected updateRate; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| protected progress = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| protected items: T[] = []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| protected totalSize?: number = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -792,6 +792,18 @@ class BaseScanner<T> { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| get protectedBundleSize(): number { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return this.bundleSize; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Test-only override to reduce scan delay in unit tests. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Sets updateRate and/or bundleSize for the next run. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public setTestOverrides(opts: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| updateRate?: number; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bundleSize?: number; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }): void { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (opts.updateRate !== undefined) this.updateRate = opts.updateRate; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (opts.bundleSize !== undefined) this.bundleSize = opts.bundleSize; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
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. 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win Validate override values before mutating scanner state. A Proposed validation public setTestOverrides(opts: {
updateRate?: number;
bundleSize?: number;
}): void {
+ if (
+ opts.updateRate !== undefined &&
+ (!Number.isFinite(opts.updateRate) || opts.updateRate < 0)
+ ) {
+ throw new RangeError('updateRate must be a finite, non-negative number');
+ }
+ if (
+ opts.bundleSize !== undefined &&
+ (!Number.isInteger(opts.bundleSize) || opts.bundleSize <= 0)
+ ) {
+ throw new RangeError('bundleSize must be a positive integer');
+ }
if (opts.updateRate !== undefined) this.updateRate = opts.updateRate;
if (opts.bundleSize !== undefined) this.bundleSize = opts.bundleSize;
}📝 Committable suggestion
Suggested change
🤖 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. This is a public, unguarded mutator on a class with live singleton instances ( CC: @seerr-team/seerr-core
Contributor
Author
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. Lowkey didn't realize the Node test runner supported mock timers. I will just go with that, should be a lot simpler. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export default BaseScanner; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -223,6 +223,8 @@ function configureJellyfinWithLibrary( | |
|
|
||
| describe('Jellyfin Scanner', () => { | ||
| beforeEach(async () => { | ||
| jellyfinFullScanner.setTestOverrides({ updateRate: 0 }); | ||
|
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. Same as the Radarr test |
||
|
|
||
| getLibraryContentsImpl = async () => []; | ||
| getItemDataImpl = async () => undefined; | ||
| getSeasonsImpl = async () => []; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,6 +75,7 @@ function fakeRadarrMovie(overrides: Partial<RadarrMovie> = {}): RadarrMovie { | |
|
|
||
| describe('Radarr Scanner', () => { | ||
| beforeEach(() => { | ||
| radarrScanner.setTestOverrides({ updateRate: 0 }); | ||
|
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. Same concern as stated below. Would rather see |
||
| getMoviesImpl = async () => []; | ||
| }); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -163,6 +163,7 @@ function configureSonarr(overrides: Partial<SonarrSettings>[] = [{}]): void { | |
|
|
||
| describe('Sonarr Scanner', () => { | ||
| beforeEach(() => { | ||
| sonarrScanner.setTestOverrides({ updateRate: 0 }); | ||
|
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. Same as the Radarr test |
||
| getSeriesImpl = async () => []; | ||
| getShowByTvdbIdImpl = async () => fakeTmdbShow(1); | ||
| getTvShowImpl = async () => fakeTmdbShow(1); | ||
|
|
||
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.
Imo, no need to widen these.
setTestOverridesis a method on this class, it already has access to the private fields. Widening also makesprotectedBundleSize/protectedUpdateRatebelow redundant for subclasses, now there's two ways to read the same state.