@@ -67,7 +67,7 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) {
67
67
// reconnecting-pty proxy server we want to test is mounted.
68
68
client := appDetails .AppClient (t )
69
69
testReconnectingPTY (ctx ,t ,client ,appDetails .Agent .ID ,"" )
70
- assertWorkspaceLastUsedAtUpdated (t ,appDetails )
70
+ assertWorkspaceLastUsedAtUpdated (ctx , t ,appDetails )
71
71
})
72
72
73
73
t .Run ("SignedTokenQueryParameter" ,func (t * testing.T ) {
@@ -97,7 +97,7 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) {
97
97
// Make an unauthenticated client.
98
98
unauthedAppClient := codersdk .New (appDetails .AppClient (t ).URL )
99
99
testReconnectingPTY (ctx ,t ,unauthedAppClient ,appDetails .Agent .ID ,issueRes .SignedToken )
100
- assertWorkspaceLastUsedAtUpdated (t ,appDetails )
100
+ assertWorkspaceLastUsedAtUpdated (ctx , t ,appDetails )
101
101
})
102
102
})
103
103
@@ -123,7 +123,7 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) {
123
123
require .Contains (t ,string (body ),"Path-based applications are disabled" )
124
124
// Even though path-based apps are disabled, the request should indicate
125
125
// that the workspace was used.
126
- assertWorkspaceLastUsedAtNotUpdated (t ,appDetails )
126
+ assertWorkspaceLastUsedAtNotUpdated (ctx , t ,appDetails )
127
127
})
128
128
129
129
t .Run ("LoginWithoutAuthOnPrimary" ,func (t * testing.T ) {
@@ -150,7 +150,7 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) {
150
150
require .NoError (t ,err )
151
151
require .True (t ,loc .Query ().Has ("message" ))
152
152
require .True (t ,loc .Query ().Has ("redirect" ))
153
- assertWorkspaceLastUsedAtNotUpdated (t ,appDetails )
153
+ assertWorkspaceLastUsedAtNotUpdated (ctx , t ,appDetails )
154
154
})
155
155
156
156
t .Run ("LoginWithoutAuthOnProxy" ,func (t * testing.T ) {
@@ -189,7 +189,7 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) {
189
189
// request is getting stripped.
190
190
require .Equal (t ,u .Path ,redirectURI .Path + "/" )
191
191
require .Equal (t ,u .RawQuery ,redirectURI .RawQuery )
192
- assertWorkspaceLastUsedAtNotUpdated (t ,appDetails )
192
+ assertWorkspaceLastUsedAtNotUpdated (ctx , t ,appDetails )
193
193
})
194
194
195
195
t .Run ("NoAccessShould404" ,func (t * testing.T ) {
@@ -288,7 +288,7 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) {
288
288
require .NoError (t ,err )
289
289
require .Equal (t ,proxyTestAppBody ,string (body ))
290
290
require .Equal (t ,http .StatusOK ,resp .StatusCode )
291
- assertWorkspaceLastUsedAtUpdated (t ,appDetails )
291
+ assertWorkspaceLastUsedAtUpdated (ctx , t ,appDetails )
292
292
})
293
293
294
294
t .Run ("ProxiesHTTPS" ,func (t * testing.T ) {
@@ -334,7 +334,7 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) {
334
334
require .NoError (t ,err )
335
335
require .Equal (t ,proxyTestAppBody ,string (body ))
336
336
require .Equal (t ,http .StatusOK ,resp .StatusCode )
337
- assertWorkspaceLastUsedAtUpdated (t ,appDetails )
337
+ assertWorkspaceLastUsedAtUpdated (ctx , t ,appDetails )
338
338
})
339
339
340
340
t .Run ("BlocksMe" ,func (t * testing.T ) {
@@ -355,7 +355,7 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) {
355
355
body ,err := io .ReadAll (resp .Body )
356
356
require .NoError (t ,err )
357
357
require .Contains (t ,string (body ),"must be accessed with the full username, not @me" )
358
- assertWorkspaceLastUsedAtNotUpdated (t ,appDetails )
358
+ assertWorkspaceLastUsedAtNotUpdated (ctx , t ,appDetails )
359
359
})
360
360
361
361
t .Run ("ForwardsIP" ,func (t * testing.T ) {
@@ -375,7 +375,7 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) {
375
375
require .Equal (t ,proxyTestAppBody ,string (body ))
376
376
require .Equal (t ,http .StatusOK ,resp .StatusCode )
377
377
require .Equal (t ,"1.1.1.1,127.0.0.1" ,resp .Header .Get ("X-Forwarded-For" ))
378
- assertWorkspaceLastUsedAtUpdated (t ,appDetails )
378
+ assertWorkspaceLastUsedAtUpdated (ctx , t ,appDetails )
379
379
})
380
380
381
381
t .Run ("ProxyError" ,func (t * testing.T ) {
@@ -391,7 +391,7 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) {
391
391
require .Equal (t ,http .StatusBadGateway ,resp .StatusCode )
392
392
// An valid authenticated attempt to access a workspace app
393
393
// should count as usage regardless of success.
394
- assertWorkspaceLastUsedAtUpdated (t ,appDetails )
394
+ assertWorkspaceLastUsedAtUpdated (ctx , t ,appDetails )
395
395
})
396
396
397
397
t .Run ("NoProxyPort" ,func (t * testing.T ) {
@@ -407,7 +407,7 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) {
407
407
// TODO(@deansheather): This should be 400. There's a todo in the
408
408
// resolve request code to fix this.
409
409
require .Equal (t ,http .StatusInternalServerError ,resp .StatusCode )
410
- assertWorkspaceLastUsedAtNotUpdated (t ,appDetails )
410
+ assertWorkspaceLastUsedAtNotUpdated (ctx , t ,appDetails )
411
411
})
412
412
413
413
t .Run ("BadJWT" ,func (t * testing.T ) {
@@ -464,7 +464,7 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) {
464
464
require .NoError (t ,err )
465
465
require .Equal (t ,proxyTestAppBody ,string (body ))
466
466
require .Equal (t ,http .StatusOK ,resp .StatusCode )
467
- assertWorkspaceLastUsedAtUpdated (t ,appDetails )
467
+ assertWorkspaceLastUsedAtUpdated (ctx , t ,appDetails )
468
468
469
469
// Since the old token is invalid, the signed app token cookie should have a new value.
470
470
newTokenCookie := findCookie (resp .Cookies (),codersdk .SignedAppTokenCookie )
@@ -1139,7 +1139,7 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) {
1139
1139
_ = resp .Body .Close ()
1140
1140
require .Equal (t ,http .StatusOK ,resp .StatusCode )
1141
1141
require .Equal (t ,resp .Header .Get ("X-Got-Host" ),u .Host )
1142
- assertWorkspaceLastUsedAtUpdated (t ,appDetails )
1142
+ assertWorkspaceLastUsedAtUpdated (ctx , t ,appDetails )
1143
1143
})
1144
1144
1145
1145
t .Run ("WorkspaceAppsProxySubdomainHostnamePrefix/Different" ,func (t * testing.T ) {
@@ -1190,7 +1190,7 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) {
1190
1190
require .NoError (t ,err )
1191
1191
_ = resp .Body .Close ()
1192
1192
require .NotEqual (t ,http .StatusOK ,resp .StatusCode )
1193
- assertWorkspaceLastUsedAtUpdated (t ,appDetails )
1193
+ assertWorkspaceLastUsedAtUpdated (ctx , t ,appDetails )
1194
1194
})
1195
1195
1196
1196
// This test ensures that the subdomain handler does nothing if
@@ -1274,7 +1274,7 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) {
1274
1274
require .NoError (t ,err )
1275
1275
defer resp .Body .Close ()
1276
1276
require .Equal (t ,http .StatusNotFound ,resp .StatusCode )
1277
- assertWorkspaceLastUsedAtNotUpdated (t ,appDetails )
1277
+ assertWorkspaceLastUsedAtNotUpdated (ctx , t ,appDetails )
1278
1278
})
1279
1279
1280
1280
t .Run ("RedirectsWithSlash" ,func (t * testing.T ) {
@@ -1295,7 +1295,7 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) {
1295
1295
loc ,err := resp .Location ()
1296
1296
require .NoError (t ,err )
1297
1297
require .Equal (t ,appDetails .SubdomainAppURL (appDetails .Apps .Owner ).Path ,loc .Path )
1298
- assertWorkspaceLastUsedAtNotUpdated (t ,appDetails )
1298
+ assertWorkspaceLastUsedAtNotUpdated (ctx , t ,appDetails )
1299
1299
})
1300
1300
1301
1301
t .Run ("RedirectsWithQuery" ,func (t * testing.T ) {
@@ -1315,7 +1315,7 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) {
1315
1315
loc ,err := resp .Location ()
1316
1316
require .NoError (t ,err )
1317
1317
require .Equal (t ,appDetails .SubdomainAppURL (appDetails .Apps .Owner ).RawQuery ,loc .RawQuery )
1318
- assertWorkspaceLastUsedAtNotUpdated (t ,appDetails )
1318
+ assertWorkspaceLastUsedAtNotUpdated (ctx , t ,appDetails )
1319
1319
})
1320
1320
1321
1321
t .Run ("Proxies" ,func (t * testing.T ) {
@@ -1358,7 +1358,7 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) {
1358
1358
require .NoError (t ,err )
1359
1359
require .Equal (t ,proxyTestAppBody ,string (body ))
1360
1360
require .Equal (t ,http .StatusOK ,resp .StatusCode )
1361
- assertWorkspaceLastUsedAtUpdated (t ,appDetails )
1361
+ assertWorkspaceLastUsedAtUpdated (ctx , t ,appDetails )
1362
1362
})
1363
1363
1364
1364
t .Run ("ProxiesHTTPS" ,func (t * testing.T ) {
@@ -1403,7 +1403,7 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) {
1403
1403
require .NoError (t ,err )
1404
1404
require .Equal (t ,proxyTestAppBody ,string (body ))
1405
1405
require .Equal (t ,http .StatusOK ,resp .StatusCode )
1406
- assertWorkspaceLastUsedAtUpdated (t ,appDetails )
1406
+ assertWorkspaceLastUsedAtUpdated (ctx , t ,appDetails )
1407
1407
})
1408
1408
1409
1409
t .Run ("ProxiesPort" ,func (t * testing.T ) {
@@ -1420,7 +1420,7 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) {
1420
1420
require .NoError (t ,err )
1421
1421
require .Equal (t ,proxyTestAppBody ,string (body ))
1422
1422
require .Equal (t ,http .StatusOK ,resp .StatusCode )
1423
- assertWorkspaceLastUsedAtUpdated (t ,appDetails )
1423
+ assertWorkspaceLastUsedAtUpdated (ctx , t ,appDetails )
1424
1424
})
1425
1425
1426
1426
t .Run ("ProxyError" ,func (t * testing.T ) {
@@ -1434,7 +1434,7 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) {
1434
1434
require .NoError (t ,err )
1435
1435
defer resp .Body .Close ()
1436
1436
require .Equal (t ,http .StatusBadGateway ,resp .StatusCode )
1437
- assertWorkspaceLastUsedAtUpdated (t ,appDetails )
1437
+ assertWorkspaceLastUsedAtUpdated (ctx , t ,appDetails )
1438
1438
})
1439
1439
1440
1440
t .Run ("ProxyPortMinimumError" ,func (t * testing.T ) {
@@ -1456,7 +1456,7 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) {
1456
1456
err = json .NewDecoder (resp .Body ).Decode (& resBody )
1457
1457
require .NoError (t ,err )
1458
1458
require .Contains (t ,resBody .Message ,"Coder reserves ports less than" )
1459
- assertWorkspaceLastUsedAtNotUpdated (t ,appDetails )
1459
+ assertWorkspaceLastUsedAtNotUpdated (ctx , t ,appDetails )
1460
1460
})
1461
1461
1462
1462
t .Run ("SuffixWildcardOK" ,func (t * testing.T ) {
@@ -1479,7 +1479,7 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) {
1479
1479
require .NoError (t ,err )
1480
1480
require .Equal (t ,proxyTestAppBody ,string (body ))
1481
1481
require .Equal (t ,http .StatusOK ,resp .StatusCode )
1482
- assertWorkspaceLastUsedAtUpdated (t ,appDetails )
1482
+ assertWorkspaceLastUsedAtUpdated (ctx , t ,appDetails )
1483
1483
})
1484
1484
1485
1485
t .Run ("WildcardPortOK" ,func (t * testing.T ) {
@@ -1512,7 +1512,7 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) {
1512
1512
require .NoError (t ,err )
1513
1513
require .Equal (t ,proxyTestAppBody ,string (body ))
1514
1514
require .Equal (t ,http .StatusOK ,resp .StatusCode )
1515
- assertWorkspaceLastUsedAtUpdated (t ,appDetails )
1515
+ assertWorkspaceLastUsedAtUpdated (ctx , t ,appDetails )
1516
1516
})
1517
1517
1518
1518
t .Run ("SuffixWildcardNotMatch" ,func (t * testing.T ) {
@@ -1542,7 +1542,7 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) {
1542
1542
// It's probably rendering the dashboard or a 404 page, so only
1543
1543
// ensure that the body doesn't match.
1544
1544
require .NotContains (t ,string (body ),proxyTestAppBody )
1545
- assertWorkspaceLastUsedAtNotUpdated (t ,appDetails )
1545
+ assertWorkspaceLastUsedAtNotUpdated (ctx , t ,appDetails )
1546
1546
})
1547
1547
1548
1548
t .Run ("DifferentSuffix" ,func (t * testing.T ) {
@@ -1569,7 +1569,7 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) {
1569
1569
// It's probably rendering the dashboard, so only ensure that the body
1570
1570
// doesn't match.
1571
1571
require .NotContains (t ,string (body ),proxyTestAppBody )
1572
- assertWorkspaceLastUsedAtNotUpdated (t ,appDetails )
1572
+ assertWorkspaceLastUsedAtNotUpdated (ctx , t ,appDetails )
1573
1573
})
1574
1574
})
1575
1575
@@ -1628,7 +1628,7 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) {
1628
1628
require .NoError (t ,err )
1629
1629
require .Equal (t ,proxyTestAppBody ,string (body ))
1630
1630
require .Equal (t ,http .StatusOK ,resp .StatusCode )
1631
- assertWorkspaceLastUsedAtUpdated (t ,appDetails )
1631
+ assertWorkspaceLastUsedAtUpdated (ctx , t ,appDetails )
1632
1632
1633
1633
// Since the old token is invalid, the signed app token cookie should have a new value.
1634
1634
newTokenCookie := findCookie (resp .Cookies (),codersdk .SignedAppTokenCookie )
@@ -1652,7 +1652,7 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) {
1652
1652
require .NoError (t ,err )
1653
1653
defer resp .Body .Close ()
1654
1654
require .Equal (t ,http .StatusNotFound ,resp .StatusCode )
1655
- assertWorkspaceLastUsedAtNotUpdated (t ,appDetails )
1655
+ assertWorkspaceLastUsedAtNotUpdated (ctx , t ,appDetails )
1656
1656
})
1657
1657
1658
1658
t .Run ("AuthenticatedOK" ,func (t * testing.T ) {
@@ -1681,7 +1681,7 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) {
1681
1681
require .NoError (t ,err )
1682
1682
defer resp .Body .Close ()
1683
1683
require .Equal (t ,http .StatusOK ,resp .StatusCode )
1684
- assertWorkspaceLastUsedAtUpdated (t ,appDetails )
1684
+ assertWorkspaceLastUsedAtUpdated (ctx , t ,appDetails )
1685
1685
})
1686
1686
1687
1687
t .Run ("PublicOK" ,func (t * testing.T ) {
@@ -1709,7 +1709,7 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) {
1709
1709
require .NoError (t ,err )
1710
1710
defer resp .Body .Close ()
1711
1711
require .Equal (t ,http .StatusOK ,resp .StatusCode )
1712
- assertWorkspaceLastUsedAtUpdated (t ,appDetails )
1712
+ assertWorkspaceLastUsedAtUpdated (ctx , t ,appDetails )
1713
1713
})
1714
1714
1715
1715
t .Run ("HTTPS" ,func (t * testing.T ) {
@@ -1739,7 +1739,7 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) {
1739
1739
require .NoError (t ,err )
1740
1740
defer resp .Body .Close ()
1741
1741
require .Equal (t ,http .StatusOK ,resp .StatusCode )
1742
- assertWorkspaceLastUsedAtUpdated (t ,appDetails )
1742
+ assertWorkspaceLastUsedAtUpdated (ctx , t ,appDetails )
1743
1743
})
1744
1744
})
1745
1745
@@ -2466,33 +2466,33 @@ func testReconnectingPTY(ctx context.Context, t *testing.T, client *codersdk.Cli
2466
2466
// Accessing an app should update the workspace's LastUsedAt.
2467
2467
// NOTE: Despite our efforts with the flush channel, this is inherently racy when used with
2468
2468
// parallel tests on the same workspace/app.
2469
- func assertWorkspaceLastUsedAtUpdated (t testing.TB ,details * Details ) {
2469
+ func assertWorkspaceLastUsedAtUpdated (ctx context. Context , t testing.TB ,details * Details ) {
2470
2470
t .Helper ()
2471
2471
2472
2472
require .NotNil (t ,details .Workspace ,"can't assert LastUsedAt on a nil workspace!" )
2473
- before ,err := details .SDKClient .Workspace (context . Background () ,details .Workspace .ID )
2473
+ before ,err := details .SDKClient .Workspace (ctx ,details .Workspace .ID )
2474
2474
require .NoError (t ,err )
2475
- require .Eventually (t ,func ()bool {
2475
+ testutil .Eventually (ctx , t ,func (ctx context. Context )bool {
2476
2476
// We may need to flush multiple times, since the stats from the app we are testing might be
2477
2477
// collected asynchronously from when we see the connection close, and thus, could race
2478
2478
// against being flushed.
2479
2479
details .FlushStats ()
2480
- after ,err := details .SDKClient .Workspace (context . Background () ,details .Workspace .ID )
2480
+ after ,err := details .SDKClient .Workspace (ctx ,details .Workspace .ID )
2481
2481
return assert .NoError (t ,err )&& after .LastUsedAt .After (before .LastUsedAt )
2482
- },testutil .WaitShort , testutil . IntervalMedium )
2482
+ },testutil .IntervalMedium )
2483
2483
}
2484
2484
2485
2485
// Except when it sometimes shouldn't (e.g. no access)
2486
2486
// NOTE: Despite our efforts with the flush channel, this is inherently racy when used with
2487
2487
// parallel tests on the same workspace/app.
2488
- func assertWorkspaceLastUsedAtNotUpdated (t testing.TB ,details * Details ) {
2488
+ func assertWorkspaceLastUsedAtNotUpdated (ctx context. Context , t testing.TB ,details * Details ) {
2489
2489
t .Helper ()
2490
2490
2491
2491
require .NotNil (t ,details .Workspace ,"can't assert LastUsedAt on a nil workspace!" )
2492
- before ,err := details .SDKClient .Workspace (context . Background () ,details .Workspace .ID )
2492
+ before ,err := details .SDKClient .Workspace (ctx ,details .Workspace .ID )
2493
2493
require .NoError (t ,err )
2494
2494
details .FlushStats ()
2495
- after ,err := details .SDKClient .Workspace (context . Background () ,details .Workspace .ID )
2495
+ after ,err := details .SDKClient .Workspace (ctx ,details .Workspace .ID )
2496
2496
require .NoError (t ,err )
2497
2497
require .Equal (t ,before .LastUsedAt ,after .LastUsedAt ,"workspace LastUsedAt updated when it should not have been" )
2498
2498
}