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

testing: go test shouldn't terminate if leftover process remain when executed in verbose mode (-v flag) #12538

Closed
mildred opened this issue Sep 8, 2015 · 2 comments
Milestone

Comments

@mildred
Copy link

mildred commented Sep 8, 2015

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:

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.

@ianlancetaylor 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
@ianlancetaylor
Copy link
Contributor

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?

@ianlancetaylor ianlancetaylor added this to the Go1.6 milestone Sep 8, 2015
@rsc
Copy link
Contributor

rsc commented Nov 5, 2015

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.

@rsc rsc closed this as completed Nov 5, 2015
@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

4 participants