Retry RDE report on SocketTimeoutException

It's likely that either 1) we should be doing this for more than a
SocketTimeoutException - we probably want to do this in the case of a number
of different transient failures 2) we don't want to do this at all because it
happens in a background task that will get re-run anyway.

In any case, this seems like the right fix and it addresses a problem we see
occassionally.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=139935190
This commit is contained in:
mmuller 2016-11-22 11:40:41 -08:00 committed by Ben McIlwain
parent b3907d5d90
commit ddacd33c5e
3 changed files with 40 additions and 11 deletions

View file

@ -52,11 +52,15 @@ import google.registry.request.HttpException.InternalServerErrorException;
import google.registry.testing.AppEngineRule;
import google.registry.testing.BouncyCastleProviderRule;
import google.registry.testing.ExceptionRule;
import google.registry.testing.FakeClock;
import google.registry.testing.FakeResponse;
import google.registry.testing.FakeSleeper;
import google.registry.util.Retrier;
import google.registry.xjc.XjcXmlTransformer;
import google.registry.xjc.rdereport.XjcRdeReportReport;
import google.registry.xml.XmlException;
import java.io.ByteArrayInputStream;
import java.net.SocketTimeoutException;
import java.util.Map;
import org.bouncycastle.openpgp.PGPPublicKey;
import org.joda.time.DateTime;
@ -103,6 +107,7 @@ public class RdeReportActionTest {
reporter.reportUrlPrefix = "https://rde-report.example";
reporter.urlFetchService = urlFetchService;
reporter.password = "foo";
reporter.retrier = new Retrier(new FakeSleeper(new FakeClock()), 3);
RdeReportAction action = new RdeReportAction();
action.gcsUtils = new GcsUtils(gcsService, 1024);
action.ghostryde = new Ghostryde(1024);
@ -185,6 +190,19 @@ public class RdeReportActionTest {
createAction().runWithLock(loadRdeReportCursor());
}
@Test
public void testRunWithLock_socketTimeout_doesRetry() throws Exception {
when(httpResponse.getResponseCode()).thenReturn(SC_OK);
when(httpResponse.getContent()).thenReturn(IIRDEA_GOOD_XML.read());
when(urlFetchService.fetch(request.capture()))
.thenThrow(new SocketTimeoutException())
.thenReturn(httpResponse);
createAction().runWithLock(loadRdeReportCursor());
assertThat(response.getStatus()).isEqualTo(200);
assertThat(response.getContentType()).isEqualTo(PLAIN_TEXT_UTF_8);
assertThat(response.getPayload()).isEqualTo("OK test 2006-06-06T00:00:00.000Z\n");
}
private DateTime loadRdeReportCursor() {
return ofy()
.load()