[TEST] make testTimeoutSendExceptionWithDelayedResponse more reliable on slow systems

This commit is contained in:
Simon Willnauer 2014-04-16 22:59:31 +02:00
parent 1755ae7470
commit 0948260ada
1 changed files with 5 additions and 6 deletions

View File

@ -441,7 +441,6 @@ public abstract class AbstractSimpleTransportTests extends ElasticsearchTestCase
} }
@Test @Test
@TestLogging("_root:TRACE")
public void testTimeoutSendExceptionWithDelayedResponse() throws Exception { public void testTimeoutSendExceptionWithDelayedResponse() throws Exception {
serviceA.registerHandler("sayHelloTimeoutDelayedResponse", new BaseTransportRequestHandler<StringMessageRequest>() { serviceA.registerHandler("sayHelloTimeoutDelayedResponse", new BaseTransportRequestHandler<StringMessageRequest>() {
@Override @Override
@ -470,7 +469,7 @@ public abstract class AbstractSimpleTransportTests extends ElasticsearchTestCase
} }
} }
}); });
final CountDownLatch latch = new CountDownLatch(1);
TransportFuture<StringMessageResponse> res = serviceB.submitRequest(nodeA, "sayHelloTimeoutDelayedResponse", TransportFuture<StringMessageResponse> res = serviceB.submitRequest(nodeA, "sayHelloTimeoutDelayedResponse",
new StringMessageRequest("300ms"), options().withTimeout(100), new BaseTransportResponseHandler<StringMessageResponse>() { new StringMessageRequest("300ms"), options().withTimeout(100), new BaseTransportResponseHandler<StringMessageResponse>() {
@Override @Override
@ -485,11 +484,13 @@ public abstract class AbstractSimpleTransportTests extends ElasticsearchTestCase
@Override @Override
public void handleResponse(StringMessageResponse response) { public void handleResponse(StringMessageResponse response) {
latch.countDown();
assertThat("got response instead of exception", false, equalTo(true)); assertThat("got response instead of exception", false, equalTo(true));
} }
@Override @Override
public void handleException(TransportException exp) { public void handleException(TransportException exp) {
latch.countDown();
assertThat(exp, instanceOf(ReceiveTimeoutTransportException.class)); assertThat(exp, instanceOf(ReceiveTimeoutTransportException.class));
} }
}); });
@ -500,15 +501,13 @@ public abstract class AbstractSimpleTransportTests extends ElasticsearchTestCase
} catch (Exception e) { } catch (Exception e) {
assertThat(e, instanceOf(ReceiveTimeoutTransportException.class)); assertThat(e, instanceOf(ReceiveTimeoutTransportException.class));
} }
latch.await();
// sleep for 400 millis to make sure we get back the response
Thread.sleep(400);
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
final int counter = i; final int counter = i;
// now, try and send another request, this times, with a short timeout // now, try and send another request, this times, with a short timeout
res = serviceB.submitRequest(nodeA, "sayHelloTimeoutDelayedResponse", res = serviceB.submitRequest(nodeA, "sayHelloTimeoutDelayedResponse",
new StringMessageRequest(counter + "ms"), options().withTimeout(100), new BaseTransportResponseHandler<StringMessageResponse>() { new StringMessageRequest(counter + "ms"), options().withTimeout(300), new BaseTransportResponseHandler<StringMessageResponse>() {
@Override @Override
public StringMessageResponse newInstance() { public StringMessageResponse newInstance() {
return new StringMessageResponse(); return new StringMessageResponse();