-
Notifications
You must be signed in to change notification settings - Fork 1.5k
test(usm): fix flakiness in resolver periodic-update tests #55883
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -448,6 +448,12 @@ func TestLocalResolverPeriodicUpdates(t *testing.T) { | |
| resolver.Run() | ||
| mockedClock.Add(11 * time.Second) | ||
|
|
||
| assert.Eventually(func() bool { | ||
|
Contributor
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 wall-clock-based |
||
| resolver.mux.Lock() | ||
| defer resolver.mux.Unlock() | ||
| return len(resolver.addrToCtrID) == 4 | ||
| }, 2*time.Second, 5*time.Millisecond) | ||
|
|
||
| connections := &model.Connections{ | ||
| Conns: []*model.Connection{ | ||
| // connection 0 | ||
|
|
@@ -538,6 +544,12 @@ func TestLocalResolverCachePersistence(t *testing.T) { | |
| resolver.Run() | ||
| mockedClock.Add(11 * time.Second) | ||
|
|
||
| assert.Eventually(func() bool { | ||
| resolver.mux.Lock() | ||
| defer resolver.mux.Unlock() | ||
| return len(resolver.addrToCtrID) == 4 | ||
| }, 2*time.Second, 5*time.Millisecond) | ||
|
|
||
| func() { | ||
| resolver.mux.Lock() | ||
| defer resolver.mux.Unlock() | ||
|
|
@@ -628,17 +640,6 @@ func TestLocalResolverCachePersistence(t *testing.T) { | |
| } | ||
|
|
||
| mockContainerProvider.EXPECT().GetContainers(2*time.Second, nil).Return(containers, nil, nil, nil) | ||
| mockedClock.Add(10 * time.Second) | ||
|
|
||
| // still should have 4 entries in the addr cache, | ||
| // missing entries should be just marked as not | ||
| // in use | ||
| func() { | ||
| resolver.mux.Lock() | ||
| defer resolver.mux.Unlock() | ||
|
|
||
| assert.Len(resolver.addrToCtrID, 4) | ||
| }() | ||
|
|
||
| missingAddrs := []model.ContainerAddr{ | ||
| { | ||
|
|
@@ -653,6 +654,32 @@ func TestLocalResolverCachePersistence(t *testing.T) { | |
| }, | ||
| } | ||
|
|
||
| mockedClock.Add(10 * time.Second) | ||
|
|
||
| assert.Eventually(func() bool { | ||
| resolver.mux.Lock() | ||
| defer resolver.mux.Unlock() | ||
|
|
||
| for addr, cid := range resolver.addrToCtrID { | ||
| for _, missing := range missingAddrs { | ||
| if missing == addr && cid.inUse { | ||
| return false | ||
| } | ||
| } | ||
| } | ||
| return len(resolver.addrToCtrID) == 4 | ||
| }, 2*time.Second, 5*time.Millisecond) | ||
|
|
||
| // still should have 4 entries in the addr cache, | ||
| // missing entries should be just marked as not | ||
| // in use | ||
| func() { | ||
| resolver.mux.Lock() | ||
| defer resolver.mux.Unlock() | ||
|
|
||
| assert.Len(resolver.addrToCtrID, 4) | ||
| }() | ||
|
|
||
| // verify the missing address entries were marked | ||
| // as not in use | ||
| func() { | ||
|
|
@@ -743,6 +770,12 @@ func TestLocalResolverCacheLimits(t *testing.T) { | |
| resolver.Run() | ||
| mockedClock.Add(11 * time.Second) | ||
|
|
||
| assert.Eventually(func() bool { | ||
| resolver.mux.Lock() | ||
| defer resolver.mux.Unlock() | ||
| return len(resolver.addrToCtrID) == 1 && len(resolver.ctrForPid) == 1 | ||
| }, 2*time.Second, 5*time.Millisecond) | ||
|
|
||
| func() { | ||
| resolver.mux.Lock() | ||
| defer resolver.mux.Unlock() | ||
|
|
||
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.
Eventuallystill depends on wall-clock polling and an arbitrary 2-second deadline, so these tests can remain flaky under sufficient contention. Synchronize with the mockedGetContainerscall (for example, signal a channel fromDoAndReturn) and wait for that completion instead. The same issue applies to the other addedEventuallycalls.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.
My understanding is that relying on a channel here would need to also change the code being tested, which I don't want to do.
I'll let the reviewers comment further since I don't know this code enough to make the call IMHO