diff --git a/internal/scheduler/recommendation_completeness_integration_test.go b/internal/scheduler/recommendation_completeness_integration_test.go index 414bf9f02..93bc72789 100644 --- a/internal/scheduler/recommendation_completeness_integration_test.go +++ b/internal/scheduler/recommendation_completeness_integration_test.go @@ -26,6 +26,27 @@ import ( "github.com/stretchr/testify/require" ) +// lockedBuffer is a bytes.Buffer safe for concurrent use. The test captures +// the process-wide logger, and connection pools from other subtests on the +// shared Postgres server (#1400) can still log from background goroutines +// (pgxpool's idle-connection creation) while the test reads the capture. +type lockedBuffer struct { + mu sync.Mutex + buf bytes.Buffer +} + +func (b *lockedBuffer) Write(p []byte) (int, error) { + b.mu.Lock() + defer b.mu.Unlock() + return b.buf.Write(p) +} + +func (b *lockedBuffer) String() string { + b.mu.Lock() + defer b.mu.Unlock() + return b.buf.String() +} + type completenessHTTP struct { resourceType string accounts []any @@ -205,7 +226,7 @@ func TestAWSRecommendationCompletenessPersistence(t *testing.T) { } { t.Run(tc.name, func(t *testing.T) { ctx := context.Background() - var diagnostics bytes.Buffer + var diagnostics lockedBuffer previous := logging.SetOutput(&diagnostics) t.Cleanup(func() { logging.SetOutput(previous) }) container := testhelpers.RequireMigratedDatabase(ctx, t, "../database/postgres/migrations")