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>
This commit is contained in:
Cory Snider 2022-11-07 19:13:05 -05:00
parent 7b2308980c
commit 010077ba0f

View file

@ -1087,6 +1087,8 @@ func TestCreateParallel(t *testing.T) {
t.Fatalf("Failed to setup driver config: %v", err)
}
ipV4Data := getIPv4Data(t, "docker0")
ch := make(chan error, 100)
for i := 0; i < 100; i++ {
name := "net" + strconv.Itoa(i)
@ -1094,11 +1096,11 @@ func TestCreateParallel(t *testing.T) {
config := &networkConfiguration{BridgeName: name}
genericOption := make(map[string]interface{})
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)
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)
return
}