@@ -54,6 +54,7 @@ func testNewV1(t *testing.T) {
5454 t .Run ("MissingNetworkFaultyRand" , testNewV1MissingNetworkFaultyRand )
5555 t .Run ("MissingNetworkFaultyRandWithOptions" , testNewV1MissingNetworkFaultyRandWithOptions )
5656 t .Run ("AtSpecificTime" , testNewV1AtTime )
57+ t .Run ("AtSpecificTimeClockSequenceWrap" , testNewV1AtTimeClockSequenceWrap )
5758}
5859
5960func TestNewGenWithHWAF (t * testing.T ) {
@@ -273,6 +274,35 @@ func testNewV1AtTime(t *testing.T) {
273274 }
274275}
275276
277+ func testNewV1AtTimeClockSequenceWrap (t * testing.T ) {
278+ atTime := time .Unix (0 , 1000000 )
279+
280+ g := NewGenWithOptions (
281+ WithHWAddrFunc (func () (net.HardwareAddr , error ) {
282+ return net.HardwareAddr {0 , 1 , 2 , 3 , 4 , 5 }, nil
283+ }),
284+ WithEpochFunc (func () time.Time {
285+ return time .Unix (0 , 2000000 )
286+ }),
287+ WithRandomReader (bytes .NewReader ([]byte {0x00 , 0x00 })),
288+ )
289+
290+ const total = 0x3fff + 3
291+ seen := make (map [UUID ]int , total )
292+
293+ for i := 0 ; i < total ; i ++ {
294+ u , err := g .NewV1AtTime (atTime )
295+ if err != nil {
296+ t .Fatalf ("g.NewV1AtTime() err = %v, want <nil>" , err )
297+ }
298+
299+ if prev , ok := seen [u ]; ok {
300+ t .Fatalf ("duplicate UUID at iteration %d (previous %d): %s" , i , prev , u )
301+ }
302+ seen [u ] = i
303+ }
304+ }
305+
276306func testNewV1FaultyRandWithOptions (t * testing.T ) {
277307 g := NewGenWithOptions (WithRandomReader (& faultyReader {
278308 readToFail : 0 , // fail immediately
0 commit comments