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

Function TestWatchAllWorkspaceBuilds

coderd/workspaces_test.go:3975–4080  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

3973}
3974
3975func TestWatchAllWorkspaceBuilds(t *testing.T) {
3976 t.Parallel()
3977
3978 // Enable the workspace build updates experiment.
3979 client, closer := coderdtest.NewWithProvisionerCloser(t, &coderdtest.Options{
3980 IncludeProvisionerDaemon: true,
3981 DeploymentValues: coderdtest.DeploymentValues(t, func(dv *codersdk.DeploymentValues) {
3982 dv.Experiments = []string{string(codersdk.ExperimentWorkspaceBuildUpdates)}
3983 }),
3984 })
3985 defer closer.Close()
3986 user := coderdtest.CreateFirstUser(t, client)
3987
3988 // Create a simple template version.
3989 version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{
3990 Parse: echo.ParseComplete,
3991 ProvisionPlan: echo.PlanComplete,
3992 ProvisionGraph: []*proto.Response{{
3993 Type: &proto.Response_Graph{
3994 Graph: &proto.GraphComplete{
3995 Resources: []*proto.Resource{{
3996 Name: "example",
3997 Type: "aws_instance",
3998 }},
3999 },
4000 },
4001 }},
4002 })
4003 coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID)
4004 template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
4005
4006 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
4007 defer cancel()
4008
4009 // Subscribe to all workspace build updates via SSE BEFORE creating workspaces
4010 // so we can use it to wait for the initial builds.
4011 decoder, err := client.WatchAllWorkspaceBuilds(ctx)
4012 require.NoError(t, err)
4013 defer decoder.Close()
4014
4015 updates := decoder.Chan()
4016 logger := testutil.Logger(t).Named(t.Name())
4017
4018 // Helper to wait for a specific update.
4019 waitForUpdate := func(event string, workspaceID uuid.UUID, expectedTransition, expectedStatus string) codersdk.WorkspaceBuildUpdate {
4020 t.Helper()
4021 for {
4022 select {
4023 case <-ctx.Done():
4024 require.FailNow(t, "timed out waiting for event", event)
4025 return codersdk.WorkspaceBuildUpdate{}
4026 case update, ok := <-updates:
4027 if !ok {
4028 require.FailNow(t, "updates channel closed", event)
4029 return codersdk.WorkspaceBuildUpdate{}
4030 }
4031 logger.Info(ctx, "received workspace build update",
4032 slog.F("event", event),

Callers

nothing calls this directly

Calls 15

NewWithProvisionerCloserFunction · 0.92
DeploymentValuesFunction · 0.92
CreateFirstUserFunction · 0.92
CreateTemplateVersionFunction · 0.92
CreateTemplateFunction · 0.92
LoggerFunction · 0.92
CreateWorkspaceFunction · 0.92
CreateWorkspaceBuildFunction · 0.92
NamedMethod · 0.80
FailNowMethod · 0.80

Tested by

no test coverage detected