Skip to content

Commit fac947a

Browse files
committed
Fix unittest race
1 parent 4758132 commit fac947a

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

bdns/dns_test.go

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,6 @@ func TestRetryMetrics(t *testing.T) {
791791

792792
testClient := New(time.Second*10, staticProvider, metrics.NoopRegisterer, clock.NewFake(), 3, "", blog.UseMock(), tlsConfig)
793793
dr := testClient.(*impl)
794-
795794
dr.exchanger = &testExchanger{errs: []error{isTimeoutErr, isTimeoutErr, nil}}
796795
ctx, cancel := context.WithCancel(context.Background())
797796
cancel()
@@ -800,7 +799,15 @@ func TestRetryMetrics(t *testing.T) {
800799
err.Error() != "DNS problem: query timed out (and was canceled) looking up TXT for example.com" {
801800
t.Errorf("expected %s, got %s", context.Canceled, err)
802801
}
802+
test.AssertMetricWithLabelsEquals(
803+
t, dr.timeoutCounter, prometheus.Labels{
804+
"qtype": "TXT",
805+
"result": "canceled",
806+
"resolver": "127.0.0.1",
807+
}, 1)
803808

809+
testClient = New(time.Second*10, staticProvider, metrics.NoopRegisterer, clock.NewFake(), 3, "", blog.UseMock(), tlsConfig)
810+
dr = testClient.(*impl)
804811
dr.exchanger = &testExchanger{errs: []error{isTimeoutErr, isTimeoutErr, nil}}
805812
ctx, cancel = context.WithTimeout(context.Background(), -10*time.Hour)
806813
defer cancel()
@@ -809,28 +816,12 @@ func TestRetryMetrics(t *testing.T) {
809816
err.Error() != "DNS problem: query timed out looking up TXT for example.com" {
810817
t.Errorf("expected %s, got %s", context.DeadlineExceeded, err)
811818
}
812-
813-
dr.exchanger = &testExchanger{errs: []error{isTimeoutErr, isTimeoutErr, nil}}
814-
ctx, deadlineCancel := context.WithTimeout(context.Background(), -10*time.Hour)
815-
deadlineCancel()
816-
_, _, err = dr.LookupTXT(ctx, "example.com")
817-
if err == nil ||
818-
err.Error() != "DNS problem: query timed out looking up TXT for example.com" {
819-
t.Errorf("expected %s, got %s", context.DeadlineExceeded, err)
820-
}
821-
822-
test.AssertMetricWithLabelsEquals(
823-
t, dr.timeoutCounter, prometheus.Labels{
824-
"qtype": "TXT",
825-
"result": "canceled",
826-
"resolver": "127.0.0.1",
827-
}, 1)
828819
test.AssertMetricWithLabelsEquals(
829820
t, dr.timeoutCounter, prometheus.Labels{
830821
"qtype": "TXT",
831822
"result": "deadline exceeded",
832823
"resolver": "127.0.0.1",
833-
}, 2)
824+
}, 1)
834825
}
835826

836827
type testTimeoutError bool

0 commit comments

Comments
 (0)