MCPcopy
hub / github.com/google/uuid / TestNewV6FromTimeGeneratesUniqueUUIDs

Function TestNewV6FromTimeGeneratesUniqueUUIDs

version6_test.go:42–67  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

40}
41
42func TestNewV6FromTimeGeneratesUniqueUUIDs(t *testing.T) {
43 now := time.Now()
44 ids := make([]string, 0)
45 runs := 26000
46
47 for i := 0; i < runs; i++ {
48 now = now.Add(time.Nanosecond) // Without this line, we can generate only 16384 UUIDs for the same timestamp
49 id, err := NewV6WithTime(&now)
50 if err != nil {
51 t.Errorf("NewV6WithTime returned unexpected error %v", err)
52 }
53 if id.Version() != 6 {
54 t.Errorf("got %d, want version 6", id.Version())
55 }
56
57 // Make sure we add only unique values
58 if !contains(t, ids, id.String()) {
59 ids = append(ids, id.String())
60 }
61 }
62
63 // Check we added all the UIDs
64 if len(ids) != runs {
65 t.Errorf("got %d UUIDs, want %d", len(ids), runs)
66 }
67}
68
69func BenchmarkNewV6WithTime(b *testing.B) {
70 b.RunParallel(func(pb *testing.PB) {

Callers

nothing calls this directly

Calls 4

NewV6WithTimeFunction · 0.85
containsFunction · 0.85
VersionMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected