-
Notifications
You must be signed in to change notification settings - Fork 659
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ package project_test | |
import ( | ||
"slices" | ||
"testing" | ||
"time" | ||
|
||
"github.com/microsoft/typescript-go/internal/bundled" | ||
"github.com/microsoft/typescript-go/internal/core" | ||
|
@@ -215,16 +216,12 @@ func TestAta(t *testing.T) { | |
_, p2 := service.EnsureDefaultProjectForFile("/user/username/projects/project2/app.js") | ||
var installStatuses []project.TypingsInstallerStatus | ||
installStatuses = append(installStatuses, <-host.ServiceOptions.InstallStatus, <-host.ServiceOptions.InstallStatus) | ||
// Order can be non deterministic since they both will run in parallel | ||
assert.Assert(t, slices.Contains(installStatuses, project.TypingsInstallerStatus{ | ||
RequestId: 1, | ||
Project: p1, | ||
Status: "Success", | ||
// Order can be non deterministic since they both will run in parallel - not looking into request ID | ||
assert.Assert(t, slices.ContainsFunc(installStatuses, func(s project.TypingsInstallerStatus) bool { | ||
return s.Project == p1 && s.Status == "Success" | ||
})) | ||
assert.Assert(t, slices.Contains(installStatuses, project.TypingsInstallerStatus{ | ||
RequestId: 2, | ||
Project: p2, | ||
Status: "Success", | ||
assert.Assert(t, slices.ContainsFunc(installStatuses, func(s project.TypingsInstallerStatus) bool { | ||
return s.Project == p2 && s.Status == "Success" | ||
})) | ||
}) | ||
|
||
|
@@ -242,6 +239,7 @@ func TestAta(t *testing.T) { | |
"typeAcquisition": { "include": ["grunt", "gulp", "commander"] }, | ||
}`, | ||
} | ||
expectedP1First := true | ||
service, host := projecttestutil.Setup(files, &projecttestutil.TestTypingsInstaller{ | ||
TestTypingsInstallerOptions: projecttestutil.TestTypingsInstallerOptions{ | ||
PackageToFile: map[string]string{ | ||
|
@@ -250,31 +248,40 @@ func TestAta(t *testing.T) { | |
"lodash": "declare const lodash: { x: number }", | ||
"cordova": "declare const cordova: { x: number }", | ||
"grunt": "declare const grunt: { x: number }", | ||
"gulp": "declare const grunt: { x: number }", | ||
"gulp": "declare const gulp: { x: number }", | ||
}, | ||
}, | ||
TypingsInstallerOptions: project.TypingsInstallerOptions{ | ||
ThrottleLimit: 1, | ||
}, | ||
}) | ||
|
||
host.TestOptions.CheckBeforeNpmInstall = func(cwd string, npmInstallArgs []string) { | ||
for { | ||
pendingCount := service.TypingsInstaller().PendingRunRequestsCount() | ||
if pendingCount == 1 { | ||
if slices.Contains(npmInstallArgs, "@types/gulp@latest") { | ||
expectedP1First = false | ||
} | ||
host.TestOptions.CheckBeforeNpmInstall = nil // Stop checking after first run | ||
break | ||
} | ||
assert.NilError(t, t.Context().Err()) | ||
time.Sleep(10 * time.Millisecond) | ||
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. Can we do this without sleeps? 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. 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 ? 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. 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. |
||
} | ||
} | ||
|
||
service.OpenFile("/user/username/projects/project1/app.js", files["/user/username/projects/project1/app.js"].(string), core.ScriptKindJS, "") | ||
service.OpenFile("/user/username/projects/project2/app.js", files["/user/username/projects/project2/app.js"].(string), core.ScriptKindJS, "") | ||
_, p1 := service.EnsureDefaultProjectForFile("/user/username/projects/project1/app.js") | ||
_, p2 := service.EnsureDefaultProjectForFile("/user/username/projects/project2/app.js") | ||
// Order is determinate since second install will run only after completing first one | ||
status := <-host.ServiceOptions.InstallStatus | ||
assert.Equal(t, status, project.TypingsInstallerStatus{ | ||
RequestId: 1, | ||
Project: p1, | ||
Status: "Success", | ||
}) | ||
assert.Equal(t, status.Project, core.IfElse(expectedP1First, p1, p2)) | ||
assert.Equal(t, status.Status, "Success") | ||
status = <-host.ServiceOptions.InstallStatus | ||
assert.Equal(t, status, project.TypingsInstallerStatus{ | ||
RequestId: 2, | ||
Project: p2, | ||
Status: "Success", | ||
}) | ||
assert.Equal(t, status.Project, core.IfElse(expectedP1First, p2, p1)) | ||
assert.Equal(t, status.Status, "Success") | ||
}) | ||
|
||
t.Run("discover from node_modules", func(t *testing.T) { | ||
|
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.
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.
Copilot uses AI. Check for mistakes.
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.
Yeah, wat happens if the pending requests drop to 0 instead of 1?
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.
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
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.
I guess the test infra will time out the test anyway, but it would probably be good do something like this in the loop:
Just so we error out and bail when the test is cancelled.
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.
Mainly, I'm just wanting the test to not hang forever if we introduce a bug.