Skip to content

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

@mildred

Description

@mildred

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions