Skip to content

Commit 5ce92d0

Browse files
committed
net: deflake lookup tests
The build dashboard is dotted with net test failures. We cannot declare all builders to have flaky networks, although all fundamentally do. Instead, add a simple retry/backoff loop to the ones that show up most commonly on the dashboard at this moment. If this approach works well in practice, we can incrementally apply it to other flaky net tests. Change-Id: I69c1ca6ce5b347ad549c7eb18d0438373f6e2489 Reviewed-on: https://go-review.googlesource.com/102397 Run-TryBot: Josh Bleecher Snyder <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 6f08b9f commit 5ce92d0

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

src/net/lookup_test.go

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ var lookupGoogleSRVTests = []struct {
6060
},
6161
}
6262

63+
var backoffDuration = [...]time.Duration{time.Second, 5 * time.Second, 30 * time.Second}
64+
6365
func TestLookupGoogleSRV(t *testing.T) {
6466
if testenv.Builder() == "" {
6567
testenv.MustHaveExternalNetwork(t)
@@ -69,10 +71,20 @@ func TestLookupGoogleSRV(t *testing.T) {
6971
t.Skip("IPv4 is required")
7072
}
7173

72-
for _, tt := range lookupGoogleSRVTests {
74+
attempts := 0
75+
for i := 0; i < len(lookupGoogleSRVTests); i++ {
76+
tt := lookupGoogleSRVTests[i]
7377
cname, srvs, err := LookupSRV(tt.service, tt.proto, tt.name)
7478
if err != nil {
7579
testenv.SkipFlakyNet(t)
80+
if attempts < len(backoffDuration) {
81+
dur := backoffDuration[attempts]
82+
t.Logf("backoff %v after failure %v\n", dur, err)
83+
time.Sleep(dur)
84+
attempts++
85+
i--
86+
continue
87+
}
7688
t.Fatal(err)
7789
}
7890
if len(srvs) == 0 {
@@ -107,9 +119,20 @@ func TestLookupGmailMX(t *testing.T) {
107119

108120
defer dnsWaitGroup.Wait()
109121

110-
for _, tt := range lookupGmailMXTests {
122+
attempts := 0
123+
for i := 0; i < len(lookupGmailMXTests); i++ {
124+
tt := lookupGmailMXTests[i]
111125
mxs, err := LookupMX(tt.name)
112126
if err != nil {
127+
testenv.SkipFlakyNet(t)
128+
if attempts < len(backoffDuration) {
129+
dur := backoffDuration[attempts]
130+
t.Logf("backoff %v after failure %v\n", dur, err)
131+
time.Sleep(dur)
132+
attempts++
133+
i--
134+
continue
135+
}
113136
t.Fatal(err)
114137
}
115138
if len(mxs) == 0 {
@@ -176,9 +199,20 @@ func TestLookupGmailTXT(t *testing.T) {
176199

177200
defer dnsWaitGroup.Wait()
178201

179-
for _, tt := range lookupGmailTXTTests {
202+
attempts := 0
203+
for i := 0; i < len(lookupGmailTXTTests); i++ {
204+
tt := lookupGmailTXTTests[i]
180205
txts, err := LookupTXT(tt.name)
181206
if err != nil {
207+
testenv.SkipFlakyNet(t)
208+
if attempts < len(backoffDuration) {
209+
dur := backoffDuration[attempts]
210+
t.Logf("backoff %v after failure %v\n", dur, err)
211+
time.Sleep(dur)
212+
attempts++
213+
i--
214+
continue
215+
}
182216
t.Fatal(err)
183217
}
184218
if len(txts) == 0 {

0 commit comments

Comments
 (0)