Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6cdc9c4

Browse files
committed
maybe fix race conditions?
1 parent64f970f commit6cdc9c4

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

‎coderd/workspaceapps/apptest/apptest.go‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) {
147147
require.NoError(t,err)
148148
require.True(t,loc.Query().Has("message"))
149149
require.True(t,loc.Query().Has("redirect"))
150-
assertWorkspaceLastUsedAtNotUpdated(t,appDetails)
150+
assertWorkspaceLastUsedAtUpdated(t,appDetails)
151151
})
152152

153153
t.Run("LoginWithoutAuthOnProxy",func(t*testing.T) {
@@ -185,7 +185,7 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) {
185185
// request is getting stripped.
186186
require.Equal(t,u.Path,redirectURI.Path+"/")
187187
require.Equal(t,u.RawQuery,redirectURI.RawQuery)
188-
assertWorkspaceLastUsedAtNotUpdated(t,appDetails)
188+
assertWorkspaceLastUsedAtUpdated(t,appDetails)
189189
})
190190

191191
t.Run("NoAccessShould404",func(t*testing.T) {
@@ -396,7 +396,7 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) {
396396
// TODO(@deansheather): This should be 400. There's a todo in the
397397
// resolve request code to fix this.
398398
require.Equal(t,http.StatusInternalServerError,resp.StatusCode)
399-
assertWorkspaceLastUsedAtNotUpdated(t,appDetails)
399+
assertWorkspaceLastUsedAtUpdated(t,appDetails)
400400
})
401401
})
402402

@@ -1570,16 +1570,23 @@ func assertWorkspaceLastUsedAtUpdated(t testing.TB, details *Details) {
15701570
t.Helper()
15711571

15721572
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+
returnws.LastUsedAt.After(details.Workspace.LastUsedAt)
1579+
},testutil.WaitShort,testutil.IntervalMedium,"workspace LastUsedAt not updated when it should have been")
15761580
}
15771581

15781582
// Except when it sometimes shouldn't (e.g. no access)
15791583
funcassertWorkspaceLastUsedAtNotUpdated(t testing.TB,details*Details) {
15801584
t.Helper()
15811585

15821586
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)
15831590
ws,err:=details.SDKClient.Workspace(context.Background(),details.Workspace.ID)
15841591
require.NoError(t,err)
15851592
require.Equal(t,ws.LastUsedAt,details.Workspace.LastUsedAt,"workspace LastUsedAt updated when it should not have been")

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp