@@ -147,7 +147,7 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) {
147
147
require .NoError (t , err )
148
148
require .True (t , loc .Query ().Has ("message" ))
149
149
require .True (t , loc .Query ().Has ("redirect" ))
150
- assertWorkspaceLastUsedAtNotUpdated (t , appDetails )
150
+ assertWorkspaceLastUsedAtUpdated (t , appDetails )
151
151
})
152
152
153
153
t .Run ("LoginWithoutAuthOnProxy" , func (t * testing.T ) {
@@ -185,7 +185,7 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) {
185
185
// request is getting stripped.
186
186
require .Equal (t , u .Path , redirectURI .Path + "/" )
187
187
require .Equal (t , u .RawQuery , redirectURI .RawQuery )
188
- assertWorkspaceLastUsedAtNotUpdated (t , appDetails )
188
+ assertWorkspaceLastUsedAtUpdated (t , appDetails )
189
189
})
190
190
191
191
t .Run ("NoAccessShould404" , func (t * testing.T ) {
@@ -396,7 +396,7 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) {
396
396
// TODO(@deansheather): This should be 400. There's a todo in the
397
397
// resolve request code to fix this.
398
398
require .Equal (t , http .StatusInternalServerError , resp .StatusCode )
399
- assertWorkspaceLastUsedAtNotUpdated (t , appDetails )
399
+ assertWorkspaceLastUsedAtUpdated (t , appDetails )
400
400
})
401
401
})
402
402
@@ -1570,16 +1570,23 @@ func assertWorkspaceLastUsedAtUpdated(t testing.TB, details *Details) {
1570
1570
t .Helper ()
1571
1571
1572
1572
details .FlushStats ()
1573
- ws , err := details .SDKClient .Workspace (context .Background (), details .Workspace .ID )
1574
- require .NoError (t , err )
1575
- require .Greater (t , ws .LastUsedAt , details .Workspace .LastUsedAt , "workspace LastUsedAt not updated when it should have been" )
1573
+ // Despite our efforts with the flush channel, this is inherently racy.
1574
+ // Retry a few times to ensure that the stats collection pipeline has flushed.
1575
+ require .Eventually (t , func () bool {
1576
+ ws , err := details .SDKClient .Workspace (context .Background (), details .Workspace .ID )
1577
+ assert .NoError (t , err )
1578
+ return ws .LastUsedAt .After (details .Workspace .LastUsedAt )
1579
+ }, testutil .WaitShort , testutil .IntervalMedium , "workspace LastUsedAt not updated when it should have been" )
1576
1580
}
1577
1581
1578
1582
// Except when it sometimes shouldn't (e.g. no access)
1579
1583
func assertWorkspaceLastUsedAtNotUpdated (t testing.TB , details * Details ) {
1580
1584
t .Helper ()
1581
1585
1582
1586
details .FlushStats ()
1587
+ // Despite our efforts with the flush channel, this is inherently racy.
1588
+ // Wait for a short time to ensure that the stats collection pipeline has flushed.
1589
+ <- time .After (testutil .IntervalSlow )
1583
1590
ws , err := details .SDKClient .Workspace (context .Background (), details .Workspace .ID )
1584
1591
require .NoError (t , err )
1585
1592
require .Equal (t , ws .LastUsedAt , details .Workspace .LastUsedAt , "workspace LastUsedAt updated when it should not have been" )
0 commit comments