- Notifications
You must be signed in to change notification settings - Fork1.1k
feat: reinitialize agents when a prebuilt workspace is claimed#17475
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
c09c9b9476fe718c8bca67ce4eea52ac64e362db7cdcc7379ff66b3fefff5d9cebd5db26791389feebefb117b5ca22b4149bbd2c758042017e8dcee725f97ba9b156721ee970e54d7e727998581d93003763fc120f879c761784c9604eb27bf4d2cf38b4f0d20df5384bb3b6883972db146b1585eb16cd730d803150adc0b4ecf103fa3edf7e45919a63250872125ecb65eea7e1339f3c1a8ba65363dcc7ad9b6d394571d890747bb3870dbFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1105,6 +1105,69 @@ func (w WorkspaceAgentWaiter) MatchResources(m func([]codersdk.WorkspaceResource | ||
| return w | ||
| } | ||
| // WaitForAgentFn represents a boolean assertion to be made against each agent | ||
| // that a given WorkspaceAgentWaited knows about. Each WaitForAgentFn should apply | ||
| // the check to a single agent, but it should be named for plural, because `func (w WorkspaceAgentWaiter) WaitFor` | ||
| // applies the check to all agents that it is aware of. This ensures that the public API of the waiter | ||
| // reads correctly. For example: | ||
| // | ||
| // waiter := coderdtest.NewWorkspaceAgentWaiter(t, client, r.Workspace.ID) | ||
| // waiter.WaitFor(coderdtest.AgentsReady) | ||
| type WaitForAgentFn func(agent codersdk.WorkspaceAgent) bool | ||
| // AgentsReady checks that the latest lifecycle state of an agent is "Ready". | ||
| func AgentsReady(agent codersdk.WorkspaceAgent) bool { | ||
| return agent.LifecycleState == codersdk.WorkspaceAgentLifecycleReady | ||
| } | ||
| // AgentsNotReady checks that the latest lifecycle state of an agent is anything except "Ready". | ||
| func AgentsNotReady(agent codersdk.WorkspaceAgent) bool { | ||
| return !AgentsReady(agent) | ||
| } | ||
| func (w WorkspaceAgentWaiter) WaitFor(criteria ...WaitForAgentFn) { | ||
| w.t.Helper() | ||
| agentNamesMap := make(map[string]struct{}, len(w.agentNames)) | ||
| for _, name := range w.agentNames { | ||
| agentNamesMap[name] = struct{}{} | ||
| } | ||
| ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong) | ||
| defer cancel() | ||
| w.t.Logf("waiting for workspace agents (workspace %s)", w.workspaceID) | ||
| require.Eventually(w.t, func() bool { | ||
| var err error | ||
| workspace, err := w.client.Workspace(ctx, w.workspaceID) | ||
| if err != nil { | ||
| return false | ||
| } | ||
| if workspace.LatestBuild.Job.CompletedAt == nil { | ||
| return false | ||
| } | ||
| if workspace.LatestBuild.Job.CompletedAt.IsZero() { | ||
| return false | ||
| } | ||
| for _, resource := range workspace.LatestBuild.Resources { | ||
| for _, agent := range resource.Agents { | ||
SasSwart marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| if len(w.agentNames) > 0 { | ||
| if _, ok := agentNamesMap[agent.Name]; !ok { | ||
| continue | ||
| } | ||
| } | ||
| for _, criterium := range criteria { | ||
| if !criterium(agent) { | ||
| return false | ||
| } | ||
| } | ||
| } | ||
| } | ||
| return true | ||
| }, testutil.WaitLong, testutil.IntervalMedium) | ||
| } | ||
| // Wait waits for the agent(s) to connect and fails the test if they do not within testutil.WaitLong | ||
| func (w WorkspaceAgentWaiter) Wait() []codersdk.WorkspaceResource { | ||
| w.t.Helper() | ||
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.