We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 514337d commit 5774cb0Copy full SHA for 5774cb0
03_singleton/singleton_test.go
@@ -1,11 +1,26 @@
1
package singleton
2
3
-import "testing"
+import (
4
+ "sync"
5
+ "testing"
6
+)
7
+
8
+const count = 100
9
10
func TestSingleton(t *testing.T) {
- ins1 := GetInstance()
- ins2 := GetInstance()
- if ins1 != ins2 {
- t.Fatal("instance is not equal")
11
+ wg := sync.WaitGroup{}
12
+ wg.Add(count)
13
+ instances := [count]*Singleton{}
14
+ for i := 0; i < count; i++ {
15
+ go func(index int) {
16
+ instances[index] = GetInstance()
17
+ wg.Done()
18
+ }(i)
19
+ }
20
+ wg.Wait()
21
+ for i := 1; i < count; i++ {
22
+ if instances[i] != instances[i-1] {
23
+ t.Fatal("instance is not equal")
24
25
}
26
0 commit comments