Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down
Loading