github.com/go-kit/log@v0.2.1/concurrency_test.go (about) 1 package log_test 2 3 import ( 4 "math" 5 "testing" 6 7 "github.com/go-kit/log" 8 ) 9 10 // These test are designed to be run with the race detector. 11 12 func testConcurrency(t *testing.T, logger log.Logger, total int) { 13 n := int(math.Sqrt(float64(total))) 14 share := total / n 15 16 errC := make(chan error, n) 17 18 for i := 0; i < n; i++ { 19 go func() { 20 errC <- spam(logger, share) 21 }() 22 } 23 24 for i := 0; i < n; i++ { 25 err := <-errC 26 if err != nil { 27 t.Fatalf("concurrent logging error: %v", err) 28 } 29 } 30 } 31 32 func spam(logger log.Logger, count int) error { 33 for i := 0; i < count; i++ { 34 err := logger.Log("key", i) 35 if err != nil { 36 return err 37 } 38 } 39 return nil 40 }