Skip to content

Commit

Permalink
fix parallel test
Browse files Browse the repository at this point in the history
  • Loading branch information
pomo16 authored and senghoo committed Nov 3, 2020
1 parent fb3e973 commit 09ca01f
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions 03_singleton/singleton_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@ func TestSingleton(t *testing.T) {
}

func TestParallelSingleton(t *testing.T) {
start := make(chan struct{})
wg := sync.WaitGroup{}
wg.Add(parCount)
instances := [parCount]*Singleton{}
for i := 0; i < parCount; i++ {
go func(index int) {
<-start
instances[index] = GetInstance()
wg.Done()
}(i)
}
close(start)
wg.Wait()
for i := 1; i < parCount; i++ {
if instances[i] != instances[i-1] {
Expand Down

0 comments on commit 09ca01f

Please sign in to comment.