snapshot of https://github.com/ThreeDotsLabs/watermill.git (master, 2026-09-15; blobs > 131072B omitted)
Some checks failed
master / ci (push) Failing after 0s

This commit is contained in:
upstream-mirror
2026-09-15 21:27:46 +05:00
commit ce933d1277
538 changed files with 46504 additions and 0 deletions

57
uuid_test.go Normal file
View File

@@ -0,0 +1,57 @@
package watermill_test
import (
"sync"
"testing"
"github.com/ThreeDotsLabs/watermill"
)
func testUniqueness(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) {
testUniqueness(t, watermill.NewUUID)
}
func TestShortUUID(t *testing.T) {
testUniqueness(t, watermill.NewShortUUID)
}
func TestULID(t *testing.T) {
testUniqueness(t, watermill.NewULID)
}