Skip to content

Commit 09ca01f

Browse files
pomo16senghoo
authored andcommitted
fix parallel test
1 parent fb3e973 commit 09ca01f

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

03_singleton/singleton_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,18 @@ func TestSingleton(t *testing.T) {
1616
}
1717

1818
func TestParallelSingleton(t *testing.T) {
19+
start := make(chan struct{})
1920
wg := sync.WaitGroup{}
2021
wg.Add(parCount)
2122
instances := [parCount]*Singleton{}
2223
for i := 0; i < parCount; i++ {
2324
go func(index int) {
25+
<-start
2426
instances[index] = GetInstance()
2527
wg.Done()
2628
}(i)
2729
}
30+
close(start)
2831
wg.Wait()
2932
for i := 1; i < parCount; i++ {
3033
if instances[i] != instances[i-1] {

0 commit comments

Comments
 (0)