mirror of
https://github.com/google/nomulus
synced 2026-08-28 03:46:30 +00: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:
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user