Fix race in remote_test.go

PiperOrigin-RevId: 447505504
This commit is contained in:
Fabricio Voznika 2022-05-09 10:30:54 -07:00 committed by gVisor bot
parent d5002c6adc
commit b3609b7167
1 changed files with 20 additions and 1 deletions

View File

@ -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) {