Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfebe12d

Browse files
committed
Fix workspace tests waiting, erroring on workspace update, and add comments to workspace events
1 parentf2cce85 commitfebe12d

File tree

4 files changed

+31
-33
lines changed

4 files changed

+31
-33
lines changed

‎coderd/workspaceagents.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -547,9 +547,7 @@ func (api *API) workspaceAgentCoordinate(rw http.ResponseWriter, r *http.Request
547547
_=conn.Close(websocket.StatusGoingAway,err.Error())
548548
return
549549
}
550-
if!api.publishWorkspaceUpdate(ctx,rw,build.WorkspaceID) {
551-
return
552-
}
550+
api.publishWorkspaceUpdate(ctx,build.WorkspaceID)
553551

554552
// End span so we don't get long lived trace data.
555553
tracing.EndHTTPSpan(r,http.StatusOK,trace.SpanFromContext(ctx))
@@ -1000,9 +998,7 @@ func (api *API) postWorkspaceAppHealth(rw http.ResponseWriter, r *http.Request)
1000998
})
1001999
return
10021000
}
1003-
if!api.publishWorkspaceUpdate(r.Context(),rw,workspace.ID) {
1004-
return
1005-
}
1001+
api.publishWorkspaceUpdate(r.Context(),workspace.ID)
10061002

10071003
httpapi.Write(r.Context(),rw,http.StatusOK,nil)
10081004
}

‎coderd/workspacebuilds.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -574,9 +574,7 @@ func (api *API) postWorkspaceBuilds(rw http.ResponseWriter, r *http.Request) {
574574
return
575575
}
576576

577-
if!api.publishWorkspaceUpdate(ctx,rw,workspace.ID) {
578-
return
579-
}
577+
api.publishWorkspaceUpdate(ctx,workspace.ID)
580578

581579
httpapi.Write(ctx,rw,http.StatusCreated,apiBuild)
582580
}
@@ -637,9 +635,7 @@ func (api *API) patchCancelWorkspaceBuild(rw http.ResponseWriter, r *http.Reques
637635
return
638636
}
639637

640-
if!api.publishWorkspaceUpdate(ctx,rw,workspace.ID) {
641-
return
642-
}
638+
api.publishWorkspaceUpdate(ctx,workspace.ID)
643639

644640
httpapi.Write(ctx,rw,http.StatusOK, codersdk.Response{
645641
Message:"Job has been marked as canceled...",

‎coderd/workspaces.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -634,9 +634,7 @@ func (api *API) patchWorkspace(rw http.ResponseWriter, r *http.Request) {
634634
return
635635
}
636636

637-
if!api.publishWorkspaceUpdate(ctx,rw,workspace.ID) {
638-
return
639-
}
637+
api.publishWorkspaceUpdate(ctx,workspace.ID)
640638

641639
aReq.New=newWorkspace
642640
rw.WriteHeader(http.StatusNoContent)
@@ -923,14 +921,19 @@ func (api *API) watchWorkspace(rw http.ResponseWriter, r *http.Request) {
923921
})
924922
})
925923
iferr!=nil {
926-
httpapi.Write(ctx,rw,http.StatusInternalServerError, codersdk.Response{
927-
Message:"Internal error subscribing to workspace events.",
928-
Detail:err.Error(),
924+
_=sendEvent(ctx, codersdk.ServerSentEvent{
925+
Type:codersdk.ServerSentEventTypeError,
926+
Data: codersdk.Response{
927+
Message:"Internal error subscribing to workspace events.",
928+
Detail:err.Error(),
929+
},
929930
})
930931
return
931932
}
932933
defercancelSubscribe()
933934

935+
// An initial ping signals to the request that the server is now ready
936+
// and the client can begin servicing a channel with data.
934937
_=sendEvent(ctx, codersdk.ServerSentEvent{
935938
Type:codersdk.ServerSentEventTypePing,
936939
})
@@ -1234,14 +1237,10 @@ func watchWorkspaceChannel(id uuid.UUID) string {
12341237
returnfmt.Sprintf("workspace:%s",id)
12351238
}
12361239

1237-
func (api*API)publishWorkspaceUpdate(ctx context.Context,rw http.ResponseWriter,workspaceID uuid.UUID)bool {
1240+
func (api*API)publishWorkspaceUpdate(ctx context.Context,workspaceID uuid.UUID) {
12381241
err:=api.Pubsub.Publish(watchWorkspaceChannel(workspaceID), []byte{})
12391242
iferr!=nil {
1240-
httpapi.Write(ctx,rw,http.StatusInternalServerError, codersdk.Response{
1241-
Message:"Internal error publishing workspace update.",
1242-
Detail:err.Error(),
1243-
})
1244-
returnfalse
1243+
api.Logger.Warn(ctx,"failed to publish workspace update",
1244+
slog.F("workspace_id",workspaceID),slog.Error(err))
12451245
}
1246-
returntrue
12471246
}

‎coderd/workspaces_test.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,14 +1383,21 @@ func TestWorkspaceWatcher(t *testing.T) {
13831383

13841384
wc,err:=client.WatchWorkspace(ctx,workspace.ID)
13851385
require.NoError(t,err)
1386+
wait:=func() {
1387+
select {
1388+
case<-ctx.Done():
1389+
t.Fail()
1390+
case<-wc:
1391+
}
1392+
}
13861393

13871394
coderdtest.CreateWorkspaceBuild(t,client,workspace,database.WorkspaceTransitionStart)
13881395
// the workspace build being created
1389-
<-wc
1396+
wait()
13901397
// the workspace build being acquired
1391-
<-wc
1398+
wait()
13921399
// the workspace build completing
1393-
<-wc
1400+
wait()
13941401

13951402
agentClient:=codersdk.New(client.URL)
13961403
agentClient.SessionToken=authToken
@@ -1403,25 +1410,25 @@ func TestWorkspaceWatcher(t *testing.T) {
14031410
}()
14041411

14051412
// the agent connected
1406-
<-wc
1413+
wait()
14071414
agentCloser.Close()
14081415
// the agent disconnected
1409-
<-wc
1416+
wait()
14101417

14111418
closeFunc.Close()
14121419
build:=coderdtest.CreateWorkspaceBuild(t,client,workspace,database.WorkspaceTransitionStart)
14131420
// First is for the workspace build itself
1414-
<-wc
1421+
wait()
14151422
err=client.CancelWorkspaceBuild(ctx,build.ID)
14161423
require.NoError(t,err)
14171424
// Second is for the build cancel
1418-
<-wc
1425+
wait()
14191426

14201427
err=client.UpdateWorkspace(ctx,workspace.ID, codersdk.UpdateWorkspaceRequest{
14211428
Name:"another",
14221429
})
14231430
require.NoError(t,err)
1424-
<-wc
1431+
wait()
14251432

14261433
cancel()
14271434
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp