mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-01-31 23:32:16 +00:00
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:
parent
f7a944983c
commit
c61ec5023e
@ -117,9 +117,11 @@ public class TestWithNetworkConnections {
|
|||||||
peer.addEventListener(new AbstractPeerEventListener() {
|
peer.addEventListener(new AbstractPeerEventListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onPeerDisconnected(Peer p, int peerCount) {
|
public void onPeerDisconnected(Peer p, int peerCount) {
|
||||||
|
synchronized (doneConnecting) {
|
||||||
if (!doneConnecting.get())
|
if (!doneConnecting.get())
|
||||||
thisThread.interrupt();
|
thisThread.interrupt();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
if (clientType == ClientType.NIO_CLIENT_MANAGER || clientType == ClientType.BLOCKING_CLIENT_MANAGER)
|
if (clientType == ClientType.NIO_CLIENT_MANAGER || clientType == ClientType.BLOCKING_CLIENT_MANAGER)
|
||||||
channels.openConnection(new InetSocketAddress("127.0.0.1", 2000), peer);
|
channels.openConnection(new InetSocketAddress("127.0.0.1", 2000), peer);
|
||||||
@ -138,7 +140,10 @@ public class TestWithNetworkConnections {
|
|||||||
try {
|
try {
|
||||||
assertTrue(writeTarget.nextMessageBlocking() instanceof VersionMessage);
|
assertTrue(writeTarget.nextMessageBlocking() instanceof VersionMessage);
|
||||||
assertTrue(writeTarget.nextMessageBlocking() instanceof VersionAck);
|
assertTrue(writeTarget.nextMessageBlocking() instanceof VersionAck);
|
||||||
|
synchronized (doneConnecting) {
|
||||||
doneConnecting.set(true);
|
doneConnecting.set(true);
|
||||||
|
}
|
||||||
|
Thread.interrupted(); // Clear interrupted bit in case it was set before we got into the CS
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
// We were disconnected before we got back version/verack
|
// We were disconnected before we got back version/verack
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user