Skip to content

Fix the flakyness of test which verifies there has to be only one npm request at a time #1026

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

Merged
merged 2 commits into from
Jun 3, 2025

Conversation

sheetalkamat
Copy link
Member

No description provided.

@Copilot Copilot AI review requested due to automatic review settings June 3, 2025 19:09
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR aims to fix the flakiness of tests related to npm install requests and improve the testing utilities by adding a hook to verify npm install conditions. The key changes are:

  • Refactoring internal test option fields from unexported (testOptions) to exported (TestOptions) for consistent usage.
  • Introducing a CheckBeforeNpmInstall callback in the test options to synchronize and verify the state before an npm install.
  • Adding a PendingRunRequestsCount method to the TypingsInstaller to assist in tracking pending npm install requests.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
internal/testutil/projecttestutil/projecttestutil.go Renamed testOptions to TestOptions and added CheckBeforeNpmInstall callback
internal/project/ata_test.go Updated test assertions and added a hook using CheckBeforeNpmInstall to control install ordering
internal/project/ata.go Added a new PendingRunRequestsCount method for testing purposes

},
},
TypingsInstallerOptions: project.TypingsInstallerOptions{
ThrottleLimit: 1,
},
})

host.TestOptions.CheckBeforeNpmInstall = func(cwd string, npmInstallArgs []string) {
Copy link
Preview

Copilot AI Jun 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The loop inside the CheckBeforeNpmInstall callback may run indefinitely if the pending run requests count never becomes 1. Consider adding a timeout mechanism to avoid a potential infinite loop and to fail gracefully when the condition is not met.

Suggested change
host.TestOptions.CheckBeforeNpmInstall = func(cwd string, npmInstallArgs []string) {
host.TestOptions.CheckBeforeNpmInstall = func(cwd string, npmInstallArgs []string) {
timeout := 5 * time.Second
startTime := time.Now()

Copilot uses AI. Check for mistakes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, wat happens if the pending requests drop to 0 instead of 1?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it wont thats what it is checking/. initially it might be 0, but we wait till we get 1 and then return from this function to continue npm install so next request cannot start till we return from here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the test infra will time out the test anyway, but it would probably be good do something like this in the loop:

assert.NilError(t, t.Context().Err()

Just so we error out and bail when the test is cancelled.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mainly, I'm just wanting the test to not hang forever if we introduce a bug.

host.TestOptions.CheckBeforeNpmInstall = nil // Stop checking after first run
break
}
time.Sleep(10 * time.Millisecond)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do this without sleeps?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically this thing is waiting to ensure that there is request in the queue - should i just keep looping till i see that instead of sleep ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we'd have a version that doesn't require sleeping, since we have nicer things available in Go for managing queues and waiting for done. Probably not possible in the current layout, at least.

Copy link
Member

@jakebailey jakebailey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No more failures in my local testing, thanks.

@sheetalkamat sheetalkamat enabled auto-merge June 3, 2025 21:26
@sheetalkamat sheetalkamat added this pull request to the merge queue Jun 3, 2025
Merged via the queue into main with commit db8c64e Jun 3, 2025
23 checks passed
@sheetalkamat sheetalkamat deleted the fixFlakyATATest branch June 3, 2025 21:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants