mirror of
https://github.com/google/nomulus.git
synced 2025-05-15 00:47:11 +02:00
Allow for a longer timeout in the nomulus tool
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=225440541
This commit is contained in:
parent
4491b7b909
commit
b27a49c1b4
2 changed files with 32 additions and 5 deletions
|
@ -30,6 +30,8 @@ import google.registry.config.RegistryConfig;
|
||||||
*/
|
*/
|
||||||
@Module
|
@Module
|
||||||
class RequestFactoryModule {
|
class RequestFactoryModule {
|
||||||
|
|
||||||
|
static final int REQUEST_TIMEOUT_MS = 10 * 60 * 1000;
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
static HttpRequestFactory provideHttpRequestFactory(
|
static HttpRequestFactory provideHttpRequestFactory(
|
||||||
|
@ -42,7 +44,17 @@ class RequestFactoryModule {
|
||||||
.getHeaders()
|
.getHeaders()
|
||||||
.setCookie("dev_appserver_login=test@example.com:true:1858047912411"));
|
.setCookie("dev_appserver_login=test@example.com:true:1858047912411"));
|
||||||
} else {
|
} else {
|
||||||
return new NetHttpTransport().createRequestFactory(credential);
|
return new NetHttpTransport()
|
||||||
|
.createRequestFactory(
|
||||||
|
request -> {
|
||||||
|
credential.initialize(request);
|
||||||
|
// GAE request times out after 10 min, so here we set the timeout to 10 min. This is
|
||||||
|
// needed to support some nomulus commands like updating premium lists that take
|
||||||
|
// a lot of time to complete.
|
||||||
|
// See https://developers.google.com/api-client-library/java/google-api-java-client/errors
|
||||||
|
request.setConnectTimeout(REQUEST_TIMEOUT_MS);
|
||||||
|
request.setReadTimeout(REQUEST_TIMEOUT_MS);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,9 +15,15 @@
|
||||||
package google.registry.tools;
|
package google.registry.tools;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
import static google.registry.tools.RequestFactoryModule.REQUEST_TIMEOUT_MS;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||||
|
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||||
|
|
||||||
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
|
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
|
||||||
|
import com.google.api.client.http.GenericUrl;
|
||||||
|
import com.google.api.client.http.HttpRequest;
|
||||||
import com.google.api.client.http.HttpRequestFactory;
|
import com.google.api.client.http.HttpRequestFactory;
|
||||||
import com.google.api.client.http.HttpRequestInitializer;
|
import com.google.api.client.http.HttpRequestInitializer;
|
||||||
import google.registry.config.RegistryConfig;
|
import google.registry.config.RegistryConfig;
|
||||||
|
@ -41,20 +47,29 @@ public class RequestFactoryModuleTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_provideHttpRequestFactory_localhost() {
|
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.
|
||||||
RegistryConfig.CONFIG_SETTINGS.get().appEngine.isLocal = true;
|
RegistryConfig.CONFIG_SETTINGS.get().appEngine.isLocal = true;
|
||||||
HttpRequestFactory factory = RequestFactoryModule.provideHttpRequestFactory(googleCredential);
|
HttpRequestFactory factory = RequestFactoryModule.provideHttpRequestFactory(googleCredential);
|
||||||
HttpRequestInitializer initializer = factory.getInitializer();
|
HttpRequestInitializer initializer = factory.getInitializer();
|
||||||
assertThat(initializer).isNotNull();
|
assertThat(initializer).isNotNull();
|
||||||
assertThat(initializer).isNotSameAs(googleCredential);
|
HttpRequest request = factory.buildGetRequest(new GenericUrl("http://localhost"));
|
||||||
|
initializer.initialize(request);
|
||||||
|
verifyZeroInteractions(googleCredential);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_provideHttpRequestFactory_remote() {
|
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
|
||||||
RegistryConfig.CONFIG_SETTINGS.get().appEngine.isLocal = false;
|
RegistryConfig.CONFIG_SETTINGS.get().appEngine.isLocal = false;
|
||||||
HttpRequestFactory factory = RequestFactoryModule.provideHttpRequestFactory(googleCredential);
|
HttpRequestFactory factory = RequestFactoryModule.provideHttpRequestFactory(googleCredential);
|
||||||
assertThat(factory.getInitializer()).isSameAs(googleCredential);
|
HttpRequestInitializer initializer = factory.getInitializer();
|
||||||
|
assertThat(initializer).isNotNull();
|
||||||
|
// HttpRequestFactory#buildGetRequest() calls initialize() once.
|
||||||
|
HttpRequest request = factory.buildGetRequest(new GenericUrl("http://localhost"));
|
||||||
|
verify(googleCredential).initialize(request);
|
||||||
|
assertThat(request.getConnectTimeout()).isEqualTo(REQUEST_TIMEOUT_MS);
|
||||||
|
assertThat(request.getReadTimeout()).isEqualTo(REQUEST_TIMEOUT_MS);
|
||||||
|
verifyNoMoreInteractions(googleCredential);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue