AwaitWorkspaceBuildJobCompleted waits for a workspace provision job to reach completed status.
(t testing.TB, client *codersdk.Client, build uuid.UUID)
| 1223 | |
| 1224 | // AwaitWorkspaceBuildJobCompleted waits for a workspace provision job to reach completed status. |
| 1225 | func AwaitWorkspaceBuildJobCompleted(t testing.TB, client *codersdk.Client, build uuid.UUID) codersdk.WorkspaceBuild { |
| 1226 | t.Helper() |
| 1227 | |
| 1228 | ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort) |
| 1229 | defer cancel() |
| 1230 | |
| 1231 | t.Logf("waiting for workspace build job %s", build) |
| 1232 | var workspaceBuild codersdk.WorkspaceBuild |
| 1233 | require.Eventually(t, func() bool { |
| 1234 | var err error |
| 1235 | workspaceBuild, err = client.WorkspaceBuild(ctx, build) |
| 1236 | if err != nil { |
| 1237 | t.Logf("failed to get workspace build %s: %v", build, err) |
| 1238 | return false |
| 1239 | } |
| 1240 | if workspaceBuild.Job.CompletedAt == nil { |
| 1241 | t.Logf("workspace build job %s still running (status: %s)", build, workspaceBuild.Job.Status) |
| 1242 | return false |
| 1243 | } |
| 1244 | return true |
| 1245 | }, testutil.WaitMedium, testutil.IntervalFast) |
| 1246 | t.Logf("got workspace build job %s (status: %s)", build, workspaceBuild.Job.Status) |
| 1247 | return workspaceBuild |
| 1248 | } |
| 1249 | |
| 1250 | // AwaitWorkspaceAgents waits for all resources with agents to be connected. If |
| 1251 | // specific agents are provided, it will wait for those agents to be connected |