Skip to content

Commit 90ec2c2

Browse files
committed
libn/networkdb: listen only on loopback in tests
NetworkDB defaults to binding to the unspecified address for gossip communications, with no advertise address set. In this configuration, the memberlist instance listens on all network interfaces and picks one of the host's public IP addresses as the advertise address. The NetworkDB unit tests don't override this default, leaving them vulnerable to flaking out as a result of rogue network traffic perturbing the test, or the inferred advertise address not being useable for loopback testing. And macOS prompts for permission to allow the test executable to listen on public interfaces every time it is rebuilt. Modify the NetworkDB tests to explicitly bind to, advertise, and join ports on 127.0.0.1 to make the tests more robust to flakes in CI and more convenient to run locally. Signed-off-by: Cory Snider <[email protected]>
1 parent e3f9edd commit 90ec2c2

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

libnetwork/networkdb/networkdb_test.go

Lines changed: 3 additions & 1 deletion
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)

0 commit comments

Comments
 (0)