Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Data race if c.Fail is called in a goroutine #43
Comments
|
Don't ever call FailNow in gocheck or even in the testing package if you are inside a goroutine. These will call Go's runtime.Goexit, which will not do the right thing if you are inside a goroutine. |
niemeyer
closed this
Jun 10, 2015
|
Sorry, I jumped to conclusions too soon. The race exists also without FailNow. |
niemeyer
reopened this
Jun 10, 2015
|
Please read the example I supplied, nobody is calling FailNow directly, but On Thu, 11 Jun 2015 09:07 Gustavo Niemeyer notifications@github.com wrote:
|
|
I win. ;-) |
|
Lol. Yes, sorry about the crap issue title, it totally buried the lead. On Thu, 11 Jun 2015 09:10 Gustavo Niemeyer notifications@github.com wrote:
|
niemeyer
changed the title from
Data race if c.Fail, or c.FailNow are called in a goroutine
to
Data race if c.Fail is called in a goroutine
Jun 10, 2015
added a commit
to juju/check
that referenced
this issue
Jun 17, 2015
rogpeppe
commented
Jun 17, 2015
|
The gocheck docs should document exactly what concurrent behaviour If it was up to me, I would explicitly allow FailNow within a goroutine, |
|
It feels a bit pointless to "allow" something to happen that has completely unusual and not useful behavior. "Yeah, you can call panic, but it won't work! Hah!" |
rogpeppe
commented
Jun 18, 2015
|
If I've started a goroutine I don't expect it to be able to influence other And of course it's useful for just the same reason that Assert is useful Strictly speaking, any code that calls methods on a *C instance |
|
Please read the sample code Rog, I'm only calling c.Error. I'm sorry I buried the lede by talking about c.FailNow
|
rogpeppe
commented
Jun 18, 2015
|
I'm sorry, this has indeed drifted because I was responding to Gustavo's |
|
The
|
rogpeppe
commented
Jun 18, 2015
|
The testing package should be better documented in this respect too.
I'd argue that's it is less of a burden in the testing package because all tests are explicit |
|
|
rogpeppe
commented
Jun 18, 2015
|
I was trying to suggest that because the stdlib testing documentation explicitly states |
davecheney commentedJun 10, 2015
Consider this test case
When running the test with -race, the following data race results