Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3b7380f

Browse files
authored
fix: fix race in assertWorkspaceLastUsedAtUpdated (#12899)
fixes #12789 Stats are collected asynchronously with respect to sessions ending. Flush repeatedly so that we pick up the collection if we missed it.
1 parent f96ce80 commit 3b7380f

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

coderd/workspaceapps/apptest/apptest.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -1765,9 +1765,11 @@ func assertWorkspaceLastUsedAtUpdated(t testing.TB, details *Details) {
17651765
require.NotNil(t, details.Workspace, "can't assert LastUsedAt on a nil workspace!")
17661766
before, err := details.SDKClient.Workspace(context.Background(), details.Workspace.ID)
17671767
require.NoError(t, err)
1768-
// Wait for stats to fully flush.
1769-
details.FlushStats()
17701768
require.Eventually(t, func() bool {
1769+
// We may need to flush multiple times, since the stats from the app we are testing might be
1770+
// collected asynchronously from when we see the connection close, and thus, could race
1771+
// against being flushed.
1772+
details.FlushStats()
17711773
after, err := details.SDKClient.Workspace(context.Background(), details.Workspace.ID)
17721774
return assert.NoError(t, err) && after.LastUsedAt.After(before.LastUsedAt)
17731775
}, testutil.WaitShort, testutil.IntervalMedium)

0 commit comments

Comments
 (0)