MCPcopy Index your code
hub / github.com/coder/coder / Wait

Method Wait

coderd/coderdtest/coderdtest.go:1390–1440  ·  view source on GitHub ↗

Wait waits for the agent(s) to connect and fails the test if they do not connect before the waiter's context is canceled.

()

Source from the content-addressed store, hash-verified

1388// Wait waits for the agent(s) to connect and fails the test if they do not connect before the
1389// waiter's context is canceled.
1390func (w WorkspaceAgentWaiter) Wait() []codersdk.WorkspaceResource {
1391 w.t.Helper()
1392
1393 agentNamesMap := make(map[string]struct{}, len(w.agentNames))
1394 for _, name := range w.agentNames {
1395 agentNamesMap[name] = struct{}{}
1396 }
1397
1398 ctx := w.ctx
1399 if w.ctx == nil {
1400 ctx = testutil.Context(w.t, testutil.WaitLong)
1401 }
1402
1403 w.t.Logf("waiting for workspace agents (workspace %s)", w.workspaceID)
1404 var resources []codersdk.WorkspaceResource
1405 testutil.Eventually(ctx, w.t, func(ctx context.Context) bool {
1406 var err error
1407 workspace, err := w.client.Workspace(ctx, w.workspaceID)
1408 if err != nil {
1409 return false
1410 }
1411 if workspace.LatestBuild.Job.CompletedAt == nil {
1412 return false
1413 }
1414 if workspace.LatestBuild.Job.CompletedAt.IsZero() {
1415 return false
1416 }
1417
1418 for _, resource := range workspace.LatestBuild.Resources {
1419 for _, agent := range resource.Agents {
1420 if len(w.agentNames) > 0 {
1421 if _, ok := agentNamesMap[agent.Name]; !ok {
1422 continue
1423 }
1424 }
1425
1426 if agent.Status != codersdk.WorkspaceAgentConnected {
1427 w.t.Logf("agent %s not connected yet", agent.Name)
1428 return false
1429 }
1430 }
1431 }
1432 resources = workspace.LatestBuild.Resources
1433 if w.resourcesMatcher == nil {
1434 return true
1435 }
1436 return w.resourcesMatcher(resources)
1437 }, testutil.IntervalFast)
1438 w.t.Logf("got workspace agents (workspace %s)", w.workspaceID)
1439 return resources
1440}
1441
1442// CreateWorkspace creates a workspace for the user and template provided.
1443// A random name is generated for it.

Callers

nothing calls this directly

Calls 6

ContextFunction · 0.92
EventuallyFunction · 0.92
WorkspaceMethod · 0.80
HelperMethod · 0.65
LogfMethod · 0.65
IsZeroMethod · 0.45

Tested by

no test coverage detected