-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
dns: fix constant 30s backoff for re-resolution #7262
Conversation
Without Fix
With Fix
|
efa9843
to
074c279
Compare
dbbbea6
to
7484d21
Compare
I've tested this and can confirm that it resolves the issue described in #7186. |
|
@purnesh42H : This PR definitely needs a release note because we are fixing a bug that we introduced. |
// the likelihood of flakiness due to timing issues. | ||
for i := 0; i < 4; i++ { | ||
verifyUpdateFromResolver(ctx, t, stateCh, wantAddrs, nil, wantSC) | ||
time.Sleep(1 * time.Second) // respect resolution rate of 1 second for re-resolve |
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.
We try to avoid sleeping in our tests as much as possible. Sleeping causes the tests to unnecessarily flaky, and run for longer than actually required.
Instead, if you override internal.TimeAfterFunc
, you can control exactly when this function pushes something on the channel read by the code. This way, you can avoid sleeping as well.
There is currently an overrideTimeAfterFunc
helper function, but this sets the after func
to be invoked after a set duration. Instead you can override internal.TimeAfterFunc
to return a channel that is controlled by the test, and have it push to it whenever it wants the code under test to be unblocked.
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.
I don't think we should overriding internal.TimeAfterFunc
because we want to test the actual implementation work correctly with MinResolutionInterval
. Here, we just want to wait outside for 1 second before making another request so I just replaced time.Sleep
with another channel using TimeAfterFunc
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.
No, we don't want this test to run for 4+ seconds.
Instead I suggest the following:
- Define a variable for
internal.TimeNowFunc
, just like how it is done forinternal.TimeAfterFunc
- set this variable to
time.Now
in theinit
function
- set this variable to
- Override this variable to return a time value that you control in your test
- Override
internal.TimeAfterFunc
in your test and verify that it is called with the expected duration
Let me know if this doesn't work.
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.
Thanks for the suggestion. Modified the test to override time.Until
to calculate remaining wait to allow resolution after 1s i.e. equivalent of making re-resolution after 1s and verify the expected wait duration is very small.
ce604c2
to
e5f053b
Compare
e5f053b
to
78a490c
Compare
bec24bd
to
23dd2e8
Compare
e6304b1
to
41e46e4
Compare
41e46e4
to
a775921
Compare
@@ -102,6 +102,15 @@ func overrideTimeAfterFuncWithChannel(t *testing.T) (durChan chan time.Duration, | |||
return durChan, timeChan | |||
} | |||
|
|||
// Override the remaining time used by the DNS resolver to allow resolution |
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.
// between two resolution requests apart from [minResolutionInterval]. | ||
// It sets the minResolutionInterval 1s and overrides timeUntilFunc to | ||
// calculate remaining time to allow resolution after 1s and verifies that | ||
// remaining time to allow resolution is very small |
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.
Nit: Same here. Please terminate with a period.
|
||
// TestMinResolutionInterval_NoExtraDelay verifies that there is no extra delay | ||
// between two resolution requests apart from [minResolutionInterval]. | ||
// It sets the minResolutionInterval 1s and overrides timeUntilFunc to |
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.
Nit: Switch It sets the minResolutionInterval 1s
with either It sets the minResolutionInterval to 1s
or It sets a minResolutionInterval of 1s
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) | ||
defer cancel() |
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.
Please don't recreate the test context. Use the one created earlier. Using the same top-level test context will ensure that all operations in the test complete within defaultTestTimeout
.
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.
Done. Missed removing it after getting the test work
}, | ||
} | ||
overrideNetResolver(t, tr) | ||
var minResolutionInterval = 1 * time.Second |
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.
Use const instead.
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.
Done
23d7528
to
6d8cc1b
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #7262 +/- ##
==========================================
- Coverage 81.24% 80.49% -0.75%
==========================================
Files 345 348 +3
Lines 33941 33985 +44
==========================================
- Hits 27574 27357 -217
- Misses 5202 5432 +230
- Partials 1165 1196 +31
|
6d8cc1b
to
deff579
Compare
Fixes #7186 with a test
RELEASE NOTES: