Repository: moby/moby (Go)

Issue:
Flaky test: TestNetworkDBCRUDMediumCluster (libnetwork)
Seen failing on Windows RS5 https://github.com/moby/moby/pull/42005 https://ci-next.docker.com/public/job/moby/job/PR-42005/6/execution/node/270/log/?consoleFull

```
=== RUN   TestNetworkDBCRUDMediumCluster
2021/06/07 07:36:57 Closing DB instances...
time="2021-06-07T07:36:57Z" level=error msg="node: c784143724ad is unknown to memberlist"
time="2021-06-07T07:36:58Z" level=error msg="node: c0a70b8886f7 is unknown to memberlist"
--- FAIL: TestNetworkDBCRUDMediumCluster (9.68s)
    networkdb_test.go:117: Network existence verification failed
```

[windowsRS5-integration-bundles.zip](https://github.com/moby/moby/files/6616800/windowsRS5-integration-bundles.zip)



Discussion:
Seen failing again, now on https://github.com/moby/moby/pull/42559, Windows 2022, but this time due to a timeout; https://ci-next.docker.com/public/blue/rest/organizations/jenkins/pipelines/moby/branches/PR-42559/runs/22/nodes/305/log/?start=0

```
=== RUN   TestNetworkDBCRUDMediumCluster
    networkdb_test.go:420: timeout hit after 20s: node2:Waiting for cluser peers to be established
--- FAIL: TestNetworkDBCRUDMediumCluster (22.34s)
```

[win-2022-integration-bundles-3.zip](https://github.com/moby/moby/files/6795063/win-2022-integration-bundles-3.zip)



Patch:
diff --git a/libnetwork/networkdb/cluster.go b/libnetwork/networkdb/cluster.go
index a6c10e36a5245..0c0a522d05e9b 100644
--- a/libnetwork/networkdb/cluster.go
+++ b/libnetwork/networkdb/cluster.go
@@ -112,6 +112,7 @@ func (nDB *NetworkDB) clusterInit() error {
 
 	if nDB.config.BindPort != 0 {
 		config.BindPort = nDB.config.BindPort
+		config.AdvertisePort = nDB.config.BindPort
 	}
 
 	config.ProtocolVersion = memberlist.ProtocolVersion2Compatible


Test patch:
diff --git a/libnetwork/networkdb/networkdb_test.go b/libnetwork/networkdb/networkdb_test.go
index f48c253b738d3..566dcb0b5a713 100644
--- a/libnetwork/networkdb/networkdb_test.go
+++ b/libnetwork/networkdb/networkdb_test.go
@@ -46,9 +46,11 @@ func createNetworkDBInstances(t *testing.T, num int, namePrefix string, conf *Co
 		localConfig.Hostname = fmt.Sprintf("%s%d", namePrefix, i+1)
 		localConfig.NodeID = stringid.TruncateID(stringid.GenerateRandomID())
 		localConfig.BindPort = int(dbPort.Add(1))
+		localConfig.BindAddr = "127.0.0.1"
+		localConfig.AdvertiseAddr = localConfig.BindAddr
 		db := launchNode(t, localConfig)
 		if i != 0 {
-			assert.Check(t, db.Join([]string{fmt.Sprintf("localhost:%d", db.config.BindPort-1)}))
+			assert.Check(t, db.Join([]string{net.JoinHostPort(db.config.AdvertiseAddr, strconv.Itoa(db.config.BindPort-1))}))
 		}
 
 		dbs = append(dbs, db)
@@ -244,7 +246,7 @@ func TestNetworkDBJoinLeaveNetworks(t *testing.T) {
 	closeNetworkDBInstances(t, dbs)
 }
 
-func TestFlakyNetworkDBCRUDTableEntry(t *testing.T) {
+func TestNetworkDBCRUDTableEntry(t *testing.T) {
 	dbs := createNetworkDBInstances(t, 3, "node", DefaultConfig())
 
 	err := dbs[0].JoinNetwork("network1")
@@ -274,7 +276,7 @@ func TestFlakyNetworkDBCRUDTableEntry(t *testing.T) {
 	closeNetworkDBInstances(t, dbs)
 }
 
-func TestFlakyNetworkDBCRUDTableEntries(t *testing.T) {
+func TestNetworkDBCRUDTableEntries(t *testing.T) {
 	dbs := createNetworkDBInstances(t, 2, "node", DefaultConfig())
 
 	err := dbs[0].JoinNetwork("network1")
@@ -344,7 +346,7 @@ func TestFlakyNetworkDBCRUDTableEntries(t *testing.T) {
 	closeNetworkDBInstances(t, dbs)
 }
 
-func TestFlakyNetworkDBNodeLeave(t *testing.T) {
+func TestNetworkDBNodeLeave(t *testing.T) {
 	dbs := createNetworkDBInstances(t, 2, "node", DefaultConfig())
 
 	err := dbs[0].JoinNetwork("network1")