Skip to content

GrpcCleanupRule errors out when retrying tests #8917

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

Closed
laurentgo opened this issue Feb 14, 2022 · 2 comments · Fixed by #8918
Closed

GrpcCleanupRule errors out when retrying tests #8917

laurentgo opened this issue Feb 14, 2022 · 2 comments · Fixed by #8918

Comments

@laurentgo
Copy link
Contributor

When GrpcCleanupRule is used as a class rule and surefire/failsafe maven plugins are configured to retry failing tests, the rule throws an exception on the second run of the test with the following stacktrace:

java.lang.IllegalStateException: This stopwatch is already running.
	at com.google.common.base.Preconditions.checkState(Preconditions.java:502)
	at com.google.common.base.Stopwatch.start(Stopwatch.java:159)
	at io.grpc.testing.GrpcCleanupRule.teardown(GrpcCleanupRule.java:150)
	at io.grpc.testing.GrpcCleanupRule.access$100(GrpcCleanupRule.java:48)
	at io.grpc.testing.GrpcCleanupRule$1.evaluate(GrpcCleanupRule.java:138)
	at org.junit.rules.RunRules.evaluate(RunRules.java:20)
	at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:299)
	at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:293)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.lang.Thread.run(Thread.java:829)

What version of gRPC-Java are you using?

1.44.0

What is your environment?

Linux/Java 8

What did you expect to see?

Expectation is for the rule not to throw when applied multiple times

What did you see instead?

An exception unrelated to the test is being thrown

Steps to reproduce the bug

Create a small maven project with a flakey test class, and enable surefire retry feature (see the attached project)

grpc-test-case.zip

laurentgo added a commit to laurentgo/grpc-java that referenced this issue Feb 14, 2022
Fix an issue in GrpcCleanupRule when tests are retried and the
teardown() method is invoked multiple times, causing Stopwatch instance
to throw an IllegalStateException.

fixes grpc#8917.
@dapengzhang0
Copy link
Member

I've never expected the same Rule instance can be re-apply()'ed in general.

Do you have any reference to "surefire/failsafe maven plugins are configured to retry failing tests"? Do the plugins work for all other Rules and they reuse the same rule instance when re-test?

Are you using the rule as a static field of the test class, so that re-test failed?

@laurentgo
Copy link
Contributor Author

Yes, the rule is defined as a static field with the @ClassRule annotation. As for the surefire configuration, you can find it in the zip file I provided, or check the reference document at https://maven.apache.org/surefire/maven-surefire-plugin/examples/rerun-failing-tests.html

dapengzhang0 pushed a commit that referenced this issue Feb 15, 2022
Fix an issue in GrpcCleanupRule when tests are retried and the
teardown() method is invoked multiple times, causing Stopwatch instance
to throw an IllegalStateException.

fixes #8917.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants