Repository navigation
fix: flaky tests and unhandled bus subscription rejection - #129
Merged
Merged
Conversation
Four tests waited exactly the ttl before expecting the entry to be expired. Timers can fire up to a millisecond before Date.now() reaches the expiration, so the entry was sometimes still fresh and the factory was not called. Wait 150ms for a 100ms ttl instead, and leave a margin after the slow factory in the soft timeout test. Amp-Thread-ID: https://ampcode.com/threads/T-01a1cc89-88ff-735a-b0e6-546b99965804
The bus subscribed to its channel without awaiting or catching the promise. When the cache was disconnected before the subscriber connection was ready, ioredis rejected the pending SUBSCRIBE with "Connection is closed." and the rejection was unhandled. This failed the test suite intermittently and can crash an application. Log the error instead. Amp-Thread-ID: https://ampcode.com/threads/T-01a1cc89-88ff-735a-b0e6-546b99965804
🦋 Changeset detectedLatest commit: eee2a25 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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 the intermittent failures of the
testsjob. I found two causes in the CI history (older logs have expired) and by running the suite in a loop.1. Unhandled rejection
Connection is closed.(bug inBus)The
Busconstructor calledthis.#bus.subscribe(...)without awaiting or catching the returned promise. When a cache is disconnected before its Redis subscriber connection is ready, ioredis rejects the queuedSUBSCRIBEwithConnection is closed.. Nothing catches that rejection. Japa then fails the run after every test has passed:The same thing can crash an application that disconnects while Redis is unreachable. The rejection is now caught and logged. The new regression test
disconnecting before the bus subscription is ready does not leave an unhandled rejectionfails without the fix (expected [ Error: Connection is closed. ] to deeply equal []). Abentocachepatch changeset is included.2. Tests that wait exactly the TTL
isLogicallyExpired()checksDate.now() >= logicalExpiration. AsetTimeoutcan fire up to one millisecond beforeDate.now()reaches that value. These four tests waitedsleep(100)for attl: 100and then expected the entry to be expired:Two tier cache / should returns old value if factory throws and grace enabled. CI failed withPlanned for 3 assertions, but ran 2.Factory Context / can access graced entry. It failed locally.Two tier cache / rethrows error when suppressL2Errors is falseOne tier cache / soft timeout should returns old value if factory take too longThey now wait 150ms. The soft timeout test also waits 100ms instead of 50ms after the 550ms factory.
The two
deleteByTagraces intagging.spec.tswere already fixed in #127.Verification
I ran all non-driver test files against local Redis and Valkey, with
CI=1as in CI:Lint, formatting and typecheck pass.