Skip to content

Commit

Permalink
[FAB-9100] fix ports to allow parallel unit-tests
Browse files Browse the repository at this point in the history
Change-Id: Ifeb2e5b8350af506411b23d42e891d6f91478989
Signed-off-by: nirro <[email protected]>
  • Loading branch information
nirrozenbaum committed Apr 15, 2018
1 parent fbe0d88 commit 2eab5b0
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 80 deletions.
52 changes: 26 additions & 26 deletions gossip/comm/comm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,8 @@ func TestHandshake(t *testing.T) {

func TestBasic(t *testing.T) {
t.Parallel()
comm1, _ := newCommInstance(52000, naiveSec)
comm2, _ := newCommInstance(53000, naiveSec)
comm1, _ := newCommInstance(2000, naiveSec)
comm2, _ := newCommInstance(3000, naiveSec)
comm1.(*commImpl).SetDialOpts()
comm2.(*commImpl).SetDialOpts()
defer comm1.Stop()
Expand All @@ -346,25 +346,25 @@ func TestBasic(t *testing.T) {
}
go reader(m1)
go reader(m2)
comm1.Send(createGossipMsg(), remotePeer(53000))
comm1.Send(createGossipMsg(), remotePeer(3000))
time.Sleep(time.Second)
comm2.Send(createGossipMsg(), remotePeer(52000))
comm2.Send(createGossipMsg(), remotePeer(2000))
waitForMessages(t, out, 2, "Didn't receive 2 messages")
}

func TestProdConstructor(t *testing.T) {
t.Parallel()
srv, lsnr, dialOpts, certs := createGRPCLayer(29000)
srv, lsnr, dialOpts, certs := createGRPCLayer(20000)
defer srv.Stop()
defer lsnr.Close()
id := []byte("localhost:29000")
id := []byte("localhost:20000")
comm1, _ := NewCommInstance(srv, certs, identity.NewIdentityMapper(naiveSec, id, noopPurgeIdentity, naiveSec), id, dialOpts)
go srv.Serve(lsnr)

srv, lsnr, dialOpts, certs = createGRPCLayer(39000)
srv, lsnr, dialOpts, certs = createGRPCLayer(30000)
defer srv.Stop()
defer lsnr.Close()
id = []byte("localhost:39000")
id = []byte("localhost:30000")
comm2, _ := NewCommInstance(srv, certs, identity.NewIdentityMapper(naiveSec, id, noopPurgeIdentity, naiveSec), id, dialOpts)
go srv.Serve(lsnr)
defer comm1.Stop()
Expand All @@ -378,9 +378,9 @@ func TestProdConstructor(t *testing.T) {
}
go reader(m1)
go reader(m2)
comm1.Send(createGossipMsg(), remotePeer(39000))
comm1.Send(createGossipMsg(), remotePeer(30000))
time.Sleep(time.Second)
comm2.Send(createGossipMsg(), remotePeer(29000))
comm2.Send(createGossipMsg(), remotePeer(20000))
waitForMessages(t, out, 2, "Didn't receive 2 messages")
}

Expand Down Expand Up @@ -549,8 +549,8 @@ func TestNonResponsivePing(t *testing.T) {

func TestResponses(t *testing.T) {
t.Parallel()
comm1, _ := newCommInstance(58611, naiveSec)
comm2, _ := newCommInstance(58612, naiveSec)
comm1, _ := newCommInstance(8611, naiveSec)
comm2, _ := newCommInstance(8612, naiveSec)

defer comm1.Stop()
defer comm2.Stop()
Expand All @@ -573,7 +573,7 @@ func TestResponses(t *testing.T) {

ticker := time.NewTicker(10 * time.Second)
wg.Wait()
comm2.Send(msg, remotePeer(58611))
comm2.Send(msg, remotePeer(8611))

select {
case <-ticker.C:
Expand All @@ -588,8 +588,8 @@ func TestResponses(t *testing.T) {

func TestAccept(t *testing.T) {
t.Parallel()
comm1, _ := newCommInstance(57611, naiveSec)
comm2, _ := newCommInstance(57612, naiveSec)
comm1, _ := newCommInstance(7611, naiveSec)
comm2, _ := newCommInstance(7612, naiveSec)

evenNONCESelector := func(m interface{}) bool {
return m.(proto.ReceivedMessage).GetGossipMessage().Nonce%2 == 0
Expand Down Expand Up @@ -620,7 +620,7 @@ func TestAccept(t *testing.T) {
go readIntoSlice(&oddResults, oddNONCES)

for i := 0; i < util.GetIntOrDefault("peer.gossip.recvBuffSize", defRecvBuffSize); i++ {
comm2.Send(createGossipMsg(), remotePeer(57611))
comm2.Send(createGossipMsg(), remotePeer(7611))
}

waitForMessages(t, out, util.GetIntOrDefault("peer.gossip.recvBuffSize", defRecvBuffSize), "Didn't receive all messages sent")
Expand All @@ -646,8 +646,8 @@ func TestAccept(t *testing.T) {

func TestReConnections(t *testing.T) {
t.Parallel()
comm1, _ := newCommInstance(43611, naiveSec)
comm2, _ := newCommInstance(43612, naiveSec)
comm1, _ := newCommInstance(3611, naiveSec)
comm2, _ := newCommInstance(3612, naiveSec)

reader := func(out chan uint64, in <-chan proto.ReceivedMessage) {
for {
Expand All @@ -666,19 +666,19 @@ func TestReConnections(t *testing.T) {
go reader(out2, comm2.Accept(acceptAll))

// comm1 connects to comm2
comm1.Send(createGossipMsg(), remotePeer(43612))
comm1.Send(createGossipMsg(), remotePeer(3612))
waitForMessages(t, out2, 1, "Comm2 didn't receive a message from comm1 in a timely manner")
time.Sleep(time.Second)
// comm2 sends to comm1
comm2.Send(createGossipMsg(), remotePeer(43611))
comm2.Send(createGossipMsg(), remotePeer(3611))
waitForMessages(t, out1, 1, "Comm1 didn't receive a message from comm2 in a timely manner")

comm1.Stop()
comm1, _ = newCommInstance(43611, naiveSec)
comm1, _ = newCommInstance(3611, naiveSec)
time.Sleep(time.Second)
out1 = make(chan uint64, 1)
go reader(out1, comm1.Accept(acceptAll))
comm2.Send(createGossipMsg(), remotePeer(43611))
comm2.Send(createGossipMsg(), remotePeer(3611))
waitForMessages(t, out1, 1, "Comm1 didn't receive a message from comm2 in a timely manner")
}

Expand Down Expand Up @@ -725,14 +725,14 @@ func TestProbe(t *testing.T) {

func TestPresumedDead(t *testing.T) {
t.Parallel()
comm1, _ := newCommInstance(44611, naiveSec)
comm2, _ := newCommInstance(44612, naiveSec)
comm1, _ := newCommInstance(4611, naiveSec)
comm2, _ := newCommInstance(4612, naiveSec)

wg := sync.WaitGroup{}
wg.Add(1)
go func() {
wg.Wait()
comm1.Send(createGossipMsg(), remotePeer(44612))
comm1.Send(createGossipMsg(), remotePeer(4612))
}()

ticker := time.NewTicker(time.Duration(10) * time.Second)
Expand All @@ -748,7 +748,7 @@ func TestPresumedDead(t *testing.T) {
comm2.Stop()
go func() {
for i := 0; i < 5; i++ {
comm1.Send(createGossipMsg(), remotePeer(44612))
comm1.Send(createGossipMsg(), remotePeer(4612))
time.Sleep(time.Millisecond * 200)
}
}()
Expand Down
4 changes: 2 additions & 2 deletions gossip/comm/crypto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func createTestServer(t *testing.T, cert *tls.Certificate) *gossipTestServer {
InsecureSkipVerify: true,
}
s := grpc.NewServer(grpc.Creds(credentials.NewTLS(tlsConf)))
ll, err := net.Listen("tcp", fmt.Sprintf("%s:%d", "", 2030))
ll, err := net.Listen("tcp", fmt.Sprintf("%s:%d", "", 5611))
assert.NoError(t, err, "%v", err)

srv := &gossipTestServer{s: s, ll: ll, selfCertHash: certHashFromRawCert(cert.Certificate[0])}
Expand Down Expand Up @@ -85,7 +85,7 @@ func TestCertificateExtraction(t *testing.T) {
})
ctx := context.Background()
ctx, _ = context.WithTimeout(ctx, time.Second)
conn, err := grpc.DialContext(ctx, "localhost:2030", grpc.WithTransportCredentials(ta), grpc.WithBlock())
conn, err := grpc.DialContext(ctx, "localhost:5611", grpc.WithTransportCredentials(ta), grpc.WithBlock())
assert.NoError(t, err, "%v", err)

cl := proto.NewGossipClient(conn)
Expand Down
20 changes: 10 additions & 10 deletions gossip/discovery/discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ func TestConnect(t *testing.T) {
instances := []*gossipInstance{}
firstSentMemReqMsgs := make(chan *proto.SignedGossipMessage, nodeNum)
for i := 0; i < nodeNum; i++ {
inst := createDiscoveryInstance(17611+i, fmt.Sprintf("d%d", i), []string{})
inst := createDiscoveryInstance(7611+i, fmt.Sprintf("d%d", i), []string{})

inst.comm.lock.Lock()
inst.comm.mock = &mock.Mock{}
Expand All @@ -447,7 +447,7 @@ func TestConnect(t *testing.T) {

instances = append(instances, inst)
j := (i + 1) % 10
endpoint := fmt.Sprintf("localhost:%d", 17611+j)
endpoint := fmt.Sprintf("localhost:%d", 7611+j)
netMember2Connect2 := NetworkMember{Endpoint: endpoint, PKIid: []byte(endpoint)}
inst.Connect(netMember2Connect2, func() (identification *PeerIdentification, err error) {
return &PeerIdentification{SelfOrg: false, ID: nil}, nil
Expand Down Expand Up @@ -479,18 +479,18 @@ func TestConnect(t *testing.T) {
func TestUpdate(t *testing.T) {
t.Parallel()
nodeNum := 5
bootPeers := []string{bootPeer(16611), bootPeer(16612)}
bootPeers := []string{bootPeer(6611), bootPeer(6612)}
instances := []*gossipInstance{}

inst := createDiscoveryInstance(16611, "d1", bootPeers)
inst := createDiscoveryInstance(6611, "d1", bootPeers)
instances = append(instances, inst)

inst = createDiscoveryInstance(16612, "d2", bootPeers)
inst = createDiscoveryInstance(6612, "d2", bootPeers)
instances = append(instances, inst)

for i := 3; i <= nodeNum; i++ {
id := fmt.Sprintf("d%d", i)
inst = createDiscoveryInstance(16610+i, id, bootPeers)
inst = createDiscoveryInstance(6610+i, id, bootPeers)
instances = append(instances, inst)
}

Expand All @@ -501,7 +501,7 @@ func TestUpdate(t *testing.T) {
waitUntilOrFail(t, fullMembership)

instances[0].UpdateMetadata([]byte("bla bla"))
instances[nodeNum-1].UpdateEndpoint("localhost:15511")
instances[nodeNum-1].UpdateEndpoint("localhost:5511")

checkMembership := func() bool {
for _, member := range instances[nodeNum-1].GetMembership() {
Expand All @@ -514,7 +514,7 @@ func TestUpdate(t *testing.T) {

for _, member := range instances[0].GetMembership() {
if string(member.PKIid) == instances[nodeNum-1].comm.id {
if "localhost:15511" != string(member.Endpoint) {
if "localhost:5511" != string(member.Endpoint) {
return false
}
}
Expand Down Expand Up @@ -652,14 +652,14 @@ func TestGetFullMembership(t *testing.T) {

func TestGossipDiscoveryStopping(t *testing.T) {
t.Parallel()
inst := createDiscoveryInstance(19611, "d1", []string{bootPeer(19611)})
inst := createDiscoveryInstance(9611, "d1", []string{bootPeer(9611)})
time.Sleep(time.Second)
waitUntilOrFailBlocking(t, inst.Stop)
}

func TestGossipDiscoverySkipConnectingToLocalhostBootstrap(t *testing.T) {
t.Parallel()
inst := createDiscoveryInstance(11711, "d1", []string{"localhost:11711", "127.0.0.1:11711"})
inst := createDiscoveryInstance(11611, "d1", []string{"localhost:11611", "127.0.0.1:11611"})
inst.comm.lock.Lock()
inst.comm.mock = &mock.Mock{}
inst.comm.mock.On("SendToPeer", mock.Anything, mock.Anything).Run(func(mock.Arguments) {
Expand Down
Loading

0 comments on commit 2eab5b0

Please sign in to comment.