Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9f4cf7c6c4 |
@@ -1424,6 +1424,37 @@ func TestQueryNameserverIP_DeadlineDuringFirstTry(t *testing.T) {
|
|||||||
assert.NotEmpty(t, resp.Error)
|
assert.NotEmpty(t, resp.Error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestQueryNameserverIP_CancelDuringFirstTry cancels the context while
|
||||||
|
// the first try of a query to 192.0.2.1, where nothing answers, waits
|
||||||
|
// for a reply. That try's timeout is all that is learned about the
|
||||||
|
// nameserver, so it is reported as timed out, not as answering.
|
||||||
|
func TestQueryNameserverIP_CancelDuringFirstTry(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
r := newTestResolver(t)
|
||||||
|
|
||||||
|
// The first try starts at once and waits two seconds for a reply;
|
||||||
|
// the cancel comes a second in. The DNS client cuts a try short at
|
||||||
|
// the context's deadline but not at a cancel, so the try still
|
||||||
|
// waits its full two seconds and ends as a timeout a second after
|
||||||
|
// the cancel. By then the context has certainly ended, so no second
|
||||||
|
// try is made. With a deadline instead, the try ends at the moment
|
||||||
|
// the context does, and whether a second try is made depends on
|
||||||
|
// which the resolver sees first.
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
t.Cleanup(cancel)
|
||||||
|
time.AfterFunc(time.Second, cancel)
|
||||||
|
|
||||||
|
resp, err := r.QueryNameserverIP(
|
||||||
|
ctx, "unreachable.test.", "192.0.2.1",
|
||||||
|
"example.com",
|
||||||
|
)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
assert.Equal(t, resolver.StatusTimeout, resp.Status)
|
||||||
|
assert.NotEmpty(t, resp.Error)
|
||||||
|
}
|
||||||
|
|
||||||
// TestQueryNameserverIP_CancelledLogsNothing cancels the context while
|
// TestQueryNameserverIP_CancelledLogsNothing cancels the context while
|
||||||
// a query to 192.0.2.1, where nothing answers, is waiting for a reply,
|
// a query to 192.0.2.1, where nothing answers, is waiting for a reply,
|
||||||
// as shutdown does. The query was cut short, not failed, so nothing is
|
// as shutdown does. The query was cut short, not failed, so nothing is
|
||||||
|
|||||||
Reference in New Issue
Block a user