Browse Source

libnetwork: ensure all nodes are available in tests

`github.com/hashicorp/memberlist` update caused `TestNetworkDBCRUDTableEntries`
to occasionally fail, because the test would try to check whether an entry
write is propagated to all nodes, but it would not wait for all nodes to
be available before performing the write.
It could be that the failure is caused simply by improved performance of
the dependency - it could also be that some connectivity guarantee the
test depended on is not provided by the dependency anymore.
The same fix is applied to `TestNetworkDBNodeJoinLeaveIteration` due to
same issue.

Signed-off-by: Roman Volosatovs <roman.volosatovs@docker.com>
Roman Volosatovs 4 years ago
parent
commit
2837fba75f
1 changed files with 4 additions and 12 deletions
  1. 4 12
      libnetwork/networkdb/networkdb_test.go

+ 4 - 12
libnetwork/networkdb/networkdb_test.go

@@ -278,6 +278,8 @@ func TestNetworkDBCRUDTableEntries(t *testing.T) {
 	err = dbs[1].JoinNetwork("network1")
 	err = dbs[1].JoinNetwork("network1")
 	assert.NilError(t, err)
 	assert.NilError(t, err)
 
 
+	dbs[0].verifyNetworkExistence(t, dbs[1].config.NodeID, "network1", true)
+
 	n := 10
 	n := 10
 	for i := 1; i <= n; i++ {
 	for i := 1; i <= n; i++ {
 		err = dbs[0].CreateEntry("test_table", "network1",
 		err = dbs[0].CreateEntry("test_table", "network1",
@@ -497,12 +499,7 @@ func TestNetworkDBNodeJoinLeaveIteration(t *testing.T) {
 	assert.NilError(t, err)
 	assert.NilError(t, err)
 
 
 	// Wait for the propagation on db[0]
 	// Wait for the propagation on db[0]
-	for i := 0; i < maxRetry; i++ {
-		if len(dbs[0].networkNodes["network1"]) == 2 {
-			break
-		}
-		time.Sleep(1 * time.Second)
-	}
+	dbs[0].verifyNetworkExistence(t, dbs[1].config.NodeID, "network1", true)
 	if len(dbs[0].networkNodes["network1"]) != 2 {
 	if len(dbs[0].networkNodes["network1"]) != 2 {
 		t.Fatalf("The networkNodes list has to have be 2 instead of %d - %v", len(dbs[0].networkNodes["network1"]), dbs[0].networkNodes["network1"])
 		t.Fatalf("The networkNodes list has to have be 2 instead of %d - %v", len(dbs[0].networkNodes["network1"]), dbs[0].networkNodes["network1"])
 	}
 	}
@@ -511,12 +508,7 @@ func TestNetworkDBNodeJoinLeaveIteration(t *testing.T) {
 	}
 	}
 
 
 	// Wait for the propagation on db[1]
 	// Wait for the propagation on db[1]
-	for i := 0; i < maxRetry; i++ {
-		if len(dbs[1].networkNodes["network1"]) == 2 {
-			break
-		}
-		time.Sleep(1 * time.Second)
-	}
+	dbs[1].verifyNetworkExistence(t, dbs[0].config.NodeID, "network1", true)
 	if len(dbs[1].networkNodes["network1"]) != 2 {
 	if len(dbs[1].networkNodes["network1"]) != 2 {
 		t.Fatalf("The networkNodes list has to have be 2 instead of %d - %v", len(dbs[1].networkNodes["network1"]), dbs[1].networkNodes["network1"])
 		t.Fatalf("The networkNodes list has to have be 2 instead of %d - %v", len(dbs[1].networkNodes["network1"]), dbs[1].networkNodes["network1"])
 	}
 	}