Merge pull request #705 from fef1312/main

make ClockSequence wrap correctly
This commit is contained in:
Ashley Mannix 2023-08-16 15:55:28 +10:00 committed by GitHub
commit cef501931b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 5 deletions

View File

@ -438,7 +438,7 @@ pub mod context {
// increment the clock sequence we want to wrap once it becomes larger
// than what we can represent in a "u14". Otherwise there'd be patches
// where the clock sequence doesn't change regardless of the timestamp
self.count.fetch_add(1, Ordering::AcqRel) % (u16::MAX >> 2)
self.count.fetch_add(1, Ordering::AcqRel) & (u16::MAX >> 2)
}
}
}

View File

@ -178,7 +178,7 @@ mod tests {
let node = [1, 2, 3, 4, 5, 6];
// This context will wrap
let context = Context::new((u16::MAX >> 2) - 1);
let context = Context::new(u16::MAX >> 2);
let uuid1 = Uuid::new_v1(Timestamp::from_unix(&context, time, time_fraction), &node);
@ -186,7 +186,7 @@ mod tests {
let uuid2 = Uuid::new_v1(Timestamp::from_unix(&context, time, time_fraction), &node);
assert_eq!(uuid1.get_timestamp().unwrap().to_rfc4122().1, 16382);
assert_eq!(uuid1.get_timestamp().unwrap().to_rfc4122().1, 16383);
assert_eq!(uuid2.get_timestamp().unwrap().to_rfc4122().1, 0);
let time = 1_496_854_535;

View File

@ -180,7 +180,7 @@ mod tests {
let node = [1, 2, 3, 4, 5, 6];
// This context will wrap
let context = Context::new((u16::MAX >> 2) - 1);
let context = Context::new(u16::MAX >> 2);
let uuid1 = Uuid::new_v6(Timestamp::from_unix(&context, time, time_fraction), &node);
@ -188,7 +188,7 @@ mod tests {
let uuid2 = Uuid::new_v6(Timestamp::from_unix(&context, time, time_fraction), &node);
assert_eq!(uuid1.get_timestamp().unwrap().to_rfc4122().1, 16382);
assert_eq!(uuid1.get_timestamp().unwrap().to_rfc4122().1, 16383);
assert_eq!(uuid2.get_timestamp().unwrap().to_rfc4122().1, 0);
let time = 1_496_854_535;