Fix race in TestWithNetworkConnections

There was a nasty bug where a connection-failed interrupt was
run afer any interruptible calls were made, making the next
test-case fail due to interruption.
This commit is contained in:
Matt Corallo 2013-12-14 23:22:51 -05:00 committed by Mike Hearn
parent f7a944983c
commit c61ec5023e

View File

@ -117,8 +117,10 @@ public class TestWithNetworkConnections {
peer.addEventListener(new AbstractPeerEventListener() {
@Override
public void onPeerDisconnected(Peer p, int peerCount) {
if (!doneConnecting.get())
thisThread.interrupt();
synchronized (doneConnecting) {
if (!doneConnecting.get())
thisThread.interrupt();
}
}
});
if (clientType == ClientType.NIO_CLIENT_MANAGER || clientType == ClientType.BLOCKING_CLIENT_MANAGER)
@ -138,7 +140,10 @@ public class TestWithNetworkConnections {
try {
assertTrue(writeTarget.nextMessageBlocking() instanceof VersionMessage);
assertTrue(writeTarget.nextMessageBlocking() instanceof VersionAck);
doneConnecting.set(true);
synchronized (doneConnecting) {
doneConnecting.set(true);
}
Thread.interrupted(); // Clear interrupted bit in case it was set before we got into the CS
} catch (InterruptedException e) {
// We were disconnected before we got back version/verack
}