- Notifications
You must be signed in to change notification settings - Fork906
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
c09c9b9
476fe71
8c8bca6
7ce4eea
52ac64e
362db7c
dcc7379
ff66b3f
efff5d9
cebd5db
2679138
9feebef
b117b5c
a22b414
9bbd2c7
5804201
7e8dcee
725f97b
a9b1567
21ee970
e54d7e7
2799858
1d93003
763fc12
0f879c7
61784c9
604eb27
bf4d2cf
38b4f0d
20df538
4bb3b68
83972db
146b158
5eb16cd
730d803
150adc0
b4ecf10
3fa3edf
7e45919
a632508
72125ec
b65eea7
e1339f3
c1a8ba6
5363dcc
7ad9b6d
394571d
890747b
b3870db
File 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.