Skip to content

test(coderd): fix TestWorkspaceWatcher hang waiting for update #8992

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions coderd/workspaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2121,9 +2121,14 @@ func TestWorkspaceWatcher(t *testing.T) {
case w, ok := <-wc:
require.True(t, ok, "watch channel closed: %s", event)
if ready == nil || ready(w) {
logger.Info(ctx, "done waiting for event", slog.F("event", event))
logger.Info(ctx, "done waiting for event",
slog.F("event", event),
slog.F("workspace", w))
return
}
logger.Info(ctx, "skipped update for event",
slog.F("event", event),
slog.F("workspace", w))
}
}
}
Expand Down Expand Up @@ -2194,12 +2199,23 @@ func TestWorkspaceWatcher(t *testing.T) {
})
// We want to verify pending state here, but it's possible that we reach
// failed state fast enough that we never see pending.
sawFailed := false
wait("workspace build pending or failed", func(w codersdk.Workspace) bool {
return w.LatestBuild.Status == codersdk.WorkspaceStatusPending || w.LatestBuild.Status == codersdk.WorkspaceStatusFailed
})
wait("workspace build failed", func(w codersdk.Workspace) bool {
return w.LatestBuild.Status == codersdk.WorkspaceStatusFailed
switch w.LatestBuild.Status {
case codersdk.WorkspaceStatusPending:
return true
case codersdk.WorkspaceStatusFailed:
sawFailed = true
return true
default:
return false
}
})
if !sawFailed {
wait("workspace build failed", func(w codersdk.Workspace) bool {
return w.LatestBuild.Status == codersdk.WorkspaceStatusFailed
})
}

closeFunc.Close()
build := coderdtest.CreateWorkspaceBuild(t, client, workspace, database.WorkspaceTransitionStart)
Expand Down