test: add unit tests for retryWithBackoff#7446
Open
sapnilbiswas wants to merge 1 commit into
Open
Conversation
Contributor
|
🧪 Jest Test Results ✅ All Jest tests passed! This PR is ready to merge. Coverage: Statements: 47.58% | Branches: 38.82% | Functions: 52.5% | Lines: 47.98% |
Contributor
Author
|
@walterbender PLease have a look when you get time |
mahesh-09-12
approved these changes
May 31, 2026
mahesh-09-12
left a comment
Contributor
There was a problem hiding this comment.
Tested locally - the added tests cover the retry, backoff, and failure scenarios well.
Collaborator
|
why a separate file when we already have one on master ? need changes |
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 adds a comprehensive Jest test suite for the
js/utils/retryWithBackoff.jsmodule, which handles race conditions (like waiting for container bounds) using an exponential backoff strategy. This previously untested file now has 100% test coverage (statements, branches, functions, and lines).What changed
js/utils/__tests__/retryWithBackoff.test.js— New Jest test file for testing the backoff and retry behavior.Test coverage
check()returns truthy on the first try, it resolves immediately without triggering any delay timeouts.initialDelay * 2^attempt).maxRetriesproperly halts execution and throws anErrorwith the provided (or default)errorMessage.onRetry): Asserts that the optionalonRetrycallback is invoked with the correct attempt index on each failure.setTimeoutwhen a customdelayFnis omitted, and tests the defaultmaxRetries(20) andinitialDelay(50) values.How it is tested
jest.fn()to mock thecheck(),onSuccess(),onRetry(), anddelayFn()functions to strictly verify invocation counts and arguments..mockReturnValueOnce()to simulatecheck()initially failing (returning falsy values) before eventually succeeding on later attempts to test the retry loop.delayFn(which uses standardsetTimeout),jest.useFakeTimers()andjest.advanceTimersByTime()were used to advance the clock instantly, ensuring the tests remain fast and deterministic without actual asynchronous waiting..rejects.toThrow()to validate that the correct error boundaries are hit when the maximum number of retries is exceeded.PR Category