Fix race conditions for tests
This commit is contained in:
parent
2c277864f1
commit
a95341d70f
|
@ -92,7 +92,7 @@ public class InterceptorUserDataMapDstu2Test {
|
||||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||||
|
|
||||||
ourLog.info(myMapCheckMethods.toString());
|
ourLog.info(myMapCheckMethods.toString());
|
||||||
assertThat(myMapCheckMethods, containsInAnyOrder("incomingRequestPostProcessed", "incomingRequestPreHandled", "preProcessOutgoingException", "handleException"));
|
assertThat(myMapCheckMethods, contains("incomingRequestPostProcessed", "incomingRequestPreHandled", "preProcessOutgoingException", "handleException"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -106,6 +106,12 @@ public class InterceptorUserDataMapDstu2Test {
|
||||||
HttpResponse status = ourClient.execute(httpGet);
|
HttpResponse status = ourClient.execute(httpGet);
|
||||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||||
|
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
if (!myMapCheckMethods.contains("processingCompletedNormally")) {
|
||||||
|
Thread.sleep(100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ourLog.info(myMapCheckMethods.toString());
|
ourLog.info(myMapCheckMethods.toString());
|
||||||
assertThat(myMapCheckMethods.toString(), myMapCheckMethods, contains("incomingRequestPostProcessed", "incomingRequestPreHandled", "outgoingResponse", "processingCompletedNormally"));
|
assertThat(myMapCheckMethods.toString(), myMapCheckMethods, contains("incomingRequestPostProcessed", "incomingRequestPreHandled", "outgoingResponse", "processingCompletedNormally"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,9 @@ import static org.hamcrest.Matchers.matchesPattern;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.assertThat;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.mockito.Mockito.after;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.timeout;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
|
@ -97,10 +99,8 @@ public class LoggingInterceptorDstu2Test {
|
||||||
HttpResponse status = ourClient.execute(httpGet);
|
HttpResponse status = ourClient.execute(httpGet);
|
||||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||||
|
|
||||||
avoidRaceCondition();
|
|
||||||
|
|
||||||
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
|
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
|
||||||
verify(logger, times(1)).info(captor.capture());
|
verify(logger, timeout(1000).times(1)).info(captor.capture());
|
||||||
assertThat(captor.getAllValues().get(0), StringContains.containsString("ERROR - GET http://localhost:" + ourPort + "/Patient/EX"));
|
assertThat(captor.getAllValues().get(0), StringContains.containsString("ERROR - GET http://localhost:" + ourPort + "/Patient/EX"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,10 +117,10 @@ public class LoggingInterceptorDstu2Test {
|
||||||
HttpResponse status = ourClient.execute(httpGet);
|
HttpResponse status = ourClient.execute(httpGet);
|
||||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||||
|
|
||||||
avoidRaceCondition();
|
|
||||||
|
|
||||||
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
|
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
|
||||||
verify(logger, times(1)).info(captor.capture());
|
verify(logger, timeout(1000).times(1)).info(captor.capture());
|
||||||
assertThat(captor.getValue(), StringContains.containsString("metadata - "));
|
assertThat(captor.getValue(), StringContains.containsString("metadata - "));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,18 +138,13 @@ public class LoggingInterceptorDstu2Test {
|
||||||
HttpResponse status = ourClient.execute(httpGet);
|
HttpResponse status = ourClient.execute(httpGet);
|
||||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||||
|
|
||||||
avoidRaceCondition();
|
|
||||||
|
|
||||||
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
|
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
|
||||||
verify(logger, times(1)).info(captor.capture());
|
verify(logger, timeout(1000).times(1)).info(captor.capture());
|
||||||
assertEquals("extended-operation-instance - $everything - Patient/123", captor.getValue());
|
assertEquals("extended-operation-instance - $everything - Patient/123", captor.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void avoidRaceCondition() throws InterruptedException {
|
|
||||||
// The server finishes the response and closes the connection, then runs the final interceptor so technically
|
|
||||||
// we could get here before the interceptor has fired
|
|
||||||
Thread.sleep(100);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRequestBodyRead() throws Exception {
|
public void testRequestBodyRead() throws Exception {
|
||||||
|
@ -167,7 +162,7 @@ public class LoggingInterceptorDstu2Test {
|
||||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||||
|
|
||||||
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
|
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
|
||||||
verify(logger, times(1)).info(captor.capture());
|
verify(logger, timeout(1000).times(1)).info(captor.capture());
|
||||||
assertEquals("read - - Patient/1 - ", captor.getValue());
|
assertEquals("read - - Patient/1 - ", captor.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,10 +182,10 @@ public class LoggingInterceptorDstu2Test {
|
||||||
HttpResponse status = ourClient.execute(httpGet);
|
HttpResponse status = ourClient.execute(httpGet);
|
||||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||||
|
|
||||||
avoidRaceCondition();
|
|
||||||
|
|
||||||
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
|
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
|
||||||
verify(logger, times(1)).info(captor.capture());
|
verify(logger, timeout(1000).times(1)).info(captor.capture());
|
||||||
assertThat(captor.getValue(), matchesPattern("[0-9]{3}"));
|
assertThat(captor.getValue(), matchesPattern("[0-9]{3}"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -211,7 +206,7 @@ public class LoggingInterceptorDstu2Test {
|
||||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||||
|
|
||||||
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
|
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
|
||||||
verify(logger, times(1)).info(captor.capture());
|
verify(logger, timeout(1000).times(1)).info(captor.capture());
|
||||||
assertEquals("read - - Patient/1 - ", captor.getValue());
|
assertEquals("read - - Patient/1 - ", captor.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,10 +230,10 @@ public class LoggingInterceptorDstu2Test {
|
||||||
HttpResponse status = ourClient.execute(httpPost);
|
HttpResponse status = ourClient.execute(httpPost);
|
||||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||||
|
|
||||||
avoidRaceCondition();
|
|
||||||
|
|
||||||
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
|
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
|
||||||
verify(logger, times(1)).info(captor.capture());
|
verify(logger, timeout(1000).times(1)).info(captor.capture());
|
||||||
assertEquals("create - - Patient - <Patient xmlns=\"http://hl7.org/fhir\"><identifier><value value=\"VAL\"/></identifier></Patient>", captor.getValue());
|
assertEquals("create - - Patient - <Patient xmlns=\"http://hl7.org/fhir\"><identifier><value value=\"VAL\"/></identifier></Patient>", captor.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -265,10 +260,10 @@ public class LoggingInterceptorDstu2Test {
|
||||||
HttpResponse status = ourClient.execute(httpPost);
|
HttpResponse status = ourClient.execute(httpPost);
|
||||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||||
|
|
||||||
avoidRaceCondition();
|
|
||||||
|
|
||||||
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
|
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
|
||||||
verify(logger, times(1)).info(captor.capture());
|
verify(logger, timeout(1000).times(1)).info(captor.capture());
|
||||||
assertEquals("ERROR - create - - Patient - <Patient xmlns=\"http://hl7.org/fhir\"><identifier><value value=\"VAL\"/></identifier></Patient>", captor.getValue());
|
assertEquals("ERROR - create - - Patient - <Patient xmlns=\"http://hl7.org/fhir\"><identifier><value value=\"VAL\"/></identifier></Patient>", captor.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -286,10 +281,10 @@ public class LoggingInterceptorDstu2Test {
|
||||||
HttpResponse status = ourClient.execute(httpGet);
|
HttpResponse status = ourClient.execute(httpGet);
|
||||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||||
|
|
||||||
avoidRaceCondition();
|
|
||||||
|
|
||||||
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
|
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
|
||||||
verify(logger, times(1)).info(captor.capture());
|
verify(logger, timeout(1000).times(1)).info(captor.capture());
|
||||||
assertEquals("extended-operation-server - $everything - ", captor.getValue());
|
assertEquals("extended-operation-server - $everything - ", captor.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -307,10 +302,10 @@ public class LoggingInterceptorDstu2Test {
|
||||||
HttpResponse status = ourClient.execute(httpGet);
|
HttpResponse status = ourClient.execute(httpGet);
|
||||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||||
|
|
||||||
avoidRaceCondition();
|
|
||||||
|
|
||||||
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
|
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
|
||||||
verify(logger, times(1)).info(captor.capture());
|
verify(logger, timeout(1000).times(1)).info(captor.capture());
|
||||||
assertEquals("extended-operation-type - $everything - Patient", captor.getValue());
|
assertEquals("extended-operation-type - $everything - Patient", captor.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -327,10 +322,10 @@ public class LoggingInterceptorDstu2Test {
|
||||||
HttpResponse status = ourClient.execute(httpGet);
|
HttpResponse status = ourClient.execute(httpGet);
|
||||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||||
|
|
||||||
avoidRaceCondition();
|
|
||||||
|
|
||||||
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
|
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
|
||||||
verify(logger, times(1)).info(captor.capture());
|
verify(logger, timeout(1000).times(1)).info(captor.capture());
|
||||||
assertThat(captor.getValue(), StringContains.containsString("read - Patient/1"));
|
assertThat(captor.getValue(), StringContains.containsString("read - Patient/1"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -348,10 +343,10 @@ public class LoggingInterceptorDstu2Test {
|
||||||
HttpResponse status = ourClient.execute(httpGet);
|
HttpResponse status = ourClient.execute(httpGet);
|
||||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||||
|
|
||||||
avoidRaceCondition();
|
|
||||||
|
|
||||||
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
|
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
|
||||||
verify(logger, times(1)).info(captor.capture());
|
verify(logger, timeout(1000).times(1)).info(captor.capture());
|
||||||
assertThat(captor.getValue(), StringContains.containsString("search-type - Patient - ?_id=1"));
|
assertThat(captor.getValue(), StringContains.containsString("search-type - Patient - ?_id=1"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue