Parcourir la source

libnet/d/bridge: fix race condition in test case

TestCreateParallel, which was ostensibly added as a regression test for
race conditions inside the bridge driver, contains a race condition. The
getIPv4Data() calls race the network configuration and so will sometimes
see the existing address assignments return IP address ranges which do
not conflict with them. While normally a good thing, the test asserts
that exactly one of the 100 networks is successfully created. Pass the
same IPAM data when attempting to create every network to ensure that
the address ranges conflict.

Signed-off-by: Cory Snider <csnider@mirantis.com>
Cory Snider il y a 2 ans
Parent
commit
010077ba0f
1 fichiers modifiés avec 4 ajouts et 2 suppressions
  1. 4 2
      libnetwork/drivers/bridge/bridge_test.go

+ 4 - 2
libnetwork/drivers/bridge/bridge_test.go

@@ -1087,6 +1087,8 @@ func TestCreateParallel(t *testing.T) {
 		t.Fatalf("Failed to setup driver config: %v", err)
 		t.Fatalf("Failed to setup driver config: %v", err)
 	}
 	}
 
 
+	ipV4Data := getIPv4Data(t, "docker0")
+
 	ch := make(chan error, 100)
 	ch := make(chan error, 100)
 	for i := 0; i < 100; i++ {
 	for i := 0; i < 100; i++ {
 		name := "net" + strconv.Itoa(i)
 		name := "net" + strconv.Itoa(i)
@@ -1094,11 +1096,11 @@ func TestCreateParallel(t *testing.T) {
 			config := &networkConfiguration{BridgeName: name}
 			config := &networkConfiguration{BridgeName: name}
 			genericOption := make(map[string]interface{})
 			genericOption := make(map[string]interface{})
 			genericOption[netlabel.GenericData] = config
 			genericOption[netlabel.GenericData] = config
-			if err := d.CreateNetwork(name, genericOption, nil, getIPv4Data(t, "docker0"), nil); err != nil {
+			if err := d.CreateNetwork(name, genericOption, nil, ipV4Data, nil); err != nil {
 				ch <- fmt.Errorf("failed to create %s", name)
 				ch <- fmt.Errorf("failed to create %s", name)
 				return
 				return
 			}
 			}
-			if err := d.CreateNetwork(name, genericOption, nil, getIPv4Data(t, "docker0"), nil); err == nil {
+			if err := d.CreateNetwork(name, genericOption, nil, ipV4Data, nil); err == nil {
 				ch <- fmt.Errorf("failed was able to create overlap %s", name)
 				ch <- fmt.Errorf("failed was able to create overlap %s", name)
 				return
 				return
 			}
 			}