-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
node-neigh: Fix unit test flake #16072
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,7 @@ import ( | |
nodeaddressing "github.com/cilium/cilium/pkg/node/addressing" | ||
nodeTypes "github.com/cilium/cilium/pkg/node/types" | ||
"github.com/cilium/cilium/pkg/option" | ||
"github.com/cilium/cilium/pkg/testutils" | ||
|
||
"github.com/containernetworking/plugins/pkg/ns" | ||
"github.com/vishvananda/netlink" | ||
|
@@ -1014,7 +1015,7 @@ func (s *linuxPrivilegedIPv4OnlyTestSuite) TestArpPingHandling(c *check.C) { | |
dpConfig := DatapathConfiguration{HostDevice: "veth0"} | ||
prevARPPeriod := option.Config.ARPPingRefreshPeriod | ||
defer func() { option.Config.ARPPingRefreshPeriod = prevARPPeriod }() | ||
option.Config.ARPPingRefreshPeriod = time.Duration(10 * time.Millisecond) | ||
option.Config.ARPPingRefreshPeriod = time.Duration(1 * time.Nanosecond) | ||
|
||
linuxNodeHandler := NewNodeHandler(dpConfig, s.nodeAddressing, nil).(*linuxNodeHandler) | ||
c.Assert(linuxNodeHandler, check.Not(check.IsNil)) | ||
|
@@ -1026,18 +1027,42 @@ func (s *linuxPrivilegedIPv4OnlyTestSuite) TestArpPingHandling(c *check.C) { | |
}) | ||
c.Assert(err, check.IsNil) | ||
|
||
// wait waits for neigh entry update or waits for removal if waitForDelete=true | ||
wait := func(nodeID nodeTypes.Identity, before *time.Time, waitForDelete bool) { | ||
err := testutils.WaitUntil(func() bool { | ||
linuxNodeHandler.neighLock.Lock() | ||
defer linuxNodeHandler.neighLock.Unlock() | ||
nextHop, found := linuxNodeHandler.neighNextHopByNode[nodeID] | ||
if !found { | ||
return waitForDelete | ||
} | ||
lastPing, found := linuxNodeHandler.neighLastPingByNextHop[nextHop] | ||
if !found { | ||
return false | ||
} | ||
if waitForDelete { | ||
return false | ||
} | ||
return before.Before(lastPing) | ||
}, 5*time.Second) | ||
c.Assert(err, check.IsNil) | ||
} | ||
|
||
nodev1 := nodeTypes.Node{ | ||
Name: "node1", | ||
IPAddresses: []nodeTypes.Address{{nodeaddressing.NodeInternalIP, ip1}}, | ||
} | ||
now := time.Now() | ||
err = linuxNodeHandler.NodeAdd(nodev1) | ||
c.Assert(err, check.IsNil) | ||
// insertNeighbor is invoked async | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same comment appears a few lines below. Was this maybe forgotten from an earlier version? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed redundant comments. |
||
// Insert the same node second time. This should not increment refcount for | ||
// the same nextHop. We test it by checking that NodeDelete has removed the | ||
// related neigh entry. | ||
err = linuxNodeHandler.NodeAdd(nodev1) | ||
c.Assert(err, check.IsNil) | ||
time.Sleep(100 * time.Millisecond) // insertNeighbor is invoked async | ||
// insertNeighbor is invoked async, so thus this wait based on last ping | ||
wait(nodev1.Identity(), &now, false) | ||
|
||
// Check whether an arp entry for nodev1 IP addr (=veth1) was added | ||
neighs, err := netlink.NeighList(veth0.Attrs().Index, netlink.FAMILY_V4) | ||
|
@@ -1064,10 +1089,12 @@ func (s *linuxPrivilegedIPv4OnlyTestSuite) TestArpPingHandling(c *check.C) { | |
return nil | ||
}) | ||
|
||
now = time.Now() | ||
err = netlink.LinkSetHardwareAddr(veth0, veth1HwAddr) | ||
c.Assert(err, check.IsNil) | ||
|
||
linuxNodeHandler.NodeNeighborRefresh(context.TODO(), nodev1) | ||
wait(nodev1.Identity(), &now, false) | ||
neighs, err = netlink.NeighList(veth0.Attrs().Index, netlink.FAMILY_V4) | ||
c.Assert(err, check.IsNil) | ||
found = false | ||
|
@@ -1084,7 +1111,8 @@ func (s *linuxPrivilegedIPv4OnlyTestSuite) TestArpPingHandling(c *check.C) { | |
// Remove nodev1, and check whether the arp entry was removed | ||
err = linuxNodeHandler.NodeDelete(nodev1) | ||
c.Assert(err, check.IsNil) | ||
time.Sleep(100 * time.Millisecond) // deleteNeighbor is invoked async | ||
// deleteNeighbor is invoked async too | ||
wait(nodev1.Identity(), nil, true) | ||
|
||
neighs, err = netlink.NeighList(veth0.Attrs().Index, netlink.FAMILY_V4) | ||
c.Assert(err, check.IsNil) | ||
|
@@ -1100,9 +1128,10 @@ func (s *linuxPrivilegedIPv4OnlyTestSuite) TestArpPingHandling(c *check.C) { | |
// Create multiple goroutines which call insertNeighbor and check whether | ||
// MAC changes of veth1 are properly handled. This is a basic randomized | ||
// testing of insertNeighbor() fine-grained locking. | ||
now = time.Now() | ||
err = linuxNodeHandler.NodeAdd(nodev1) | ||
c.Assert(err, check.IsNil) | ||
time.Sleep(100 * time.Millisecond) | ||
wait(nodev1.Identity(), &now, false) | ||
|
||
rndHWAddr := func() net.HardwareAddr { | ||
mac := make([]byte, 6) | ||
|
@@ -1172,10 +1201,10 @@ func (s *linuxPrivilegedIPv4OnlyTestSuite) TestArpPingHandling(c *check.C) { | |
} | ||
// Cleanup | ||
close(done) | ||
wg.Wait() | ||
now = time.Now() | ||
err = linuxNodeHandler.NodeDelete(nodev1) | ||
c.Assert(err, check.IsNil) | ||
time.Sleep(100 * time.Millisecond) // deleteNeighbor is invoked async | ||
wait(nodev1.Identity(), nil, true) | ||
|
||
// Setup routine for the 2. test | ||
setupRemoteNode := func(vethName, vethPeerName, netnsName, vethCIDR, vethIPAddr, | ||
|
@@ -1320,15 +1349,17 @@ func (s *linuxPrivilegedIPv4OnlyTestSuite) TestArpPingHandling(c *check.C) { | |
Name: "node2", | ||
IPAddresses: []nodeTypes.Address{{nodeaddressing.NodeInternalIP, node2IP}}, | ||
} | ||
now = time.Now() | ||
c.Assert(linuxNodeHandler.NodeAdd(nodev2), check.IsNil) | ||
wait(nodev2.Identity(), &now, false) | ||
|
||
node3IP := net.ParseIP("7.7.7.250") | ||
nodev3 := nodeTypes.Node{ | ||
Name: "node3", | ||
IPAddresses: []nodeTypes.Address{{nodeaddressing.NodeInternalIP, node3IP}}, | ||
} | ||
c.Assert(linuxNodeHandler.NodeAdd(nodev3), check.IsNil) | ||
time.Sleep(100 * time.Millisecond) // insertNeighbor is invoked async | ||
wait(nodev3.Identity(), &now, false) | ||
|
||
nextHop := net.ParseIP("9.9.9.250") | ||
// Check that both node{2,3} are via nextHop (gw) | ||
|
@@ -1346,6 +1377,7 @@ func (s *linuxPrivilegedIPv4OnlyTestSuite) TestArpPingHandling(c *check.C) { | |
|
||
// Check that removing node2 will not remove nextHop, as it is still used by node3 | ||
c.Assert(linuxNodeHandler.NodeDelete(nodev2), check.IsNil) | ||
wait(nodev2.Identity(), nil, true) | ||
neighs, err = netlink.NeighList(veth0.Attrs().Index, netlink.FAMILY_V4) | ||
found = false | ||
for _, n := range neighs { | ||
|
@@ -1358,7 +1390,7 @@ func (s *linuxPrivilegedIPv4OnlyTestSuite) TestArpPingHandling(c *check.C) { | |
|
||
// However, removing node3 should remove the neigh entry for nextHop | ||
c.Assert(linuxNodeHandler.NodeDelete(nodev3), check.IsNil) | ||
time.Sleep(100 * time.Millisecond) // deleteNeighbor is invoked async | ||
wait(nodev3.Identity(), nil, true) | ||
|
||
found = false | ||
neighs, err = netlink.NeighList(veth0.Attrs().Index, netlink.FAMILY_V4) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From my reading of the code
now
is a lower bound for when the operation happened.However, it is used only for insertion and not deletion (since for the latter, we do not have a deletion timestamp to check).
Given this, and the overall structure of the function, I wonder if it would be better to have two versions of this function one for deletes and one for inserts.
I think this would also improve readability on the caller side (at the cost of some code duplication).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did s/now/before/. Hope it's more clear.
Made
before
as*time.Time
, so that nil can be passed for the wait for the deletion.I want this waiting routine to be concise to avoid polluting the test case. Also, to follow DRY principle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, sounds good.