Skip to content

testing: testlog kills tests that call m.Run multiple times #23129

Closed

Description

@rsc

After fixing #23047, running the influxdb tests turned up a failure caused by github.com/influxdata/influxdb/tests/server_test.go, which (surprise!) runs m.Run in a loop during TestMain:

func TestMain(m *testing.M) {
	var r int
	for _, indexType = range tsdb.RegisteredIndexes() {
		... setup ...

		// Run test suite.
		if testing.Verbose() {
			fmt.Printf("============= Running all tests for %q index =============\n", indexType)
		}
		if thisr := m.Run(); r == 0 {
			r = thisr // We'll always remember the first time r is non-zero
		}

		... cleanup ...
	}
	os.Exit(r)
}

This only barely works today. Flags like -test.cpuprofile overwrite the output on each iteration, so that the profile applies only to the last iteration. But it doesn't crash in Go 1.9. Now it crashes, because the second m.Run calls testlog.SetLogger, and testlog.SetLogger must only be called once.

I guess now we have to support running m.Run multiple times. Sigh.

Activity

  1. added this to the Go1.10 milestone on Dec 14, 2017
  2. bradfitz commented on Dec 14, 2017

    @bradfitz
    Contributor

    There's no sad face emoji reaction, so ... 😢

  3. gopherbot commented on Dec 14, 2017

    @gopherbot
    Contributor

    Change https://golang.org/cl/83956 mentions this issue: testing: do not crash when m.Run is called twice and -test.testlogfile is used

  4. locked and limited conversation to collaborators on Dec 14, 2018
  5. unlocked this conversation on Aug 28, 2020
  6. gopherbot commented on Aug 28, 2020

    @gopherbot
    Contributor

    Change https://golang.org/cl/251262 mentions this issue: testing: restore os.Exit(0) after every call to (*M).Run

  7. locked and limited conversation to collaborators on Aug 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions