@@ -1239,8 +1239,10 @@ func TestWorkspaceBuildTimings(t *testing.T) {
1239
1239
1240
1240
//nolint:paralleltest
1241
1241
t .Run ("NonExistentBuild" , func (t * testing.T ) {
1242
- // When: fetching an inexistent build
1242
+ // Given: an inexistent build
1243
1243
buildID := uuid .New ()
1244
+
1245
+ // When: fetching timings for the build
1244
1246
ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
1245
1247
t .Cleanup (cancel )
1246
1248
_ , err := client .WorkspaceBuildTimings (ctx , buildID )
@@ -1252,8 +1254,10 @@ func TestWorkspaceBuildTimings(t *testing.T) {
1252
1254
1253
1255
//nolint:paralleltest
1254
1256
t .Run ("EmptyTimings" , func (t * testing.T ) {
1255
- // When: fetching timings for a build with no timings
1257
+ // Given: a build with no timings
1256
1258
build := makeBuild ()
1259
+
1260
+ // When: fetching timings for the build
1257
1261
ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
1258
1262
t .Cleanup (cancel )
1259
1263
res , err := client .WorkspaceBuildTimings (ctx , build .ID )
@@ -1266,17 +1270,18 @@ func TestWorkspaceBuildTimings(t *testing.T) {
1266
1270
1267
1271
//nolint:paralleltest
1268
1272
t .Run ("ProvisionerTimings" , func (t * testing.T ) {
1269
- // When: fetching timings for a build with provisioner timings
1273
+ // Given: a build with provisioner timings
1270
1274
build := makeBuild ()
1271
1275
provisionerTimings := dbgen .ProvisionerJobTimings (t , db , build , 5 )
1272
1276
1273
- // Then: return a response with the expected timings
1277
+ // When: fetching timings for the build
1274
1278
ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
1275
1279
t .Cleanup (cancel )
1276
1280
res , err := client .WorkspaceBuildTimings (ctx , build .ID )
1277
1281
require .NoError (t , err )
1278
- require .Len (t , res .ProvisionerTimings , 5 )
1279
1282
1283
+ // Then: return a response with the expected timings
1284
+ require .Len (t , res .ProvisionerTimings , 5 )
1280
1285
for i := range res .ProvisionerTimings {
1281
1286
timingRes := res .ProvisionerTimings [i ]
1282
1287
genTiming := provisionerTimings [i ]
@@ -1292,7 +1297,7 @@ func TestWorkspaceBuildTimings(t *testing.T) {
1292
1297
1293
1298
//nolint:paralleltest
1294
1299
t .Run ("AgentScriptTimings" , func (t * testing.T ) {
1295
- // When: fetching timings for a build with agent script timings
1300
+ // Given: a build with agent script timings
1296
1301
build := makeBuild ()
1297
1302
resource := dbgen .WorkspaceResource (t , db , database.WorkspaceResource {
1298
1303
JobID : build .JobID ,
@@ -1305,13 +1310,14 @@ func TestWorkspaceBuildTimings(t *testing.T) {
1305
1310
})
1306
1311
agentScriptTimings := dbgen .WorkspaceAgentScriptTimings (t , db , script , 5 )
1307
1312
1308
- // Then: return a response with the expected timings
1313
+ // When: fetching timings for the build
1309
1314
ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
1310
1315
t .Cleanup (cancel )
1311
1316
res , err := client .WorkspaceBuildTimings (ctx , build .ID )
1312
1317
require .NoError (t , err )
1313
- require .Len (t , res .AgentScriptTimings , 5 )
1314
1318
1319
+ // Then: return a response with the expected timings
1320
+ require .Len (t , res .AgentScriptTimings , 5 )
1315
1321
for i := range res .AgentScriptTimings {
1316
1322
timingRes := res .AgentScriptTimings [i ]
1317
1323
genTiming := agentScriptTimings [i ]
@@ -1327,7 +1333,7 @@ func TestWorkspaceBuildTimings(t *testing.T) {
1327
1333
1328
1334
//nolint:paralleltest
1329
1335
t .Run ("NoAgentScripts" , func (t * testing.T ) {
1330
- // When: fetching timings for a build with no agent scripts
1336
+ // Given: a build with no agent scripts
1331
1337
build := makeBuild ()
1332
1338
resource := dbgen .WorkspaceResource (t , db , database.WorkspaceResource {
1333
1339
JobID : build .JobID ,
@@ -1336,29 +1342,63 @@ func TestWorkspaceBuildTimings(t *testing.T) {
1336
1342
ResourceID : resource .ID ,
1337
1343
})
1338
1344
1339
- // Then: return a response with empty agent script timings
1345
+ // When: fetching timings for the build
1340
1346
ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
1341
1347
t .Cleanup (cancel )
1342
1348
res , err := client .WorkspaceBuildTimings (ctx , build .ID )
1343
1349
require .NoError (t , err )
1350
+
1351
+ // Then: return a response with empty agent script timings
1344
1352
require .Empty (t , res .AgentScriptTimings )
1345
1353
})
1346
1354
1347
1355
// Some workspaces might not have agents. It is improbable, but possible.
1348
1356
//nolint:paralleltest
1349
1357
t .Run ("NoAgents" , func (t * testing.T ) {
1350
- // When: fetching timings for a build with no agents
1358
+ // Given: a build with no agents
1351
1359
build := makeBuild ()
1352
1360
dbgen .WorkspaceResource (t , db , database.WorkspaceResource {
1353
1361
JobID : build .JobID ,
1354
1362
})
1355
1363
1356
- // Then: return a response with empty agent script timings
1357
- // trigger build
1364
+ // When: fetching timings for the build
1358
1365
ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
1359
1366
t .Cleanup (cancel )
1360
1367
res , err := client .WorkspaceBuildTimings (ctx , build .ID )
1361
1368
require .NoError (t , err )
1369
+
1370
+ // Then: return a response with empty agent script timings
1362
1371
require .Empty (t , res .AgentScriptTimings )
1363
1372
})
1373
+
1374
+ //nolint:paralleltest
1375
+ t .Run ("AgentConnectionTimings" , func (t * testing.T ) {
1376
+ // Given: a build with multiple agents
1377
+ build := makeBuild ()
1378
+ resource := dbgen .WorkspaceResource (t , db , database.WorkspaceResource {
1379
+ JobID : build .JobID ,
1380
+ })
1381
+ agents := make ([]database.WorkspaceAgent , 5 )
1382
+ for i := range agents {
1383
+ agents [i ] = dbgen .WorkspaceAgent (t , db , database.WorkspaceAgent {
1384
+ ResourceID : resource .ID ,
1385
+ })
1386
+ }
1387
+
1388
+ // When: fetching timings for the build
1389
+ ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
1390
+ t .Cleanup (cancel )
1391
+ res , err := client .WorkspaceBuildTimings (ctx , build .ID )
1392
+ require .NoError (t , err )
1393
+
1394
+ // Then: return a response with the expected timings
1395
+ require .Len (t , res .AgentConnectionTimings , 5 )
1396
+ for i := range res .ProvisionerTimings {
1397
+ timingRes := res .AgentConnectionTimings [i ]
1398
+ require .Equal (t , agents [i ].ID .String (), timingRes .WorkspaceAgentID )
1399
+ require .Equal (t , agents [i ].Name , timingRes .WorkspaceAgentName )
1400
+ require .NotEmpty (t , timingRes .StartedAt )
1401
+ require .NotEmpty (t , timingRes .EndedAt )
1402
+ }
1403
+ })
1364
1404
}
0 commit comments