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
I wrote a test that didn' terminate in normal mode, but did terminate when running in verbose mode (-v flag). I believe the behaviour should be the same in both cases.
The test uses a TestMain function that looked like:
func TestMain(m *testing.M) {
var psql *database.Postgresql
var err error
log.Println("Create test database")
psql, db, err = database.StartPostgresqlTempConnect()
if err != nil {
log.Fatal(err)
os.Exit(1)
}
defer psql.Close()
defer db.Close()
os.Exit(m.Run())
}
The problem being that os.Exit was called, and the defer statement were not being run. There were leftover postgresql processes running.
This is obviously a problem with the test, but I still believe that the go test command should behave the same way, whether the -v flag is specified or not.
The text was updated successfully, but these errors were encountered:
ianlancetaylor
changed the title
go test shouldn't terminate if leftover process remain when executed in verbose mode (-v flag)
testing: go test shouldn't terminate if leftover process remain when executed in verbose mode (-v flag)
Sep 8, 2015
I don't understand why the fact that the deferred functions in TestMain were not run caused a change in behaviour when using the -test.v option. Can you provide a small complete test case showing the problem?
I don't see how -test.v could affect this. Also package testing did not call os.Exit: your code did. If you don't want your program to exit, don't call os.Exit. If it does call os.Exit, there's nothing package testing can do about that.
In general it is fine to have background goroutines running at exit. And while we might look for child subprocesses, some child subprocesses might be okay (for example if the test invoked something that kicked off a background daemon as part of its operation). Inserting that kind of check into package testing seems unwise.
go version go1.5 linux/amd64
I wrote a test that didn' terminate in normal mode, but did terminate when running in verbose mode (
-v
flag). I believe the behaviour should be the same in both cases.The test uses a TestMain function that looked like:
The problem being that
os.Exit
was called, and the defer statement were not being run. There were leftover postgresql processes running.This is obviously a problem with the test, but I still believe that the
go test
command should behave the same way, whether the-v
flag is specified or not.The text was updated successfully, but these errors were encountered: