mirror of
https://github.com/google/nomulus.git
synced 2025-06-27 14:54:51 +02:00
Restore original System Properties after tests
Many registry tools tests modify system properties but do not restore them to original state. These tests must be isolated from each other and cannot share the same test execution process. This has a huge impact on test performance under Gradle, which seems to have higher process startup overhead. Current Gradle test config has to set 'forEvery' to 1, i.e., every test class must be run in a freshly started process. This change significantly reduces the number of tests that need isolation, making it easier to optimize test config for the remaining tests. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=221350284
This commit is contained in:
parent
9fa2a84c35
commit
75add42a1b
11 changed files with 125 additions and 26 deletions
|
@ -32,6 +32,7 @@ import google.registry.model.poll.PollMessage;
|
|||
import google.registry.testing.AppEngineRule;
|
||||
import google.registry.testing.CertificateSamples;
|
||||
import google.registry.testing.MockitoJUnitRule;
|
||||
import google.registry.testing.SystemPropertyRule;
|
||||
import google.registry.tools.params.ParameterFactory;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
|
@ -61,6 +62,8 @@ public abstract class CommandTestCase<C extends Command> {
|
|||
public final AppEngineRule appEngine =
|
||||
AppEngineRule.builder().withDatastore().withTaskQueue().build();
|
||||
|
||||
@Rule public final SystemPropertyRule systemPropertyRule = new SystemPropertyRule();
|
||||
|
||||
@Rule public final MockitoJUnitRule mocks = MockitoJUnitRule.create();
|
||||
|
||||
@Rule
|
||||
|
@ -69,14 +72,14 @@ public abstract class CommandTestCase<C extends Command> {
|
|||
@Before
|
||||
public final void beforeCommandTestCase() {
|
||||
// Ensure the UNITTEST environment has been set before constructing a new command instance.
|
||||
RegistryToolEnvironment.UNITTEST.setup();
|
||||
RegistryToolEnvironment.UNITTEST.setup(systemPropertyRule);
|
||||
command = newCommandInstance();
|
||||
System.setOut(new PrintStream(stdout));
|
||||
System.setErr(new PrintStream(stderr));
|
||||
}
|
||||
|
||||
void runCommandInEnvironment(RegistryToolEnvironment env, String... args) throws Exception {
|
||||
env.setup();
|
||||
env.setup(systemPropertyRule);
|
||||
try {
|
||||
JCommander jcommander = new JCommander(command);
|
||||
jcommander.addConverterFactory(new ParameterFactory());
|
||||
|
@ -87,7 +90,7 @@ public abstract class CommandTestCase<C extends Command> {
|
|||
// This primarily matters for AutoTimestamp fields, which otherwise won't have updated values.
|
||||
ofy().clearSessionCache();
|
||||
// Reset back to UNITTEST environment.
|
||||
RegistryToolEnvironment.UNITTEST.setup();
|
||||
RegistryToolEnvironment.UNITTEST.setup(systemPropertyRule);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue