提交 c67986ed 编写于 作者: H Hyang-Ah Hana Kim 提交者: Derek Parker

cmd/dlv: fix race in test (#805)

% 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
上级 d9bd90d7
......@@ -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)
......@@ -93,6 +95,7 @@ func TestBuild(t *testing.T) {
for scan.Scan() {
// keep pipe empty
}
close(done)
}()
client := rpc2.NewClient(listenAddr)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册