git » dnss » commit 27caeff

dnstox: Remove race in tests

author Alberto Bertogli
2016-05-30 10:35:15 UTC
committer Alberto Bertogli
2016-05-30 10:35:15 UTC
parent d19c4a365efa496978b7fc518a77e9fda8748f79

dnstox: Remove race in tests

One of the tests has a data race, as it changes the maintenance period
"constant". This patch fixes the race by starting maintenance only once, after
the period has been updated.

It's not a pretty approach in general, but in this case, as we only test the
function once, it works fine.

internal/dnstox/caching_test.go +8 -9

diff --git a/internal/dnstox/caching_test.go b/internal/dnstox/caching_test.go
index 15200f7..778972d 100644
--- a/internal/dnstox/caching_test.go
+++ b/internal/dnstox/caching_test.go
@@ -71,15 +71,6 @@ func TestBasic(t *testing.T) {
 	if !r.init {
 		t.Errorf("caching resolver did not initialize backing")
 	}
-	go c.Maintain()
-
-	// Check that the back resolver's Maintain() is called.
-	select {
-	case <-r.maintain:
-		t.Log("Maintain() called")
-	case <-time.After(1 * time.Second):
-		t.Errorf("back resolver Maintain() was not called")
-	}
 
 	resetStats()
 
@@ -140,6 +131,14 @@ func TestTTL(t *testing.T) {
 	go c.Maintain()
 	resetStats()
 
+	// Check that the back resolver's Maintain() is called.
+	select {
+	case <-r.maintain:
+		t.Log("Maintain() called")
+	case <-time.After(1 * time.Second):
+		t.Errorf("back resolver Maintain() was not called")
+	}
+
 	start := time.Now()
 	for time.Since(start) < 1*time.Second {
 		resp = queryA(t, c, "", "test.", "1.2.3.4")