You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is this a proposal or a bug report? I'm asking because this is working as documented.
A test ends when its Test function returns or calls any of the methods FailNow, Fatal, Fatalf, SkipNow, Skip, or Skipf. Those methods, as well as the Parallel method, must be called only from the goroutine running the Test function.
@cznic Its a proposal. I think it should be allowed. t.Fatal already works in another goroutine aside from main, so I think it should work with multiple goroutines as well.
How do you propose to solve a situation where some TestFoo function launches two goroutines and one of them calls t.Fatal immediately while the other only [N minutes] later? The go test command may have even already finished before that could happen. Or worse, when the TestFoo function returns normally, but a goroutine launched by it calls/would call t.Fatal [N minutes] later?
IMO, the status quo is the only reasonable approach.
How do you propose to solve a situation where some TestFoo function launches two goroutines and one of them calls t.Fatal immediately while the other only [N minutes] later? The go test command may have even already finished before that could happen.
The main test goroutine still needs to wait for the other two goroutines like it would with t.Error. So the go test command would not have finished before that could happen.
Or worse, when the TestFoo function returns normally, but a goroutine launched by it calls/would call t.Fatal [N minutes] later?
That should of course cause a panic like it does now.
The main test goroutine still needs to wait for the other two goroutines like it would with t.Error. So the go test command would not have finished before that could happen.
How to do that? The goroutine that invokes TestMeow in the OP has no knowledge about it launching other goroutines that may possibly later call t.Fatal.
That should of course cause a panic like it does now.
This program does not panic now, nor it reports any error. The t.Fatal call is just silently lost because the program exits before calling time.After returned
How to do that? The goroutine that invokes TestMeow in the OP has no knowledge about it launching other goroutines that may possibly later call t.Fatal.
The user needs to sync by themselves. Its the same problem as with t.Error. Its not a distinct problem to t.Fatal.
This program does not panic now, nor it reports any error. The t.Fatal call is just silently lost because the program exits before calling time.After returned
The bug there is that you're not waiting for the main goroutine. The only way
It's very different in that one terminates execution of the TestXXX function while the other does not. And that also explains why t.Error is allowed from any goroutine while t.Fatal is not.
It's very different in that one terminates execution of the TestXXX function while the other does not. And that also explains why t.Error is allowed from any goroutine while t.Fatal is not.
Here's my argument. t.Error is allowed from any goroutine without any race conditions. t.Fatal is allowed from any goroutine too, even though it is documented that you should only be calling it from the main test goroutine. Go cannot enforce that t.Fatal should only be called from the main test goroutine. So at most, its a bug in that you are not following convention. If however, you run t.Fatal async in multiple goroutines, it goes from convention violation to race condition. I don't think that makes sense. Its not racey in an important way.
Thanks so much @bcmills - that is exactly what I was proposing in my comment :)
@nhooyr please refer to that issue as far as making the testing package's behavior more consistent and intuitive. If you would still like to propose that concurrent Fatal calls were supported and documented, feel free to open a new issue following the proposal process: https://github.com/golang/proposal
Activity
[-]allow multiple async t.Fatals[/-][+]testing: allow multiple async t.Fatals[/+]cznic commentedon May 20, 2018
Is this a proposal or a bug report? I'm asking because this is working as documented.
mvdan commentedon May 20, 2018
Like @cznic said, this issue is different from #24438.
Erroris documented to support being called by any goroutine, butFatalis not.However, perhaps the testing package could panic in a more obvious way, as opposed to silently working until someone uses the race detector.
nhooyr commentedon May 20, 2018
@cznic Its a proposal. I think it should be allowed.
t.Fatalalready works in another goroutine aside from main, so I think it should work with multiple goroutines as well.cznic commentedon May 20, 2018
How do you propose to solve a situation where some
TestFoofunction launches two goroutines and one of them callst.Fatalimmediately while the other only [N minutes] later? Thego testcommand may have even already finished before that could happen. Or worse, when theTestFoofunction returns normally, but a goroutine launched by it calls/would callt.Fatal[N minutes] later?IMO, the status quo is the only reasonable approach.
nhooyr commentedon May 20, 2018
The main test goroutine still needs to wait for the other two goroutines like it would with
t.Error. So thego testcommand would not have finished before that could happen.That should of course cause a panic like it does now.
cznic commentedon May 20, 2018
How to do that? The goroutine that invokes
TestMeowin the OP has no knowledge about it launching other goroutines that may possibly later callt.Fatal.This program does not panic now, nor it reports any error. The
t.Fatalcall is just silently lost because the program exits before callingtime.Afterreturnednhooyr commentedon May 20, 2018
The user needs to sync by themselves. Its the same problem as with
t.Error. Its not a distinct problem tot.Fatal.The bug there is that you're not waiting for the main goroutine. The only way
That however does produce the panic I was talking about. You can change the
t.Fataltot.Errorto see it also occurs witht.Error.cznic commentedon May 20, 2018
It's very different in that one terminates execution of the
TestXXXfunction while the other does not. And that also explains whyt.Erroris allowed from any goroutine whilet.Fatalis not.nhooyr commentedon May 20, 2018
Here's my argument.
t.Erroris allowed from any goroutine without any race conditions.t.Fatalis allowed from any goroutine too, even though it is documented that you should only be calling it from the main test goroutine. Go cannot enforce thatt.Fatalshould only be called from the main test goroutine. So at most, its a bug in that you are not following convention. If however, you runt.Fatalasync in multiple goroutines, it goes from convention violation to race condition. I don't think that makes sense. Its not racey in an important way.bcmills commentedon May 21, 2018
That's not necessarily true. See #15758.
mvdan commentedon May 21, 2018
Thanks so much @bcmills - that is exactly what I was proposing in my comment :)
@nhooyr please refer to that issue as far as making the testing package's behavior more consistent and intuitive. If you would still like to propose that concurrent Fatal calls were supported and documented, feel free to open a new issue following the proposal process: https://github.com/golang/proposal