-
Notifications
You must be signed in to change notification settings - Fork 410
/
uuid_test.go
57 lines (44 loc) · 1021 Bytes
/
uuid_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package watermill_test
import (
"sync"
"testing"
"github.com/ThreeDotsLabs/watermill"
)
func testuUniqness(t *testing.T, genFunc func() string) {
producers := 100
uuidsPerProducer := 10000
if testing.Short() {
producers = 10
uuidsPerProducer = 1000
}
uuidsCount := producers * uuidsPerProducer
uuids := make(chan string, uuidsCount)
allGenerated := sync.WaitGroup{}
allGenerated.Add(producers)
for i := 0; i < producers; i++ {
go func() {
for j := 0; j < uuidsPerProducer; j++ {
uuids <- genFunc()
}
allGenerated.Done()
}()
}
uniqueUUIDs := make(map[string]struct{}, uuidsCount)
allGenerated.Wait()
close(uuids)
for uuid := range uuids {
if _, ok := uniqueUUIDs[uuid]; ok {
t.Error(uuid, " has duplicate")
}
uniqueUUIDs[uuid] = struct{}{}
}
}
func TestUUID(t *testing.T) {
testuUniqness(t, watermill.NewUUID)
}
func TestShortUUID(t *testing.T) {
testuUniqness(t, watermill.NewShortUUID)
}
func TestULID(t *testing.T) {
testuUniqness(t, watermill.NewULID)
}