@@ -25,22 +25,23 @@ import (
25
25
26
26
func TestWorkspaceUpdates (t * testing.T ) {
27
27
t .Parallel ()
28
- ctx := context .Background ()
29
28
30
- ws1ID := uuid .New ()
29
+ ws1ID := uuid.UUID { 0x01 }
31
30
ws1IDSlice := tailnet .UUIDToByteSlice (ws1ID )
32
- agent1ID := uuid .New ()
31
+ agent1ID := uuid.UUID { 0x02 }
33
32
agent1IDSlice := tailnet .UUIDToByteSlice (agent1ID )
34
- ws2ID := uuid .New ()
33
+ ws2ID := uuid.UUID { 0x03 }
35
34
ws2IDSlice := tailnet .UUIDToByteSlice (ws2ID )
36
- ws3ID := uuid .New ()
35
+ ws3ID := uuid.UUID { 0x04 }
37
36
ws3IDSlice := tailnet .UUIDToByteSlice (ws3ID )
38
- agent2ID := uuid .New ()
37
+ agent2ID := uuid.UUID { 0x05 }
39
38
agent2IDSlice := tailnet .UUIDToByteSlice (agent2ID )
40
- ws4ID := uuid .New ()
39
+ ws4ID := uuid.UUID { 0x06 }
41
40
ws4IDSlice := tailnet .UUIDToByteSlice (ws4ID )
41
+ agent3ID := uuid.UUID {0x07 }
42
+ agent3IDSlice := tailnet .UUIDToByteSlice (agent3ID )
42
43
43
- ownerID := uuid .New ()
44
+ ownerID := uuid.UUID { 0x07 }
44
45
memberRole ,err := rbac .RoleByName (rbac .RoleMember ())
45
46
require .NoError (t ,err )
46
47
ownerSubject := rbac.Subject {
@@ -53,9 +54,11 @@ func TestWorkspaceUpdates(t *testing.T) {
53
54
t .Run ("Basic" ,func (t * testing.T ) {
54
55
t .Parallel ()
55
56
57
+ ctx := testutil .Context (t ,testutil .WaitShort )
58
+
56
59
db := & mockWorkspaceStore {
57
60
orderedRows : []database.GetWorkspacesAndAgentsByOwnerIDRow {
58
- // Gainsa new agent
61
+ // Gainsagent2
59
62
{
60
63
ID :ws1ID ,
61
64
Name :"ws1" ,
@@ -81,6 +84,12 @@ func TestWorkspaceUpdates(t *testing.T) {
81
84
Name :"ws3" ,
82
85
JobStatus :database .ProvisionerJobStatusSucceeded ,
83
86
Transition :database .WorkspaceTransitionStop ,
87
+ Agents : []database.AgentIDNamePair {
88
+ {
89
+ ID :agent3ID ,
90
+ Name :"agent3" ,
91
+ },
92
+ },
84
93
},
85
94
},
86
95
}
@@ -97,13 +106,15 @@ func TestWorkspaceUpdates(t *testing.T) {
97
106
98
107
sub ,err := updateProvider .Subscribe (dbauthz .As (ctx ,ownerSubject ),ownerID )
99
108
require .NoError (t ,err )
100
- ch := sub .Updates ()
109
+ defer sub .Close ()
101
110
102
- update ,ok := <- ch
103
- require .True (t ,ok )
111
+ update := testutil .RequireRecvCtx (ctx ,t ,sub .Updates ())
104
112
slices .SortFunc (update .UpsertedWorkspaces ,func (a ,b * proto.Workspace )int {
105
113
return strings .Compare (a .Name ,b .Name )
106
114
})
115
+ slices .SortFunc (update .UpsertedAgents ,func (a ,b * proto.Agent )int {
116
+ return strings .Compare (a .Name ,b .Name )
117
+ })
107
118
require .Equal (t ,& proto.WorkspaceUpdate {
108
119
UpsertedWorkspaces : []* proto.Workspace {
109
120
{
@@ -128,6 +139,11 @@ func TestWorkspaceUpdates(t *testing.T) {
128
139
Name :"agent1" ,
129
140
WorkspaceId :ws1IDSlice ,
130
141
},
142
+ {
143
+ Id :agent3IDSlice ,
144
+ Name :"agent3" ,
145
+ WorkspaceId :ws3IDSlice ,
146
+ },
131
147
},
132
148
DeletedWorkspaces : []* proto.Workspace {},
133
149
DeletedAgents : []* proto.Agent {},
@@ -169,8 +185,7 @@ func TestWorkspaceUpdates(t *testing.T) {
169
185
WorkspaceID :ws1ID ,
170
186
})
171
187
172
- update ,ok = <- ch
173
- require .True (t ,ok )
188
+ update = testutil .RequireRecvCtx (ctx ,t ,sub .Updates ())
174
189
slices .SortFunc (update .UpsertedWorkspaces ,func (a ,b * proto.Workspace )int {
175
190
return strings .Compare (a .Name ,b .Name )
176
191
})
@@ -203,13 +218,21 @@ func TestWorkspaceUpdates(t *testing.T) {
203
218
Status :proto .Workspace_STOPPED ,
204
219
},
205
220
},
206
- DeletedAgents : []* proto.Agent {},
221
+ DeletedAgents : []* proto.Agent {
222
+ {
223
+ Id :agent3IDSlice ,
224
+ Name :"agent3" ,
225
+ WorkspaceId :ws3IDSlice ,
226
+ },
227
+ },
207
228
},update )
208
229
})
209
230
210
231
t .Run ("Resubscribe" ,func (t * testing.T ) {
211
232
t .Parallel ()
212
233
234
+ ctx := testutil .Context (t ,testutil .WaitShort )
235
+
213
236
db := & mockWorkspaceStore {
214
237
orderedRows : []database.GetWorkspacesAndAgentsByOwnerIDRow {
215
238
{
@@ -290,7 +313,7 @@ type mockWorkspaceStore struct {
290
313
}
291
314
292
315
// 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 ) {
294
317
return m .orderedRows ,nil
295
318
}
296
319