mirror of
https://github.com/google/nomulus.git
synced 2025-05-14 00:17:20 +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
|
@ -17,10 +17,12 @@ package google.registry.tools;
|
|||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Ascii;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import google.registry.config.RegistryEnvironment;
|
||||
import google.registry.config.SystemPropertySetter;
|
||||
|
||||
/** Enum of production environments, used for the {@code --environment} flag. */
|
||||
enum RegistryToolEnvironment {
|
||||
|
@ -75,12 +77,24 @@ enum RegistryToolEnvironment {
|
|||
return instance;
|
||||
}
|
||||
|
||||
/** Setup execution environment. Call this method before any classes are loaded. */
|
||||
/** Resets static class state to uninitialized state. */
|
||||
@VisibleForTesting
|
||||
static void reset() {
|
||||
instance = null;
|
||||
}
|
||||
|
||||
/** Sets up execution environment. Call this method before any classes are loaded. */
|
||||
void setup() {
|
||||
setup(SystemPropertySetter.PRODUCTION_IMPL);
|
||||
}
|
||||
|
||||
/** Sets up execution environment. Call this method before any classes are loaded. */
|
||||
@VisibleForTesting
|
||||
void setup(SystemPropertySetter systemPropertySetter) {
|
||||
instance = this;
|
||||
System.setProperty(RegistryEnvironment.PROPERTY, actualEnvironment.name());
|
||||
actualEnvironment.setup(systemPropertySetter);
|
||||
for (ImmutableMap.Entry<String, String> entry : extraProperties.entrySet()) {
|
||||
System.setProperty(entry.getKey(), entry.getValue());
|
||||
systemPropertySetter.setProperty(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue