From b3609b7167a76a11d42dad8d5b0fa77a9fd87974 Mon Sep 17 00:00:00 2001 From: Fabricio Voznika Date: Mon, 9 May 2022 10:30:54 -0700 Subject: [PATCH] Fix race in remote_test.go PiperOrigin-RevId: 447505504 --- .../seccheck/checkers/remote/remote_test.go | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/pkg/sentry/seccheck/checkers/remote/remote_test.go b/pkg/sentry/seccheck/checkers/remote/remote_test.go index 369b35aef..1b6f80a9a 100644 --- a/pkg/sentry/seccheck/checkers/remote/remote_test.go +++ b/pkg/sentry/seccheck/checkers/remote/remote_test.go @@ -21,6 +21,7 @@ import ( "os/exec" "path/filepath" "strings" + "sync" "testing" "time" @@ -46,10 +47,28 @@ func waitForFile(path string) error { }, 5*time.Second) } +type syncBuffer struct { + mu sync.Mutex + // +checklocks:mu + buf bytes.Buffer +} + +func (s *syncBuffer) Write(p []byte) (n int, err error) { + s.mu.Lock() + defer s.mu.Unlock() + return s.buf.Write(p) +} + +func (s *syncBuffer) String() string { + s.mu.Lock() + defer s.mu.Unlock() + return s.buf.String() +} + type exampleServer struct { path string cmd *exec.Cmd - out bytes.Buffer + out syncBuffer } func newExampleServer(quiet bool) (*exampleServer, error) {