Skip to content

Commit

Permalink
runNTimes will do iterations and goroutines
Browse files Browse the repository at this point in the history
  • Loading branch information
prashantv committed Jul 27, 2016
1 parent 56f315d commit 3223491
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,17 +283,13 @@ func TestLoggerConcurrent(t *testing.T) {
jl2 := jl.With(String("foo", "bar"))

wg := &sync.WaitGroup{}
runNTimes(5, wg, func() {
for i := 0; i < 10; i++ {
jl.Info("info", String("foo", "bar"))
jl.Info("info", String("foo", "bar"))
}
runNTimes(5 /* goroutines */, 10 /* iterations */, wg, func() {
jl.Info("info", String("foo", "bar"))
jl.Info("info", String("foo", "bar"))
})
runNTimes(5, wg, func() {
for i := 0; i < 10; i++ {
jl2.Info("info")
jl2.Info("info")
}
runNTimes(5 /* goroutines */, 10 /* iterations */, wg, func() {
jl2.Info("info")
jl2.Info("info")
})

wg.Wait()
Expand All @@ -304,12 +300,14 @@ func TestLoggerConcurrent(t *testing.T) {
})
}

func runNTimes(n int, wg *sync.WaitGroup, f func()) {
wg.Add(n)
for i := 0; i < n; i++ {
func runNTimes(goroutines, iterations int, wg *sync.WaitGroup, f func()) {
wg.Add(goroutines)
for g := 0; g < goroutines; g++ {
go func() {
defer wg.Done()
f()
for i := 0; i < iterations; i++ {
f()
}
}()
}
}

0 comments on commit 3223491

Please sign in to comment.