Fix : RequestManager ignoring explicit 0 config values#5795
Closed
Chaitu7032 wants to merge 1 commit intosugarlabs:masterfrom
Closed
Fix : RequestManager ignoring explicit 0 config values#5795Chaitu7032 wants to merge 1 commit intosugarlabs:masterfrom
Chaitu7032 wants to merge 1 commit intosugarlabs:masterfrom
Conversation
Contributor
|
✅ All Jest tests passed! This PR is ready to merge. |
Contributor
Author
|
@walterbender sir , @omsuneri This fixes a bug where RequestManager treated explicit 0 config values as unset due to ||, and adds a test to ensure 0 is preserved using ??. thanking you ... |
Contributor
Author
|
@walterbender sir , if you have some time could you please have a look at this . |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes a silent misconfiguration bug in RequestManager where explicit numeric 0 configuration values were ignored and replaced with defaults.
It also adds a focused unit test to prevent regressions and to prove that explicit 0 values are preserved for all relevant options.
What happened (bug / impact)
In the
RequestManagerconstructor, defaults were applied using:options.foo || defaultBecause
0is falsy in JavaScript, passing any of the following valid and intentional configurations:{ minDelay: 0 }→ disable throttling delay{ maxRetries: 0 }→ disable retries{ baseRetryDelay: 0 }→ disable backoff delay (common in tests){ maxConcurrent: 0 }→ edge case: caller expects “no concurrent execution” semanticsImpact
Fix given (what changed / why it’s correct)
The constructor now uses nullish coalescing
(??)instead of logical OR(||)for defaulting:this.minDelay = options.minDelay ?? 500; this.maxRetries = options.maxRetries ?? 3; this.baseRetryDelay = options.baseRetryDelay ?? 1000; this.maxConcurrent = options.maxConcurrent ?? 3;Why this is correct
??only falls back when the value isnullorundefined0is preserved (as intended)Changed files
planet/js/RequestManager.jsplanet/js/__tests__/RequestManager.test.jsHow I tested (what I ran)
Targeted Jest run (clean, no coverage collection):
npm test -- --runTestsByPath "planet/js/__tests__/RequestManager.test.js" --coverage=falseNew test added
A unit test that constructs:
new RequestManager({ minDelay: 0, maxRetries: 0, baseRetryDelay: 0, maxConcurrent: 0 });and asserts that all instance fields remain 0.
Before fix - failing test
The new test fails when the constructor uses
||, proving the bug existed.How it was produced (local only, not committed):
Before fix: explicit 0 values ignored (test fails)
After fix - passing test (proof of resolution)
With
??in place, the same test now passes, confirming the fix.Scope / non-goals
Scope
Constructor defaulting logic for four numeric options only
Non-goals
Edge note
{ maxConcurrent: 0 }now remains 0 (previously defaulted to 3)If any code relied on the old buggy behavior, it will now behave as configured, which matches the intended contract .
testing