Improve tests timing logic; properly wait for the right number of connections

This commit is contained in:
Gary Russell
2010-07-31 17:01:44 +00:00
parent 086bdf408f
commit ec21584793
2 changed files with 10 additions and 4 deletions

View File

@@ -844,8 +844,8 @@ public class TcpSendingMessageHandlerTests {
ccf.setInputConverter(converter);
ccf.setOutputConverter(converter);
ccf.setSoTimeout(10000);
ccf.start();
ccf.setSingleUse(true);
ccf.start();
TcpSendingMessageHandler handler = new TcpSendingMessageHandler();
handler.setConnectionFactory(ccf);
TcpReceivingChannelAdapter adapter = new TcpReceivingChannelAdapter();
@@ -856,10 +856,10 @@ public class TcpSendingMessageHandlerTests {
for (int i = 100; i < 200; i++) {
handler.handleMessage(MessageBuilder.withPayload("Test" + i).build());
}
assertTrue(semaphore.tryAcquire(10, 10000, TimeUnit.MILLISECONDS));
assertTrue(semaphore.tryAcquire(100, 20000, TimeUnit.MILLISECONDS));
Set<String> replies = new HashSet<String>();
for (int i = 100; i < 200; i++) {
Message<?> mOut = channel.receive(10000);
Message<?> mOut = channel.receive(20000);
assertNotNull(mOut);
replies.add(new String((byte[])mOut.getPayload()));
}

View File

@@ -99,7 +99,13 @@ public class TcpNioConnectionTests {
try {
TcpNioConnection connection = factory.getConnection();
connection.send(MessageBuilder.withPayload("Test").build());
Thread.sleep(2000);
int n = 0;
while (connection.isOpen()) {
Thread.sleep(100);
if (n++ > 200) {
break;
}
}
assertTrue(!connection.isOpen());
} catch (Exception e) {
fail("Unexptected exception " + e);