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

Method WaitFor

coderd/coderdtest/coderdtest.go:1343–1386  ·  view source on GitHub ↗

WaitFor waits for the given criteria and fails the test if they are not met before the waiter's context is canceled.

(criteria ...WaitForAgentFn)

Source from the content-addressed store, hash-verified

1341// WaitFor waits for the given criteria and fails the test if they are not met before the
1342// waiter's context is canceled.
1343func (w WorkspaceAgentWaiter) WaitFor(criteria ...WaitForAgentFn) {
1344 w.t.Helper()
1345
1346 agentNamesMap := make(map[string]struct{}, len(w.agentNames))
1347 for _, name := range w.agentNames {
1348 agentNamesMap[name] = struct{}{}
1349 }
1350
1351 ctx := w.ctx
1352 if w.ctx == nil {
1353 ctx = testutil.Context(w.t, testutil.WaitLong)
1354 }
1355
1356 w.t.Logf("waiting for workspace agents (workspace %s)", w.workspaceID)
1357 testutil.Eventually(ctx, w.t, func(ctx context.Context) bool {
1358 var err error
1359 workspace, err := w.client.Workspace(ctx, w.workspaceID)
1360 if err != nil {
1361 return false
1362 }
1363 if workspace.LatestBuild.Job.CompletedAt == nil {
1364 return false
1365 }
1366 if workspace.LatestBuild.Job.CompletedAt.IsZero() {
1367 return false
1368 }
1369
1370 for _, resource := range workspace.LatestBuild.Resources {
1371 for _, agent := range resource.Agents {
1372 if len(w.agentNames) > 0 {
1373 if _, ok := agentNamesMap[agent.Name]; !ok {
1374 continue
1375 }
1376 }
1377 for _, criterium := range criteria {
1378 if !criterium(agent) {
1379 return false
1380 }
1381 }
1382 }
1383 }
1384 return true
1385 }, testutil.IntervalFast)
1386}
1387
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.

Callers 7

TestReinitializeAgentFunction · 0.95
TestTasksFunction · 0.45
TestToolsFunction · 0.45
Test_TasksFunction · 0.45
setupCLITaskTestFunction · 0.45
Test_TaskSendFunction · 0.45
TestSyncCommands_GoldenFunction · 0.45

Calls 6

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

Tested by 7

TestReinitializeAgentFunction · 0.76
TestTasksFunction · 0.36
TestToolsFunction · 0.36
Test_TasksFunction · 0.36
setupCLITaskTestFunction · 0.36
Test_TaskSendFunction · 0.36
TestSyncCommands_GoldenFunction · 0.36