-
Notifications
You must be signed in to change notification settings - Fork 7
Fix TestUpdateNPMInstall timing out on a cold npm cache #485
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
joe4dev
wants to merge
1
commit into
main
Choose a base branch
from
devx-1108-npm-install-test-timeout
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -94,7 +94,25 @@ func TestUpdateNPMInstall(t *testing.T) { | |
| t.Skipf("lstk already installed at %s, would conflict with npm install -g", path) | ||
| } | ||
|
|
||
| ctx := testContext(t) | ||
| // Not testContext: nearly all of this test's time goes into the registry | ||
| // install below, and that cost is set by the registry, not by anything here. | ||
| // Green runs on windows-latest land at 19-81s, but on a slow day the install | ||
| // alone has stretched past two minutes (one run's npm reported ~3m), so the | ||
| // shared 2-minute budget turned a slow registry into a red build on both | ||
| // Linux and Windows with no code change. Five minutes clears the observed | ||
| // worst case several times over; what follows the install is cheap by | ||
| // comparison (a `go build`, then `lstk update`'s own `npm install -g`, which | ||
| // reuses the cache the first install just filled: ~1s each measured warm). | ||
| // | ||
| // The platforms report this timeout very differently, which is worth | ||
| // knowing when reading a failure. Linux is honest: "signal: killed", with | ||
| // the test duration pinned at exactly the deadline. Windows is not: npm | ||
| // there is a .cmd wrapper around node, so killing it leaves the node | ||
| // grandchild to finish and write its success summary into the still-open | ||
| // pipe, and the failure reads "exit status 1" beside output claiming the | ||
| // install succeeded. | ||
| ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) | ||
| t.Cleanup(cancel) | ||
|
|
||
| // Set up a fake local npm project so we get a binary inside node_modules. | ||
| // On Windows, t.TempDir() may return a short 8.3 path (e.g. RUNNER~1) | ||
|
|
@@ -107,11 +125,20 @@ func TestUpdateNPMInstall(t *testing.T) { | |
| 0o644, | ||
| )) | ||
|
|
||
| // Install @localstack/lstk locally so the node_modules structure exists | ||
| npmInstall := exec.CommandContext(ctx, "npm", "install", "@localstack/lstk") | ||
| // Install @localstack/lstk locally so the node_modules structure exists. | ||
| // --no-audit/--no-fund skip an audit round trip this test has no use for; | ||
| // small next to the cold-download time, but free. WaitDelay matters because | ||
| // npm is a wrapper (npm.cmd on Windows) around node: killing it on a | ||
| // deadline leaves the node grandchild holding the output pipe, and | ||
| // CombinedOutput would block for that grandchild's full lifetime (the | ||
| // DEVX-846 lesson). | ||
| npmInstall := exec.CommandContext(ctx, "npm", "install", "--no-audit", "--no-fund", "@localstack/lstk") | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. supporting change: skipping audit and fund is recommended in CI https://www.lowlydba.com/cicd-npm-flags/ |
||
| npmInstall.Dir = projectDir | ||
| npmInstall.WaitDelay = 10 * time.Second | ||
| out, err := npmInstall.CombinedOutput() | ||
| require.NoError(t, err, "npm install failed: %s", string(out)) | ||
| // Report ctx.Err() alongside the output: npm prints its success summary even | ||
| // when it is killed part-way, so the output alone is actively misleading. | ||
| require.NoError(t, err, "npm install failed (ctx err: %v): %s", ctx.Err(), string(out)) | ||
|
|
||
| // Build a fake old version binary and replace the one in node_modules | ||
| platformPkg := npmPlatformPackage() | ||
|
|
@@ -141,10 +168,12 @@ func TestUpdateNPMInstall(t *testing.T) { | |
| // The update should always use `npm install -g` regardless of local/global context. | ||
| cmd := exec.CommandContext(ctx, nmBinaryPath, "update", "--non-interactive") | ||
| cmd.Dir = projectDir | ||
| // Same grandchild reasoning as the install above: this shells out to npm. | ||
| cmd.WaitDelay = 10 * time.Second | ||
| stdout, err := cmd.CombinedOutput() | ||
| stdoutStr := string(stdout) | ||
|
|
||
| require.NoError(t, err, "lstk update failed: %s", stdoutStr) | ||
| require.NoError(t, err, "lstk update failed (ctx err: %v): %s", ctx.Err(), stdoutStr) | ||
| requireExitCode(t, 0, err) | ||
| assert.Contains(t, stdoutStr, "npm install -g", "should always use global install") | ||
| assert.Contains(t, stdoutStr, "Updated to", "should complete the update") | ||
|
|
||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
main change: increasing timeout from 2 min to 5 min