fix: using setImmediate for error handle in log displayer unit test #3417
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
Fixes a race condition in the "403 error after connection" test that caused intermittent failures in GitHub Actions, we see here. The test was using
setImmediateto schedule the error event after emitting messages, which could cause the error handler to execute before message handlers completed, resulting in the wrong error message.Type of Change
Testing
Additional Context
Problem:
The test "when the log server returns a 403 error after connection" was failing intermittently in GitHub Actions (and locally ~10% of the time). The test would expect "Log stream access expired. Please try again." but receive "You can't access this space from your IP address. Contact your team admin."
Root Cause:
After emitting messages synchronously, the test used
setImmediateto schedule the error event. In some cases, especially under load or in CI environments, the error handler would execute before the message handlers had completed settinghasReceivedMessages = true, causing the wrong error message to be returned.Solution:
Replaced
setImmediatewithprocess.nextTickwhen emitting the error after messages. This ensures the current execution phase completes before the error is emitted, guaranteeing that message handlers finish and sethasReceivedMessages = truebefore the error handler checks it.Change:
packages/cli/test/unit/lib/run/log-displayer.unit.test.tsline 240-242 to useprocess.nextTickinstead ofsetImmediatefor error emission timingRelated Issue
W-20247783