@@ -60,7 +60,6 @@ func TestWorkspace(t *testing.T) {
60
60
require .NoError (t , err )
61
61
require .Equal (t , user .UserID , ws .LatestBuild .InitiatorID )
62
62
require .Equal (t , codersdk .BuildReasonInitiator , ws .LatestBuild .Reason )
63
- require .True (t , ws .Health .Healthy )
64
63
})
65
64
66
65
t .Run ("Deleted" , func (t * testing.T ) {
@@ -200,8 +199,11 @@ func TestWorkspace(t *testing.T) {
200
199
201
200
workspace , err := client .Workspace (ctx , workspace .ID )
202
201
require .NoError (t , err )
202
+
203
203
agent := workspace .LatestBuild .Resources [0 ].Agents [0 ]
204
204
205
+ assert .True (t , workspace .Health .Healthy )
206
+ assert .Equal (t , []uuid.UUID {}, workspace .Health .FailingAgents )
205
207
assert .True (t , agent .Health .Healthy )
206
208
assert .Empty (t , agent .Health .Reason )
207
209
})
@@ -239,17 +241,70 @@ func TestWorkspace(t *testing.T) {
239
241
var err error
240
242
testutil .Eventually (ctx , t , func (ctx context.Context ) bool {
241
243
workspace , err = client .Workspace (ctx , workspace .ID )
242
- t .Logf ("%#v" , workspace )
243
244
return assert .NoError (t , err ) && ! workspace .Health .Healthy
244
245
}, testutil .IntervalMedium )
245
246
246
247
agent := workspace .LatestBuild .Resources [0 ].Agents [0 ]
247
248
248
249
assert .False (t , workspace .Health .Healthy )
249
- assert .Len (t , workspace .Health .FailingAgents , 1 )
250
+ assert .Equal (t , []uuid. UUID { agent . ID }, workspace .Health .FailingAgents )
250
251
assert .False (t , agent .Health .Healthy )
251
252
assert .NotEmpty (t , agent .Health .Reason )
252
253
})
254
+
255
+ t .Run ("Mixed health" , func (t * testing.T ) {
256
+ t .Parallel ()
257
+ client := coderdtest .New (t , & coderdtest.Options {IncludeProvisionerDaemon : true })
258
+ user := coderdtest .CreateFirstUser (t , client )
259
+ version := coderdtest .CreateTemplateVersion (t , client , user .OrganizationID , & echo.Responses {
260
+ Parse : echo .ParseComplete ,
261
+ ProvisionApply : []* proto.Provision_Response {{
262
+ Type : & proto.Provision_Response_Complete {
263
+ Complete : & proto.Provision_Complete {
264
+ Resources : []* proto.Resource {{
265
+ Name : "some" ,
266
+ Type : "example" ,
267
+ Agents : []* proto.Agent {{
268
+ Id : uuid .NewString (),
269
+ Name : "a1" ,
270
+ Auth : & proto.Agent_Token {},
271
+ }, {
272
+ Id : uuid .NewString (),
273
+ Name : "a2" ,
274
+ Auth : & proto.Agent_Token {},
275
+ ConnectionTimeoutSeconds : 1 ,
276
+ }},
277
+ }},
278
+ },
279
+ },
280
+ }},
281
+ })
282
+ coderdtest .AwaitTemplateVersionJob (t , client , version .ID )
283
+ template := coderdtest .CreateTemplate (t , client , user .OrganizationID , version .ID )
284
+ workspace := coderdtest .CreateWorkspace (t , client , user .OrganizationID , template .ID )
285
+ coderdtest .AwaitWorkspaceBuildJob (t , client , workspace .LatestBuild .ID )
286
+
287
+ ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
288
+ defer cancel ()
289
+
290
+ var err error
291
+ testutil .Eventually (ctx , t , func (ctx context.Context ) bool {
292
+ workspace , err = client .Workspace (ctx , workspace .ID )
293
+ return assert .NoError (t , err ) && ! workspace .Health .Healthy
294
+ }, testutil .IntervalMedium )
295
+
296
+ assert .False (t , workspace .Health .Healthy )
297
+ assert .Len (t , workspace .Health .FailingAgents , 1 )
298
+
299
+ agent1 := workspace .LatestBuild .Resources [0 ].Agents [0 ]
300
+ agent2 := workspace .LatestBuild .Resources [0 ].Agents [1 ]
301
+
302
+ assert .Equal (t , []uuid.UUID {agent2 .ID }, workspace .Health .FailingAgents )
303
+ assert .True (t , agent1 .Health .Healthy )
304
+ assert .Empty (t , agent1 .Health .Reason )
305
+ assert .False (t , agent2 .Health .Healthy )
306
+ assert .NotEmpty (t , agent2 .Health .Reason )
307
+ })
253
308
})
254
309
}
255
310
0 commit comments