Use reflection to inject the attempt number

This CL is to address the public static field in RepeatableRunner
for caller to get the current attempt number. We tried to have
a JUnit TestRule to achieve the purpose but it ended up with having
a RuleChain in each class where we already have multiple rules and
need to add the retry rule. This is because we have to make sure
the retry rule is the last one to wrap the test statement so that
the actual retry can include the actions defined in other rules.
Having a rule chain is not scalable and confuses engineer so we
gave it up.

Instead, we decided to expand the current RepeatableRunner to
use reflection to inject the attempt number to the test class.
Doing it this way can reduce the burden from the caller and it also
gets rid of the global state from the previous public static field.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=240789045
This commit is contained in:
shicong 2019-03-28 09:34:08 -07:00 committed by jianglai
parent 308d5eb76b
commit c8aa6005f2
9 changed files with 132 additions and 45 deletions

View file

@ -29,15 +29,15 @@ import google.registry.model.registrar.RegistrarContact;
import google.registry.module.frontend.FrontendServlet;
import google.registry.server.RegistryTestServer;
import google.registry.testing.AppEngineRule;
import google.registry.webdriver.RepeatableRunner.AttemptNumber;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.Timeout;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.openqa.selenium.By;
/** WebDriver tests for Registrar Console UI. */
@RunWith(JUnit4.class)
@RunWith(RepeatableRunner.class)
public class RegistrarConsoleWebTest {
@Rule
@ -59,7 +59,8 @@ public class RegistrarConsoleWebTest {
.setEmail("Marla.Singer@google.com")
.build();
@Rule public final WebDriverRule driver = new WebDriverRule();
private final AttemptNumber attemptNumber = new AttemptNumber();
@Rule public final WebDriverRule driver = new WebDriverRule(attemptNumber);
@Rule public final Timeout deathClock = new Timeout(60000);