@@ -1548,6 +1548,47 @@ func TestWorkspaceBuildTimings(t *testing.T) {
1548
1548
}
1549
1549
})
1550
1550
1551
+ t .Run ("MultipleTimingsForSameAgentScript" , func (t * testing.T ) {
1552
+ t .Parallel ()
1553
+
1554
+ // Given: a build with multiple timings for the same script
1555
+ build := makeBuild (t )
1556
+ resource := dbgen .WorkspaceResource (t , db , database.WorkspaceResource {
1557
+ JobID : build .JobID ,
1558
+ })
1559
+ agent := dbgen .WorkspaceAgent (t , db , database.WorkspaceAgent {
1560
+ ResourceID : resource .ID ,
1561
+ })
1562
+ script := dbgen .WorkspaceAgentScript (t , db , database.WorkspaceAgentScript {
1563
+ WorkspaceAgentID : agent .ID ,
1564
+ })
1565
+ timings := make ([]database.WorkspaceAgentScriptTiming , 3 )
1566
+ scriptStartedAt := dbtime .Now ()
1567
+ for i := range timings {
1568
+ timings [i ] = dbgen .WorkspaceAgentScriptTiming (t , db , database.WorkspaceAgentScriptTiming {
1569
+ StartedAt : scriptStartedAt ,
1570
+ EndedAt : scriptStartedAt .Add (1 * time .Minute ),
1571
+ ScriptID : script .ID ,
1572
+ })
1573
+
1574
+ // Add an hour to the previous started so we can
1575
+ // reliably differentiate the scripts from each other.
1576
+ scriptStartedAt = scriptStartedAt .Add (1 * time .Hour )
1577
+ }
1578
+
1579
+ // When: fetching timings for the build
1580
+ ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
1581
+ t .Cleanup (cancel )
1582
+ res , err := client .WorkspaceBuildTimings (ctx , build .ID )
1583
+ require .NoError (t , err )
1584
+
1585
+ // Then: return a response with the first agent script timing
1586
+ require .Len (t , res .AgentScriptTimings , 1 )
1587
+
1588
+ require .Equal (t , timings [0 ].StartedAt .UnixMilli (), res .AgentScriptTimings [0 ].StartedAt .UnixMilli ())
1589
+ require .Equal (t , timings [0 ].EndedAt .UnixMilli (), res .AgentScriptTimings [0 ].EndedAt .UnixMilli ())
1590
+ })
1591
+
1551
1592
t .Run ("AgentScriptTimings" , func (t * testing.T ) {
1552
1593
t .Parallel ()
1553
1594
0 commit comments