@@ -25,22 +25,23 @@ import (
2525
2626func TestWorkspaceUpdates (t * testing.T ) {
2727t .Parallel ()
28- ctx := context .Background ()
2928
30- ws1ID := uuid .New ()
29+ ws1ID := uuid.UUID { 0x01 }
3130ws1IDSlice := tailnet .UUIDToByteSlice (ws1ID )
32- agent1ID := uuid .New ()
31+ agent1ID := uuid.UUID { 0x02 }
3332agent1IDSlice := tailnet .UUIDToByteSlice (agent1ID )
34- ws2ID := uuid .New ()
33+ ws2ID := uuid.UUID { 0x03 }
3534ws2IDSlice := tailnet .UUIDToByteSlice (ws2ID )
36- ws3ID := uuid .New ()
35+ ws3ID := uuid.UUID { 0x04 }
3736ws3IDSlice := tailnet .UUIDToByteSlice (ws3ID )
38- agent2ID := uuid .New ()
37+ agent2ID := uuid.UUID { 0x05 }
3938agent2IDSlice := tailnet .UUIDToByteSlice (agent2ID )
40- ws4ID := uuid .New ()
39+ ws4ID := uuid.UUID { 0x06 }
4140ws4IDSlice := tailnet .UUIDToByteSlice (ws4ID )
41+ agent3ID := uuid.UUID {0x07 }
42+ agent3IDSlice := tailnet .UUIDToByteSlice (agent3ID )
4243
43- ownerID := uuid .New ()
44+ ownerID := uuid.UUID { 0x07 }
4445memberRole ,err := rbac .RoleByName (rbac .RoleMember ())
4546require .NoError (t ,err )
4647ownerSubject := rbac.Subject {
@@ -53,9 +54,11 @@ func TestWorkspaceUpdates(t *testing.T) {
5354t .Run ("Basic" ,func (t * testing.T ) {
5455t .Parallel ()
5556
57+ ctx := testutil .Context (t ,testutil .WaitShort )
58+
5659db := & mockWorkspaceStore {
5760orderedRows : []database.GetWorkspacesAndAgentsByOwnerIDRow {
58- // Gainsa new agent
61+ // Gainsagent2
5962{
6063ID :ws1ID ,
6164Name :"ws1" ,
@@ -81,6 +84,12 @@ func TestWorkspaceUpdates(t *testing.T) {
8184Name :"ws3" ,
8285JobStatus :database .ProvisionerJobStatusSucceeded ,
8386Transition :database .WorkspaceTransitionStop ,
87+ Agents : []database.AgentIDNamePair {
88+ {
89+ ID :agent3ID ,
90+ Name :"agent3" ,
91+ },
92+ },
8493},
8594},
8695}
@@ -97,13 +106,15 @@ func TestWorkspaceUpdates(t *testing.T) {
97106
98107sub ,err := updateProvider .Subscribe (dbauthz .As (ctx ,ownerSubject ),ownerID )
99108require .NoError (t ,err )
100- ch := sub .Updates ()
109+ defer sub .Close ()
101110
102- update ,ok := <- ch
103- require .True (t ,ok )
111+ update := testutil .RequireRecvCtx (ctx ,t ,sub .Updates ())
104112slices .SortFunc (update .UpsertedWorkspaces ,func (a ,b * proto.Workspace )int {
105113return strings .Compare (a .Name ,b .Name )
106114})
115+ slices .SortFunc (update .UpsertedAgents ,func (a ,b * proto.Agent )int {
116+ return strings .Compare (a .Name ,b .Name )
117+ })
107118require .Equal (t ,& proto.WorkspaceUpdate {
108119UpsertedWorkspaces : []* proto.Workspace {
109120{
@@ -128,6 +139,11 @@ func TestWorkspaceUpdates(t *testing.T) {
128139Name :"agent1" ,
129140WorkspaceId :ws1IDSlice ,
130141},
142+ {
143+ Id :agent3IDSlice ,
144+ Name :"agent3" ,
145+ WorkspaceId :ws3IDSlice ,
146+ },
131147},
132148DeletedWorkspaces : []* proto.Workspace {},
133149DeletedAgents : []* proto.Agent {},
@@ -169,8 +185,7 @@ func TestWorkspaceUpdates(t *testing.T) {
169185WorkspaceID :ws1ID ,
170186})
171187
172- update ,ok = <- ch
173- require .True (t ,ok )
188+ update = testutil .RequireRecvCtx (ctx ,t ,sub .Updates ())
174189slices .SortFunc (update .UpsertedWorkspaces ,func (a ,b * proto.Workspace )int {
175190return strings .Compare (a .Name ,b .Name )
176191})
@@ -203,13 +218,21 @@ func TestWorkspaceUpdates(t *testing.T) {
203218Status :proto .Workspace_STOPPED ,
204219},
205220},
206- DeletedAgents : []* proto.Agent {},
221+ DeletedAgents : []* proto.Agent {
222+ {
223+ Id :agent3IDSlice ,
224+ Name :"agent3" ,
225+ WorkspaceId :ws3IDSlice ,
226+ },
227+ },
207228},update )
208229})
209230
210231t .Run ("Resubscribe" ,func (t * testing.T ) {
211232t .Parallel ()
212233
234+ ctx := testutil .Context (t ,testutil .WaitShort )
235+
213236db := & mockWorkspaceStore {
214237orderedRows : []database.GetWorkspacesAndAgentsByOwnerIDRow {
215238{
@@ -290,7 +313,7 @@ type mockWorkspaceStore struct {
290313}
291314
292315// GetAuthorizedWorkspacesAndAgentsByOwnerID implements coderd.UpdatesQuerier.
293- func (m * mockWorkspaceStore )GetAuthorizedWorkspacesAndAgentsByOwnerID (context.Context , uuid.UUID , rbac. PreparedAuthorized ) ([]database.GetWorkspacesAndAgentsByOwnerIDRow ,error ) {
316+ func (m * mockWorkspaceStore )GetWorkspacesAndAgentsByOwnerID (context.Context , uuid.UUID ) ([]database.GetWorkspacesAndAgentsByOwnerIDRow ,error ) {
294317return m .orderedRows ,nil
295318}
296319