diff --git a/pkg/wal/processor/transformer/wal_postgres_anon_rule_parser_test.go b/pkg/wal/processor/transformer/wal_postgres_anon_rule_parser_test.go index 28d22b0f..6eb651bf 100644 --- a/pkg/wal/processor/transformer/wal_postgres_anon_rule_parser_test.go +++ b/pkg/wal/processor/transformer/wal_postgres_anon_rule_parser_test.go @@ -160,7 +160,13 @@ func TestAnonRuleParser_ParseAndValidate(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { - t.Parallel() + // dumpToFile subtests share a hardcoded filename + // (anonRulesFile) and a deferred os.Remove of that path. Running + // them in parallel races: the error-case's cleanup can delete + // the success-case's file before its os.Stat check. + if !tc.dumpToFile { + t.Parallel() + } // Clean up any test files defer func() { diff --git a/pkg/wal/processor/webhook/notifier/webhook_notifier_test.go b/pkg/wal/processor/webhook/notifier/webhook_notifier_test.go index 1ba9dbb8..373877bf 100644 --- a/pkg/wal/processor/webhook/notifier/webhook_notifier_test.go +++ b/pkg/wal/processor/webhook/notifier/webhook_notifier_test.go @@ -363,24 +363,29 @@ func TestNotifier(t *testing.T) { close(doneChan) }() + walEvent := &wal.Event{ + CommitPosition: wal.CommitPosition("1"), + Data: &wal.Data{ + Action: "I", + }, + } + timer := time.NewTimer(5 * time.Second) defer timer.Stop() - var processErr error for { select { case <-doneChan: - require.ErrorIs(t, processErr, errTest) + // Notify has exited. The next ProcessWALEvent must observe the + // closed notifyDone and return the propagated error — assert on a + // fresh call rather than the previous loop iteration's result, + // which can be nil if Notify exited between PWE calls. + require.ErrorIs(t, n.ProcessWALEvent(context.Background(), walEvent), errTest) return case <-timer.C: t.Error("test timeout") return default: - processErr = n.ProcessWALEvent(context.Background(), &wal.Event{ - CommitPosition: wal.CommitPosition("1"), - Data: &wal.Data{ - Action: "I", - }, - }) + _ = n.ProcessWALEvent(context.Background(), walEvent) } } }