Fix flaky resolveNetworkAddress test#25249
Merged
Conversation
gzdunek
approved these changes
May 4, 2023
Contributor
gzdunek
left a comment
There was a problem hiding this comment.
Converting testProcess.js to ES modules is cool!
| const codeOrSignal = [ | ||
| code && `code ${code}`, | ||
| // code can be 0, so we cannot just check it the same way as the signal. | ||
| code != null && `code ${code}`, |
Contributor
There was a problem hiding this comment.
Can we be more strict? (code !== null)
Member
Author
There was a problem hiding this comment.
This is one of the cases where it covers both null and undefined. I want to perform a truthiness check on a number without treating 0 as falsy.
ryanclark
approved these changes
May 5, 2023
|
@ravicious See the table below for backport results.
|
This was referenced May 9, 2023
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.
I had the
resolveNetworkAddresstest fail randomly.resolveNetworkAddressfailed with the following error:There are two problems here.
Truthiness check
The function which returns this error is called on the
exithandler of a child process:teleport/web/packages/teleterm/src/mainProcess/resolveNetworkAddress.ts
Lines 100 to 115 in 98d3eee
Node.js docs say that either the code or the signal will be non-null, so why is neither of them present in the error message? Well, that's because
codeis a number and if it's0, meaning the process exited without errors, then it's going to evaluate to false.Race condition
The second problem: how did the child process exit without errors yet the test failed? The test spawns a child process running
testProcess.jsand then waits for the process to write{CONNECT_GRPC_PORT: 1337}to its stdout.If the child process
exithandler was triggered before the stdoutdatahandler, then it must mean thattestProcess.jsexited before writing that message to stdout.This is how
testProcess.jslooks like:teleport/web/packages/teleterm/src/mainProcess/testProcess.js
Lines 1 to 19 in 98d3eee
I realized that there's nothing awaiting this anonymous async function, so it's totally possible for the process to just not write anything to stdout. Since top-level await is available in .mjs modules since Node v14, I rewrote the file to use it. This guarantees that the process will write to stdout before exiting.