From 67d3f2d8a485119e14dc504d1404e5d83161b515 Mon Sep 17 00:00:00 2001 From: David Cheung Date: Mon, 17 Apr 2023 22:35:26 +0000 Subject: [PATCH] Fix wait.PollImmediate in TestEnableDegradedMode Error state should be checked with syncLock, and we should return false and nil if we are not in the desired state. We should also check errorState within waitPoll because seeing update in NEG does not guarantee we have also set the syncer's error state. --- pkg/neg/syncers/transaction_test.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/pkg/neg/syncers/transaction_test.go b/pkg/neg/syncers/transaction_test.go index 15acb6127e..b9dcc7d6fd 100644 --- a/pkg/neg/syncers/transaction_test.go +++ b/pkg/neg/syncers/transaction_test.go @@ -1830,16 +1830,19 @@ func TestEnableDegradedMode(t *testing.T) { err = wait.PollImmediate(time.Second, 3*time.Second, func() (bool, error) { out, _, err = retrieveExistingZoneNetworkEndpointMap(tc.negName, zoneGetter, fakeCloud, meta.VersionGA, negtypes.L7Mode) if err != nil { - return false, err + return false, nil } if !reflect.DeepEqual(tc.expectedEndpoints, out) { - return false, err + return false, nil + } + s.syncLock.Lock() + errorState := s.inErrorState() + s.syncLock.Unlock() + if errorState != tc.expectedInErrorState { + return false, nil } return true, nil }) - if s.inErrorState() != tc.expectedInErrorState { - t.Errorf("after syncInternal, error state is %v, expected to be %v", s.inErrorState(), tc.expectedInErrorState) - } if err != nil { t.Errorf("endpoints are different from expected:\ngot %+v,\n expected %+v", out, tc.expectedEndpoints) }