mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-07 06:44:16 +00:00
Fixes issue 587: disables connecting to local bitcoin node during tests
This commit is contained in:
parent
57fc280ede
commit
c11c4d126d
@ -80,6 +80,7 @@ public class TestWithPeerGroup extends TestWithNetworkConnections {
|
||||
peerGroup = new PeerGroup(unitTestParams, blockChain, new BlockingClientManager());
|
||||
peerGroup.setPingIntervalMsec(0); // Disable the pings as they just get in the way of most tests.
|
||||
peerGroup.addWallet(wallet);
|
||||
peerGroup.setUseLocalhostPeerWhenPossible(false); // Prevents from connecting to bitcoin nodes on localhost.
|
||||
}
|
||||
|
||||
protected InboundMessageQueuer connectPeerWithoutVersionExchange(int id) throws Exception {
|
||||
|
@ -141,6 +141,8 @@ public class FilteredBlockAndPartialMerkleTreeTests extends TestWithPeerGroup {
|
||||
super.setUp(blockStore);
|
||||
|
||||
peerGroup.addWallet(wallet);
|
||||
peerGroup.setUseLocalhostPeerWhenPossible(false); // Prevents from connecting to bitcoin nodes on localhost.
|
||||
|
||||
blockChain.addWallet(wallet);
|
||||
|
||||
peerGroup.startAsync();
|
||||
|
@ -36,6 +36,7 @@ import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.BindException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.ServerSocket;
|
||||
import java.util.*;
|
||||
@ -720,9 +721,24 @@ public class PeerGroupTest extends TestWithPeerGroup {
|
||||
|
||||
@Test
|
||||
public void preferLocalPeer() throws IOException {
|
||||
// Check that if we have a localhost port 8333 then it's used instead of the p2p network.
|
||||
ServerSocket local = new ServerSocket(params.getPort(), 100, InetAddresses.forString("127.0.0.1"));
|
||||
// Because we are using the same port (8333 or 18333) that is used by Satoshi client
|
||||
// We have to consider 2 cases:
|
||||
// 1. Test are executed on the same machine that is running full node / Satoshi client
|
||||
// 2. Test are executed without any full node running locally
|
||||
// We have to avoid to connecting to real and external services in unit tests
|
||||
// So we skip this test in case we have already something running on port params.getPort()
|
||||
|
||||
// Check that if we have a localhost port 8333 or 18333 then it's used instead of the p2p network.
|
||||
ServerSocket local = null;
|
||||
try {
|
||||
local = new ServerSocket(params.getPort(), 100, InetAddresses.forString("127.0.0.1"));
|
||||
}
|
||||
catch(BindException e) { // Port already in use, skipping this test.
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
peerGroup.setUseLocalhostPeerWhenPossible(true);
|
||||
peerGroup.startAsync();
|
||||
peerGroup.awaitRunning();
|
||||
local.accept().close(); // Probe connect
|
||||
|
Loading…
Reference in New Issue
Block a user