Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: "go test -race" with race condition detected should exit with exit code 1 #12129

Closed
dlsniper opened this issue Aug 13, 2015 · 5 comments

Comments

@dlsniper
Copy link
Contributor

Hi,

I'm running the following command

go test -race

When there's a race condition detected, the exit code for go test should be 1 not 0.

I've replicated this with go 1.4, go 1.4.2 and go 1.5 rc1

I've forgot to add that I'm using gocheck for helping with tests. Not sure if it's interfering or not.

@mikioh mikioh changed the title tests with race condition detected should exit with exit code 1 cmd/go: "go test -race" with race condition detected should exit with exit code 1 Aug 13, 2015
@ianlancetaylor ianlancetaylor added this to the Unplanned milestone Aug 13, 2015
@ALTree
Copy link
Member

ALTree commented Oct 25, 2015

I can't reproduce this on 1.5.1 or tip.

package main

import (
    "fmt"
    "math/rand"
    "testing"
    "time"
)

func TestFoo(te *testing.T) {
    start := time.Now()
    var t *time.Timer
    t = time.AfterFunc(randomDuration(), func() {
        fmt.Println(time.Now().Sub(start))
        t.Reset(randomDuration())
    })
    time.Sleep(5 * time.Second)
}

func randomDuration() time.Duration {
    return time.Duration(rand.Int63n(1e9))
}

Now running

$ go test -race racy_test.go
948.011474ms
==================
WARNING: DATA RACE
Read by goroutine 8:
  command-line-arguments.TestFoo.func1()
      /home/alberto/Desktop/racy_test.go:15 +0x1b4

Previous write by goroutine 6:
  command-line-arguments.TestFoo()
      /home/alberto/Desktop/racy_test.go:16 +0x14d
  testing.tRunner()
      /tmp/workdir/go/src/testing/testing.go:456 +0xdc

Goroutine 8 (running) created at:
  time.goFunc()
      /tmp/workdir/go/src/time/sleep.go:129 +0x6d

Goroutine 6 (running) created at:
  testing.RunTests()
      /tmp/workdir/go/src/testing/testing.go:561 +0xaa3
  testing.(*M).Run()
      /tmp/workdir/go/src/testing/testing.go:494 +0xe4
  main.main()
      command-line-arguments/_test/_testmain.go:54 +0x20f
==================
1.030587504s
1.697008686s
1.932285314s
2.219673927s
2.769221406s
3.402550751s
3.734587528s
3.917955035s
4.398534118s
PASS
5.159202123s
5.42332977s
Found 1 data race(s)
FAIL    command-line-arguments  6.006s

and the exit value is 1

echo $?
1

@adg adg closed this as completed Oct 25, 2015
@zellyn
Copy link

zellyn commented Nov 5, 2015

This might deserve inclusion in the next point release of 1.4: see discussion on golang-nuts.

@ianlancetaylor
Copy link
Contributor

@zellyn We don't make new point releases for test failures. The general rule is that we only make a point release for a critical problem with no workaround. We're very unlikely to make another point release of 1.4 in any case.

@zellyn
Copy link

zellyn commented Nov 5, 2015

@ianlancetaylor Ah, okay - for us, moving to 1.5 will fix this problem anyway. Thanks!

@davecheney
Copy link
Contributor

That's the best answer, 1.4 won't be getting any more updates.

On Fri, 6 Nov 2015, 01:37 Zellyn Hunter notifications@github.com wrote:

@ianlancetaylor https://github.com/ianlancetaylor Ah, okay - for us,
moving to 1.5 will fix this problem anyway. Thanks!


Reply to this email directly or view it on GitHub
#12129 (comment).

@golang golang locked and limited conversation to collaborators Nov 4, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants