Skip to content

Commit a0c3b95

Browse files
committed
[FAB-3941] Fix UT failure of port collision
This commit fixes the following possible failure: panic: listen tcp 127.0.0.1:7050: bind: address already in use [recovered] panic: listen tcp 127.0.0.1:7050: bind: address already in use goroutine 167 [running]: panic(0x95a0c0, 0xc4203993b0) /opt/go/src/runtime/panic.go:500 +0x1a1 testing.tRunner.func1(0xc420097200) /opt/go/src/testing/testing.go:579 +0x25d panic(0x95a0c0, 0xc4203993b0) /opt/go/src/runtime/panic.go:458 +0x243 github.com/hyperledger/fabric/peer/channel.newOrderer /opt/gopath/src/github.com/hyperledger/fabric/peer/channel/create_test.go:53 github.com/hyperledger/fabric/peer/channel.TestCreateChainWithTimeoutErr /opt/gopath/src/github.com/hyperledger/fabric/peer/channel/create_test.go:258 testing.tRunner(0xc420097200, 0xa3cf48) /opt/go/src/testing/testing.go:610 +0x81 created by testing.(*T).Run /opt/go/src/testing/testing.go:646 +0x2ec FAIL github.com/hyperledger/fabric/peer/channel 3.168s error: exit status 1 panic: EOF I think this happens because the client doesn't close the connection and the server port remains in TIME_WAIT and since we have 2 tests that bind to the same port, the one that runs the 2nd time - fails. The easiest way to solve this is simply by changing the port numbers that are used in the test, but I simply added a connection close to the getGenesisBlock method. Change-Id: Ia08c3d8d10a8e01cf96ea2789b4d236921b850b5 Signed-off-by: Yacov Manevich <[email protected]>
1 parent fa98b46 commit a0c3b95

File tree

2 files changed

+2
-6
lines changed

2 files changed

+2
-6
lines changed

peer/channel/create_test.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package channel
1818

1919
import (
20+
"errors"
2021
"fmt"
2122
"io/ioutil"
2223
"net"
@@ -26,9 +27,6 @@ import (
2627
"testing"
2728

2829
"github.com/golang/protobuf/proto"
29-
30-
"errors"
31-
3230
"github.com/hyperledger/fabric/msp/mgmt/testtools"
3331
"github.com/hyperledger/fabric/peer/common"
3432
cb "github.com/hyperledger/fabric/protos/common"
@@ -43,7 +41,6 @@ type timeoutOrderer struct {
4341
nextExpectedSeek uint64
4442
t *testing.T
4543
blockChannel chan uint64
46-
stopChan chan struct{}
4744
}
4845

4946
func newOrderer(port int, t *testing.T) *timeoutOrderer {
@@ -58,15 +55,13 @@ func newOrderer(port int, t *testing.T) *timeoutOrderer {
5855
t: t,
5956
nextExpectedSeek: uint64(1),
6057
blockChannel: make(chan uint64, 1),
61-
stopChan: make(chan struct{}, 1),
6258
counter: int(1),
6359
}
6460
orderer.RegisterAtomicBroadcastServer(srv, o)
6561
return o
6662
}
6763

6864
func (o *timeoutOrderer) Shutdown() {
69-
o.stopChan <- struct{}{}
7065
o.Server.Stop()
7166
o.Listener.Close()
7267
}

peer/channel/deliverclient.go

+1
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ func getGenesisBlock(cf *ChannelCmdFactory) (*common.Block, error) {
121121
}
122122
time.Sleep(200 * time.Millisecond)
123123
} else {
124+
cf.DeliverClient.Close()
124125
return block, nil
125126
}
126127
}

0 commit comments

Comments
 (0)