Skip to content

Commit 985b98b

Browse files
committed
Avoid racing writes in the mock emitter
1 parent c70c40d commit 985b98b

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

lib/auth/stableunixusers/stableunixusers_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ func TestStableUNIXUsers(t *testing.T) {
204204
_, err = clusterConfiguration.UpsertAuthPreference(ctx, authPref)
205205
require.NoError(t, err)
206206

207+
emitter.emitted = true
207208
eg, ctx := errgroup.WithContext(ctx)
208209
for i := range 1000 {
209210
eg.Go(func() error {
@@ -219,7 +220,10 @@ type mockEmitter struct {
219220
}
220221

221222
func (e *mockEmitter) EmitAuditEvent(ctx context.Context, ev apievents.AuditEvent) error {
222-
e.emitted = true
223+
if !e.emitted {
224+
// avoid racing a write if the flag is already set
225+
e.emitted = true
226+
}
223227
return nil
224228
}
225229

0 commit comments

Comments
 (0)