Skip to content

Commit e205701

Browse files
authored
Merge pull request moby#49938 from corhere/libn/fix-networkdb-loopback-tests
libnetwork/networkdb: fix most flaky loopback tests
2 parents 49a0770 + 697c17c commit e205701

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

libnetwork/networkdb/cluster.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ func (nDB *NetworkDB) clusterInit() error {
112112

113113
if nDB.config.BindPort != 0 {
114114
config.BindPort = nDB.config.BindPort
115+
config.AdvertisePort = nDB.config.BindPort
115116
}
116117

117118
config.ProtocolVersion = memberlist.ProtocolVersion2Compatible

libnetwork/networkdb/networkdb_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@ func createNetworkDBInstances(t *testing.T, num int, namePrefix string, conf *Co
4646
localConfig.Hostname = fmt.Sprintf("%s%d", namePrefix, i+1)
4747
localConfig.NodeID = stringid.TruncateID(stringid.GenerateRandomID())
4848
localConfig.BindPort = int(dbPort.Add(1))
49+
localConfig.BindAddr = "127.0.0.1"
50+
localConfig.AdvertiseAddr = localConfig.BindAddr
4951
db := launchNode(t, localConfig)
5052
if i != 0 {
51-
assert.Check(t, db.Join([]string{fmt.Sprintf("localhost:%d", db.config.BindPort-1)}))
53+
assert.Check(t, db.Join([]string{net.JoinHostPort(db.config.AdvertiseAddr, strconv.Itoa(db.config.BindPort-1))}))
5254
}
5355

5456
dbs = append(dbs, db)
@@ -244,7 +246,7 @@ func TestNetworkDBJoinLeaveNetworks(t *testing.T) {
244246
closeNetworkDBInstances(t, dbs)
245247
}
246248

247-
func TestFlakyNetworkDBCRUDTableEntry(t *testing.T) {
249+
func TestNetworkDBCRUDTableEntry(t *testing.T) {
248250
dbs := createNetworkDBInstances(t, 3, "node", DefaultConfig())
249251

250252
err := dbs[0].JoinNetwork("network1")
@@ -274,7 +276,7 @@ func TestFlakyNetworkDBCRUDTableEntry(t *testing.T) {
274276
closeNetworkDBInstances(t, dbs)
275277
}
276278

277-
func TestFlakyNetworkDBCRUDTableEntries(t *testing.T) {
279+
func TestNetworkDBCRUDTableEntries(t *testing.T) {
278280
dbs := createNetworkDBInstances(t, 2, "node", DefaultConfig())
279281

280282
err := dbs[0].JoinNetwork("network1")
@@ -344,7 +346,7 @@ func TestFlakyNetworkDBCRUDTableEntries(t *testing.T) {
344346
closeNetworkDBInstances(t, dbs)
345347
}
346348

347-
func TestFlakyNetworkDBNodeLeave(t *testing.T) {
349+
func TestNetworkDBNodeLeave(t *testing.T) {
348350
dbs := createNetworkDBInstances(t, 2, "node", DefaultConfig())
349351

350352
err := dbs[0].JoinNetwork("network1")

0 commit comments

Comments
 (0)