Restore global config after tests

Fix a couple more cases when caching related configs are changed.
This does not fix all our problems with Gradle builds.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=228735790
This commit is contained in:
weiminyu 2019-01-10 10:41:39 -08:00 committed by Ben McIlwain
parent 4866955c76
commit f94090c415
4 changed files with 50 additions and 24 deletions

View file

@ -391,9 +391,14 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
@Test @Test
public void testSuccess_cachingDisabled() throws Exception { public void testSuccess_cachingDisabled() throws Exception {
RegistryConfig.overrideIsEppResourceCachingEnabledForTesting(false); boolean origIsCachingEnabled = RegistryConfig.isEppResourceCachingEnabled();
persistContactsAndHosts(); try {
doSuccessfulTest(); RegistryConfig.overrideIsEppResourceCachingEnabledForTesting(false);
persistContactsAndHosts();
doSuccessfulTest();
} finally {
RegistryConfig.overrideIsEppResourceCachingEnabledForTesting(origIsCachingEnabled);
}
} }
@Test @Test

View file

@ -194,10 +194,15 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
@Test @Test
public void testSuccess_cachingDisabled() throws Exception { public void testSuccess_cachingDisabled() throws Exception {
RegistryConfig.overrideIsEppResourceCachingEnabledForTesting(false); boolean origIsCachingEnabled = RegistryConfig.isEppResourceCachingEnabled();
persistReferencedEntities(); try {
persistDomain(); RegistryConfig.overrideIsEppResourceCachingEnabledForTesting(false);
doSuccessfulTest(); persistReferencedEntities();
persistDomain();
doSuccessfulTest();
} finally {
RegistryConfig.overrideIsEppResourceCachingEnabledForTesting(origIsCachingEnabled);
}
} }
@Test @Test

View file

@ -14,6 +14,7 @@
package google.registry.model.registrar; package google.registry.model.registrar;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat; import static com.google.common.truth.Truth8.assertThat;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
@ -454,6 +455,11 @@ public class RegistrarTest extends EntityTestCase {
@Test @Test
public void testSuccess_setAllowedTldsUncached_newTldNotInCache() { public void testSuccess_setAllowedTldsUncached_newTldNotInCache() {
int origSingletonCacheRefreshSeconds =
RegistryConfig.CONFIG_SETTINGS.get().caching.singletonCacheRefreshSeconds;
// Sanity check for Gradle-based open-source build.
checkState(
origSingletonCacheRefreshSeconds == 0, "singletonCacheRefreshSeconds expected to be 0.");
try { try {
// Cache duration in tests is 0. To make sure the data isn't in the cache we have to set it // Cache duration in tests is 0. To make sure the data isn't in the cache we have to set it
// to a higher value and reset the cache. // to a higher value and reset the cache.
@ -490,8 +496,8 @@ public class RegistrarTest extends EntityTestCase {
// TLDs // TLDs
assertThat(Registries.getTlds()).doesNotContain("newtld"); assertThat(Registries.getTlds()).doesNotContain("newtld");
} finally { } finally {
// Set the cache duration back to 0 to satisfy other tests. RegistryConfig.CONFIG_SETTINGS.get().caching.singletonCacheRefreshSeconds =
RegistryConfig.CONFIG_SETTINGS.get().caching.singletonCacheRefreshSeconds = 0; origSingletonCacheRefreshSeconds;
Registries.resetCache(); Registries.resetCache();
} }
} }

View file

@ -49,27 +49,37 @@ public class RequestFactoryModuleTest {
@Test @Test
public void test_provideHttpRequestFactory_localhost() throws Exception { public void test_provideHttpRequestFactory_localhost() throws Exception {
// Make sure that localhost creates a request factory with an initializer. // Make sure that localhost creates a request factory with an initializer.
boolean origIsLocal = RegistryConfig.CONFIG_SETTINGS.get().appEngine.isLocal;
RegistryConfig.CONFIG_SETTINGS.get().appEngine.isLocal = true; RegistryConfig.CONFIG_SETTINGS.get().appEngine.isLocal = true;
HttpRequestFactory factory = RequestFactoryModule.provideHttpRequestFactory(googleCredential); try {
HttpRequestInitializer initializer = factory.getInitializer(); HttpRequestFactory factory = RequestFactoryModule.provideHttpRequestFactory(googleCredential);
assertThat(initializer).isNotNull(); HttpRequestInitializer initializer = factory.getInitializer();
HttpRequest request = factory.buildGetRequest(new GenericUrl("http://localhost")); assertThat(initializer).isNotNull();
initializer.initialize(request); HttpRequest request = factory.buildGetRequest(new GenericUrl("http://localhost"));
verifyZeroInteractions(googleCredential); initializer.initialize(request);
verifyZeroInteractions(googleCredential);
} finally {
RegistryConfig.CONFIG_SETTINGS.get().appEngine.isLocal = origIsLocal;
}
} }
@Test @Test
public void test_provideHttpRequestFactory_remote() throws Exception { public void test_provideHttpRequestFactory_remote() throws Exception {
// Make sure that example.com creates a request factory with the UNITTEST client id but no // Make sure that example.com creates a request factory with the UNITTEST client id but no
boolean origIsLocal = RegistryConfig.CONFIG_SETTINGS.get().appEngine.isLocal;
RegistryConfig.CONFIG_SETTINGS.get().appEngine.isLocal = false; RegistryConfig.CONFIG_SETTINGS.get().appEngine.isLocal = false;
HttpRequestFactory factory = RequestFactoryModule.provideHttpRequestFactory(googleCredential); try {
HttpRequestInitializer initializer = factory.getInitializer(); HttpRequestFactory factory = RequestFactoryModule.provideHttpRequestFactory(googleCredential);
assertThat(initializer).isNotNull(); HttpRequestInitializer initializer = factory.getInitializer();
// HttpRequestFactory#buildGetRequest() calls initialize() once. assertThat(initializer).isNotNull();
HttpRequest request = factory.buildGetRequest(new GenericUrl("http://localhost")); // HttpRequestFactory#buildGetRequest() calls initialize() once.
verify(googleCredential).initialize(request); HttpRequest request = factory.buildGetRequest(new GenericUrl("http://localhost"));
assertThat(request.getConnectTimeout()).isEqualTo(REQUEST_TIMEOUT_MS); verify(googleCredential).initialize(request);
assertThat(request.getReadTimeout()).isEqualTo(REQUEST_TIMEOUT_MS); assertThat(request.getConnectTimeout()).isEqualTo(REQUEST_TIMEOUT_MS);
verifyNoMoreInteractions(googleCredential); assertThat(request.getReadTimeout()).isEqualTo(REQUEST_TIMEOUT_MS);
verifyNoMoreInteractions(googleCredential);
} finally {
RegistryConfig.CONFIG_SETTINGS.get().appEngine.isLocal = origIsLocal;
}
} }
} }