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

Calculating the test suite duraion from timestamps #4281

Merged
merged 1 commit into from
Feb 23, 2025

Conversation

linzhp
Copy link
Contributor

@linzhp linzhp commented Feb 23, 2025

What type of PR is this?
Bug fix

What does this PR do? Why is it needed?
When test cases use t.Parallel(), the duration of a test suite is more than that of the test case with the same name. For example, when we run this test:

func TestParallel(t *testing.T) {
	t.Run("Test 1", func(t *testing.T) {
		time.Sleep(1 * time.Second)
	})

	t.Run("Test 2", func(t *testing.T) {
		t.Parallel()
		time.Sleep(2 * time.Second)
	})
}

The log shows:

=== RUN   TestParallel
=== RUN   TestParallel/Test_1
=== RUN   TestParallel/Test_2
=== PAUSE TestParallel/Test_2
=== CONT  TestParallel/Test_2
--- PASS: TestParallel (1.00s)
    --- PASS: TestParallel/Test_1 (1.00s)
    --- PASS: TestParallel/Test_2 (2.00s)
PASS

TestParallel/Test_2 took 2 seconds, but the test case TestParallel only took 1 second. Apparently, the test suite TestParallel should have taken more than 1 second.

This PR uses the timestamps from JSON events to determine end to end time of a test suite.

@linzhp
Copy link
Contributor Author

linzhp commented Feb 23, 2025

CI failed due to bazelbuild/continuous-integration#2183

@fmeum fmeum enabled auto-merge (squash) February 23, 2025 19:31
@fmeum fmeum merged commit 3af0c6f into bazel-contrib:master Feb 23, 2025
1 check passed
@linzhp linzhp deleted the suite_time branch February 24, 2025 00:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants