File tree Expand file tree Collapse file tree 1 file changed +14
-5
lines changed Expand file tree Collapse file tree 1 file changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -5,22 +5,31 @@ import (
5
5
"testing"
6
6
)
7
7
8
- const count = 100
8
+ const parCount = 100
9
9
10
10
func TestSingleton (t * testing.T ) {
11
+ ins1 := GetInstance ()
12
+ ins2 := GetInstance ()
13
+ if ins1 != ins2 {
14
+ t .Fatal ("instance is not equal" )
15
+ }
16
+ }
17
+
18
+ func TestParallelSingleton (t * testing.T ) {
11
19
wg := sync.WaitGroup {}
12
- wg .Add (count )
13
- instances := [count ]* Singleton {}
14
- for i := 0 ; i < count ; i ++ {
20
+ wg .Add (parCount )
21
+ instances := [parCount ]* Singleton {}
22
+ for i := 0 ; i < parCount ; i ++ {
15
23
go func (index int ) {
16
24
instances [index ] = GetInstance ()
17
25
wg .Done ()
18
26
}(i )
19
27
}
20
28
wg .Wait ()
21
- for i := 1 ; i < count ; i ++ {
29
+ for i := 1 ; i < parCount ; i ++ {
22
30
if instances [i ] != instances [i - 1 ] {
23
31
t .Fatal ("instance is not equal" )
24
32
}
25
33
}
26
34
}
35
+
You can’t perform that action at this time.
0 commit comments