test: add unit tests for retryWithBackoff#7446
Conversation
|
🧪 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% |
|
@walterbender PLease have a look when you get time |
mahesh-09-12
left a comment
There was a problem hiding this comment.
Tested locally - the added tests cover the retry, backoff, and failure scenarios well.
|
why a separate file when we already have one on master ? need changes |
|
Please see the comment by Ahsutosh |
|
checking in again for any updates @sapnilbiswas |
|
@Ashutoshx7 I apologize for being this late in responding, I was actually going through some end-sem exams and was unable to keep on working on it. I will be back to contributing in a week. |
Ya sure |
|
This PR has merge conflicts with Please rebase your branch: # Add upstream remote (one-time setup)
git remote add upstream https://github.com/sugarlabs/musicblocks.git
# Fetch latest master and rebase
git fetch upstream
git rebase upstream/master
# Resolve any conflicts, then:
git push --force-with-lease origin YOUR_BRANCH
|
93f728c to
4af6b22
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #7446 +/- ##
=======================================
Coverage 58.38% 58.38%
=======================================
Files 174 174
Lines 57894 57894
=======================================
+ Hits 33800 33802 +2
+ Misses 24094 24092 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
4af6b22 to
b43de39
Compare
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