From 95f37501cad4c28cf7776a709a29ce79a182781e Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Fri, 11 Jul 2025 20:58:45 +0100 Subject: [PATCH] chore: fix flake in TestWorkspaceBuildsProvisionerState --- coderd/workspacebuilds_test.go | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/coderd/workspacebuilds_test.go b/coderd/workspacebuilds_test.go index ebab0770b71b4..0855d6091f7e4 100644 --- a/coderd/workspacebuilds_test.go +++ b/coderd/workspacebuilds_test.go @@ -494,11 +494,14 @@ func TestWorkspaceBuildsProvisionerState(t *testing.T) { require.NoError(t, err) coderdtest.AwaitWorkspaceBuildJobCompleted(t, client, build.ID) - // Validate that the deletion was audited. - require.True(t, auditor.Contains(t, database.AuditLog{ - ResourceID: build.ID, - Action: database.AuditActionDelete, - })) + // Validate that the deletion was audited. This happens after the transaction + // is committed, so it may not show up in the mock auditor immediately. + testutil.Eventually(ctx, t, func(context.Context) bool { + return auditor.Contains(t, database.AuditLog{ + ResourceID: build.ID, + Action: database.AuditActionDelete, + }) + }, testutil.IntervalFast) }) t.Run("NoProvisioners", func(t *testing.T) { @@ -535,11 +538,14 @@ func TestWorkspaceBuildsProvisionerState(t *testing.T) { require.Empty(t, ws) require.Equal(t, http.StatusGone, coderdtest.SDKError(t, err).StatusCode()) - // Validate that the deletion was audited. - require.True(t, auditor.Contains(t, database.AuditLog{ - ResourceID: build.ID, - Action: database.AuditActionDelete, - })) + // Validate that the deletion was audited. This happens after the transaction + // is committed, so it may not show up in the mock auditor immediately. + testutil.Eventually(ctx, t, func(context.Context) bool { + return auditor.Contains(t, database.AuditLog{ + ResourceID: build.ID, + Action: database.AuditActionDelete, + }) + }, testutil.IntervalFast) }) }) }