fix(netxlite): make default resolver converge faster (#456)

* fix(netxlite): make default resolver converge faster

Closes https://github.com/ooni/probe/issues/1726

* Update internal/netxlite/resolver.go

* fix(ndt7): adapt tests after previous change

Because now we're running the DNS resolution inside a goroutine
with a child context, the returned error string is different.

The previous error said we canceled the whole dialing operation,
while now we see directly that the context was canceled.
This commit is contained in:
Simone Basso 2021-09-05 18:50:05 +02:00 committed by GitHub
commit a3a27b1ebf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 125 additions and 16 deletions

View file

@ -18,8 +18,8 @@ func TestDialDownloadWithCancelledContext(t *testing.T) {
cancel() // immediately halt
mgr := newDialManager("wss://hostname.fake", log.Log, "miniooni/0.1.0-dev")
conn, err := mgr.dialDownload(ctx)
if err == nil || !strings.HasSuffix(err.Error(), "operation was canceled") {
t.Fatal("not the error we expected")
if err == nil || !strings.HasSuffix(err.Error(), "context canceled") {
t.Fatal("not the error we expected", err)
}
if conn != nil {
t.Fatal("expected nil conn here")
@ -31,8 +31,8 @@ func TestDialUploadWithCancelledContext(t *testing.T) {
cancel() // immediately halt
mgr := newDialManager("wss://hostname.fake", log.Log, "miniooni/0.1.0-dev")
conn, err := mgr.dialUpload(ctx)
if err == nil || !strings.HasSuffix(err.Error(), "operation was canceled") {
t.Fatal("not the error we expected")
if err == nil || !strings.HasSuffix(err.Error(), "context canceled") {
t.Fatal("not the error we expected", err)
}
if conn != nil {
t.Fatal("expected nil conn here")

View file

@ -52,8 +52,8 @@ func TestDoDownloadWithCancelledContext(t *testing.T) {
err := m.doDownload(
ctx, sess, model.NewPrinterCallbacks(log.Log), new(TestKeys),
"ws://host.name")
if err == nil || !strings.HasSuffix(err.Error(), "operation was canceled") {
t.Fatal("not the error we expected")
if err == nil || !strings.HasSuffix(err.Error(), "context canceled") {
t.Fatal("not the error we expected", err)
}
}
@ -69,8 +69,8 @@ func TestDoUploadWithCancelledContext(t *testing.T) {
err := m.doUpload(
ctx, sess, model.NewPrinterCallbacks(log.Log), new(TestKeys),
"ws://host.name")
if err == nil || !strings.HasSuffix(err.Error(), "operation was canceled") {
t.Fatal("not the error we expected")
if err == nil || !strings.HasSuffix(err.Error(), "context canceled") {
t.Fatal("not the error we expected", err)
}
}
@ -132,8 +132,8 @@ func TestFailDownload(t *testing.T) {
new(model.Measurement),
model.NewPrinterCallbacks(log.Log),
)
if err == nil || !strings.HasSuffix(err.Error(), "operation was canceled") {
t.Fatal(err)
if err == nil || !strings.HasSuffix(err.Error(), "context canceled") {
t.Fatal("not the error we expected", err)
}
}
@ -153,8 +153,8 @@ func TestFailUpload(t *testing.T) {
new(model.Measurement),
model.NewPrinterCallbacks(log.Log),
)
if err == nil || !strings.HasSuffix(err.Error(), "operation was canceled") {
t.Fatal(err)
if err == nil || !strings.HasSuffix(err.Error(), "context canceled") {
t.Fatal("not the error we expected", err)
}
}