Skip to content

Commit 19abde1

Browse files
authored
chore(coderd): fix test flake with auditor (#11316)
1 parent 167c152 commit 19abde1

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

coderd/workspacebuilds_test.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,12 @@ func TestWorkspaceBuild(t *testing.T) {
5151
_ = coderdtest.AwaitWorkspaceBuildJobCompleted(t, client, workspace.LatestBuild.ID)
5252
// Create workspace will also start a build, so we need to wait for
5353
// it to ensure all events are recorded.
54-
require.Len(t, auditor.AuditLogs(), 2)
55-
require.Equal(t, auditor.AuditLogs()[0].Ip.IPNet.IP.String(), "127.0.0.1")
56-
require.Equal(t, auditor.AuditLogs()[1].Ip.IPNet.IP.String(), "127.0.0.1")
54+
require.Eventually(t, func() bool {
55+
logs := auditor.AuditLogs()
56+
return len(logs) == 2 &&
57+
assert.Equal(t, logs[0].Ip.IPNet.IP.String(), "127.0.0.1") &&
58+
assert.Equal(t, logs[1].Ip.IPNet.IP.String(), "127.0.0.1")
59+
}, testutil.WaitShort, testutil.IntervalFast)
5760
}
5861

5962
func TestWorkspaceBuildByBuildNumber(t *testing.T) {
@@ -969,8 +972,11 @@ func TestPostWorkspaceBuild(t *testing.T) {
969972
require.NoError(t, err)
970973
coderdtest.AwaitWorkspaceBuildJobCompleted(t, client, build.ID)
971974

972-
require.Len(t, auditor.AuditLogs(), 1)
973-
require.Equal(t, auditor.AuditLogs()[0].Ip.IPNet.IP.String(), "127.0.0.1")
975+
require.Eventually(t, func() bool {
976+
logs := auditor.AuditLogs()
977+
return len(logs) > 0 &&
978+
assert.Equal(t, logs[0].Ip.IPNet.IP.String(), "127.0.0.1")
979+
}, testutil.WaitShort, testutil.IntervalFast)
974980
})
975981

976982
t.Run("IncrementBuildNumber", func(t *testing.T) {

0 commit comments

Comments
 (0)