Skip to content

Commit

Permalink
cmd/dlv: fix race in test (go-delve#805)
Browse files Browse the repository at this point in the history
% go test -race -v -short

=== RUN   TestBuild
==================
WARNING: DATA RACE
Write at 0x00c4201379a0 by goroutine 9:
  os.(*file).close()
      /usr/local/go/src/os/file_unix.go:143 +0x10a
  os.(*File).Close()
      /usr/local/go/src/os/file_unix.go:132 +0x55
  os/exec.(*Cmd).closeDescriptors()
      /usr/local/go/src/os/exec/exec.go:263 +0x67
  os/exec.(*Cmd).Wait()
      /usr/local/go/src/os/exec/exec.go:448 +0x2b8
  github.com/derekparker/delve/cmd/dlv.TestBuild.func1()
      /home/kbuilder/go/src/github.com/derekparker/delve/cmd/dlv/dlv_test.go:82 +0x8e
  github.com/derekparker/delve/cmd/dlv.TestBuild()
      /home/kbuilder/go/src/github.com/derekparker/delve/cmd/dlv/dlv_test.go:104 +0xb6a
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:657 +0x107

Previous read at 0x00c4201379a0 by goroutine 12:
  os.(*File).Read()
      /usr/local/go/src/os/file.go:98 +0x70
  bufio.(*Scanner).Scan()
      /usr/local/go/src/bufio/scan.go:207 +0x539
  github.com/derekparker/delve/cmd/dlv.TestBuild.func2()
      /home/kbuilder/go/src/github.com/derekparker/delve/cmd/dlv/dlv_test.go:93 +0x38

Change-Id: I09d188dbf964fe4af0b33b6a8fcfe51396176b7e
  • Loading branch information
hyangah authored and derekparker committed Apr 26, 2017
1 parent d9bd90d commit c67986e
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion cmd/dlv/dlv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,16 @@ func TestBuild(t *testing.T) {
stdout, err := cmd.StdoutPipe()
assertNoError(err, t, "stdout pipe")
cmd.Start()
done := make(chan struct{})
defer func() {
if runtime.GOOS != "windows" {
cmd.Process.Signal(os.Interrupt)
cmd.Wait()
} else {
// sending os.Interrupt on windows is not supported
cmd.Process.Kill()
}
<-done
cmd.Wait()
}()

scan := bufio.NewScanner(stdout)
Expand All @@ -93,6 +95,7 @@ func TestBuild(t *testing.T) {
for scan.Scan() {
// keep pipe empty
}
close(done)
}()

client := rpc2.NewClient(listenAddr)
Expand Down

0 comments on commit c67986e

Please sign in to comment.