Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Commit

Permalink
[MINOR] no fixed ports in tests (#340)
Browse files Browse the repository at this point in the history
* [MINOR] no fixed ports in tests

First enable "0" port in PeerDiscoveryAgent so it binds to
an open port.  Then change the test to use two PeerDiscoveryAgents

The change to zero is accomplished by populating the endpoint with
the actual bound socket instead of the value passed in.  If it is
zero the value will change otherwise it will be the value passed in.
  • Loading branch information
shemnon authored Dec 1, 2018
1 parent 64d80a5 commit d2dcb46
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public CompletableFuture<?> start(final int tcpPort) {
completion.completeExceptionally(cause);
return;
}
initialize(res.result(), tcpPort);
initialize(res.result(), res.result().localAddress().port());
this.isActive = true;
completion.complete(null);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
import static tech.pegasys.pantheon.util.bytes.BytesValue.fromHexString;

import tech.pegasys.pantheon.crypto.SECP256K1;
import tech.pegasys.pantheon.ethereum.p2p.api.MessageData;
Expand Down Expand Up @@ -130,29 +129,37 @@ public void neighborsPacketLimited() {
@Test
public void shouldEvictPeerOnDisconnect() {
final Vertx vertx = Vertx.vertx();
final SECP256K1.KeyPair keyPair = SECP256K1.KeyPair.generate();
final BytesValue id =
fromHexString(
"c7849b663d12a2b5bf05b1ebf5810364f4870d5f1053fbd7500d38bc54c705b453d7511ca8a4a86003d34d4c8ee0bbfcd387aa724f5b240b3ab4bbb994a1e09b");

final DefaultPeer peer = new DiscoveryPeer(id, "127.0.0.1", 30303);
final PeerDiscoveryAgent peerDiscoveryAgent =
final SECP256K1.KeyPair keyPair1 = SECP256K1.KeyPair.generate();
final PeerDiscoveryAgent peerDiscoveryAgent1 =
new PeerDiscoveryAgent(
vertx,
keyPair,
keyPair1,
DiscoveryConfiguration.create().setBindHost("127.0.0.1").setBindPort(0),
() -> true,
new PeerBlacklist());
peerDiscoveryAgent1.start(0).join();
final DefaultPeer peer = peerDiscoveryAgent1.getAdvertisedPeer();

final SECP256K1.KeyPair keyPair2 = SECP256K1.KeyPair.generate();
final PeerDiscoveryAgent peerDiscoveryAgent2 =
new PeerDiscoveryAgent(
vertx,
keyPair2,
DiscoveryConfiguration.create()
.setBindHost("127.0.0.1")
.setBindPort(0)
.setBootstrapPeers(Lists.newArrayList(peer)),
() -> true,
new PeerBlacklist());
peerDiscoveryAgent.start(30303).join();
peerDiscoveryAgent2.start(0).join();

assertThat(peerDiscoveryAgent.getPeers().size()).isEqualTo(1);
assertThat(peerDiscoveryAgent2.getPeers().size()).isEqualTo(1);

final PeerConnection peerConnection = createAnonymousPeerConnection(id);
peerDiscoveryAgent.onDisconnect(peerConnection, DisconnectReason.REQUESTED, true);
final PeerConnection peerConnection = createAnonymousPeerConnection(peer.getId());
peerDiscoveryAgent2.onDisconnect(peerConnection, DisconnectReason.REQUESTED, true);

assertThat(peerDiscoveryAgent.getPeers().size()).isEqualTo(0);
assertThat(peerDiscoveryAgent2.getPeers().size()).isEqualTo(0);
}

@Test
Expand Down

0 comments on commit d2dcb46

Please sign in to comment.