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: testlog kills tests that call m.Run multiple times #23129

rsc opened this issue Dec 14, 2017 · 3 comments

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

rsc opened this issue Dec 14, 2017 · 3 comments


Copy link

@rsc rsc commented Dec 14, 2017

After fixing #23047, running the influxdb tests turned up a failure caused by, 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 ...

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.

@rsc rsc added this to the Go1.10 milestone Dec 14, 2017
@rsc rsc added the release-blocker label Dec 14, 2017
Copy link

@bradfitz bradfitz commented Dec 14, 2017

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

Copy link

@gopherbot gopherbot commented Dec 14, 2017

Change mentions this issue: testing: do not crash when m.Run is called twice and -test.testlogfile is used

@gopherbot gopherbot closed this in 94d7c88 Dec 14, 2017
@golang golang locked and limited conversation to collaborators Dec 14, 2018
@bcmills bcmills removed the FrozenDueToAge label Aug 28, 2020
@golang golang unlocked this conversation Aug 28, 2020
Copy link

@gopherbot gopherbot commented Aug 28, 2020

Change mentions this issue: testing: restore os.Exit(0) after every call to (*M).Run

gopherbot pushed a commit that referenced this issue Aug 28, 2020
cmd/go.TestScript/test_main_twice demonstrates a program that invokes
(*M).Run twice in a row. If we only restore os.Exit(0) in m.afterOnce,
we will fail to restore it after the second run and fail the test
process despite both runs passing.

Updates #29062
Updates #23129

Change-Id: Id22ec68f1708e4583c8dda14a8ba0efae7178b85
Run-TryBot: Bryan C. Mills <>
Reviewed-by: Ian Lance Taylor <>
TryBot-Result: Gobot Gobot <>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.