Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rust WorkUnit span_id bug #8129

Merged
merged 1 commit into from Aug 1, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/rust/engine/workunit_store/src/lib.rs
Expand Up @@ -67,7 +67,11 @@ impl WorkUnitStore {
pub fn generate_random_64bit_string() -> String {
let mut rng = thread_rng();
let random_u64: u64 = rng.gen();
format!("{:16.x}", random_u64)
hex_16_digit_string(random_u64)
}

fn hex_16_digit_string(number: u64) -> String {
format!("{:016.x}", number)
}

pub fn workunits_with_constant_span_id(workunit_store: &WorkUnitStore) -> HashSet<WorkUnit> {
Expand Down Expand Up @@ -100,3 +104,18 @@ pub fn get_parent_id() -> Option<String> {
(*task_parent_id).clone()
})
}

#[cfg(test)]
mod tests {
use crate::hex_16_digit_string;

#[test]
fn workunit_span_id_has_16_digits_len_hex_format() {
let number: u64 = 1;
let hex_string = hex_16_digit_string(number);
assert_eq!(16, hex_string.len());
for ch in hex_string.chars() {
assert!(ch.is_ascii_hexdigit())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit is looking good to me.
Maybe the test could be a tad more stringent, for instance by verifying that the hex encoding turned out OK.
You could to this by taking a somewhat random u64, but writing it down in hex with the 0x prefix, so it's easy to visually check the correctness.
So something like this:

assert_eq("0123456789abcdef", hex_16_digit_string(0x0123456789abcdef));

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since things were green, I went ahead and merged. Can discuss expanding this in a followup. Thanks!

}
}
}