Parcourir la source

add race test for Registry

zhanyaru il y a 6 ans
Parent
commit
02d3148a7d
1 fichiers modifiés avec 14 ajouts et 0 suppressions
  1. 14 0
      registry_test.go

+ 14 - 0
registry_test.go

@@ -377,3 +377,17 @@ func TestConcurrentRegistryAccess(t *testing.T) {
 		t.Fatal(i)
 	}
 }
+
+// exercise race detector
+func TestRegisterAndRegisteredConcurrency(t *testing.T)  {
+	r := NewRegistry()
+	wg := &sync.WaitGroup{}
+	wg.Add(1)
+	go func(r Registry, wg *sync.WaitGroup) {
+		defer wg.Done()
+		r.Each(func(name string, iface interface{}) {
+		})
+	}(r, wg)
+	r.Register("foo", NewCounter())
+	wg.Wait()
+}