Skip to content

Commit fca0638

Browse files
committed
[FAB-13298] Fix TestConfigureClusterListener in MacOS
Some people have port 5000 used in MacOS. When they try to run unit tests locally, the test TestConfigureClusterListener fails due to the port being already in use, which changes the actual error returned, and as a result - the test fails because the error string doesn't match what the test expects it to be. Fixed by selecting a random un-used port. Change-Id: I687ae38b8c0200e8fb899a519611b50e19cafe08 Signed-off-by: yacovm <yacovm@il.ibm.com>
1 parent cd6e7a2 commit fca0638

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

orderer/common/server/main_test.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package server
55

66
import (
7+
"fmt"
78
"io/ioutil"
89
"net"
910
"net/http"
@@ -380,6 +381,20 @@ func TestUpdateTrustedRoots(t *testing.T) {
380381
func TestConfigureClusterListener(t *testing.T) {
381382
logEntries := make(chan string, 100)
382383

384+
allocatePort := func() uint16 {
385+
l, err := net.Listen("tcp", "127.0.0.1:0")
386+
assert.NoError(t, err)
387+
_, portStr, err := net.SplitHostPort(l.Addr().String())
388+
assert.NoError(t, err)
389+
port, err := strconv.ParseInt(portStr, 10, 64)
390+
assert.NoError(t, err)
391+
assert.NoError(t, l.Close())
392+
t.Log("picked unused port", port)
393+
return uint16(port)
394+
}
395+
396+
unUsedPort := allocatePort()
397+
383398
backupLogger := logger
384399
logger = logger.With(zap.Hooks(func(entry zapcore.Entry) error {
385400
logEntries <- entry.Message
@@ -502,15 +517,15 @@ func TestConfigureClusterListener(t *testing.T) {
502517
General: localconfig.General{
503518
Cluster: localconfig.Cluster{
504519
ListenAddress: "99.99.99.99",
505-
ListenPort: 5000,
520+
ListenPort: unUsedPort,
506521
ServerPrivateKey: "key",
507522
ServerCertificate: "cert",
508523
RootCAs: []string{"ca"},
509524
},
510525
},
511526
},
512-
expectedPanic: "Failed creating gRPC server on 99.99.99.99:5000 due to " +
513-
"listen tcp 99.99.99.99:5000: bind: cannot assign requested address",
527+
expectedPanic: fmt.Sprintf("Failed creating gRPC server on 99.99.99.99:%d due "+
528+
"to listen tcp 99.99.99.99:%d: bind: cannot assign requested address", unUsedPort, unUsedPort),
514529
generalSrv: &comm.GRPCServer{},
515530
},
516531
{

0 commit comments

Comments
 (0)