testing: fix GrpcCleanupRule issue when retrying tests (#8918)

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.
This commit is contained in:
Laurent Goujon 2022-02-15 12:52:24 -08:00 committed by GitHub
parent df6db6fe8b
commit bfb970ce03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 0 deletions

View File

@ -149,6 +149,7 @@ public final class GrpcCleanupRule implements TestRule {
return new Statement() { return new Statement() {
@Override @Override
public void evaluate() throws Throwable { public void evaluate() throws Throwable {
firstException = null;
try { try {
base.evaluate(); base.evaluate();
} catch (Throwable t) { } catch (Throwable t) {
@ -175,6 +176,7 @@ public final class GrpcCleanupRule implements TestRule {
* Releases all the registered resources. * Releases all the registered resources.
*/ */
private void teardown() { private void teardown() {
stopwatch.reset();
stopwatch.start(); stopwatch.start();
if (firstException == null) { if (firstException == null) {