From 996ff55983f6143f0d82ca1fa9cf67029f142c2c Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Sat, 22 Aug 2015 13:42:02 +0100 Subject: [PATCH] minimize the race in TestSingleInflight --- client_test.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/client_test.go b/client_test.go index 313f0536..7bffa09e 100644 --- a/client_test.go +++ b/client_test.go @@ -163,6 +163,10 @@ func TestClientEDNS0Local(t *testing.T) { } func TestSingleInflight(t *testing.T) { + // Test is inherently racy, because queries might actually be returned before the test + // is over, leading to multiple queries even with SingleInflight. This ofcourse then + // leads to diff. rrts and the test fails. Number of tests is now 3, to lower the chance + // for the race to hit. HandleFunc("miek.nl.", HelloServer) defer HandleRemove("miek.nl.") @@ -177,7 +181,7 @@ func TestSingleInflight(t *testing.T) { c := new(Client) c.SingleInflight = true - nr := 10 + nr := 3 ch := make(chan time.Duration) for i := 0; i < nr; i++ { go func() { @@ -201,7 +205,7 @@ Loop: } } i++ - if i == 10 { + if i == nr { break Loop } }