Skip to content

Commit

Permalink
Fix: argument order in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasheartman committed Oct 31, 2023
1 parent b8b0cbe commit 755e645
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions src/strategy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,6 @@ pub fn partial_rollout(group: &str, variable: Option<&String>, rollout: u32) ->
}
}

const VARIANT_NORMALIZATION_SEED: u32 = 86028157;

/// Calculates a hash in the standard way expected for Unleash clients. Not
/// required for extension strategies, but reusing this is probably a good idea
/// for consistency across implementations.
Expand All @@ -129,16 +127,13 @@ pub fn normalised_hash(group: &str, identifier: &str, modulus: u32) -> std::io::
normalised_hash_internal(group, identifier, modulus, 0)
}

const VARIANT_NORMALIZATION_SEED: u32 = 86028157;

pub fn normalised_variant_hash(
group: &str,
identifier: &str,
modulus: u32,
) -> std::io::Result<u32> {
// See https://github.com/stusmall/murmur3/pull/16 : .chain may avoid
// copying in the general case, and may be faster (though perhaps
// benchmarking would be useful - small datasizes here could make the best
// path non-obvious) - but until murmur3 is fixed, we need to provide it
// with a single string no matter what.
normalised_hash_internal(group, identifier, modulus, VARIANT_NORMALIZATION_SEED)
}

Expand All @@ -149,7 +144,7 @@ fn normalised_hash_internal(
seed: u32,
) -> std::io::Result<u32> {
let mut reader = Cursor::new(format!("{}:{}", &group, &identifier));
murmur3_32(&mut reader, seed).map(|hash_result| hash_result % modulus)
murmur3_32(&mut reader, seed).map(|hash_result| (hash_result % modulus) + 1)
}

// Build a closure to handle session id rollouts, parameterised by groupId and a
Expand Down Expand Up @@ -888,19 +883,19 @@ mod tests {

#[test]
fn test_normalized_hash() {
assert_eq!(73, super::normalised_hash("123", "gr1", 100).unwrap());
assert_eq!(25, super::normalised_hash("999", "groupX", 100).unwrap());
assert_eq!(73, super::normalised_hash("gr1", "123", 100).unwrap());
assert_eq!(25, super::normalised_hash("groupX", "999", 100).unwrap());
}

#[test]
fn test_normalised_variant_hash() {
assert_eq!(
96,
super::normalised_variant_hash("123", "gr1", 100).unwrap()
super::normalised_variant_hash("gr1", "123", 100).unwrap()
);
assert_eq!(
60,
super::normalised_variant_hash("999", "groupX", 100).unwrap()
super::normalised_variant_hash("groupX", "999", 100).unwrap()
);
}
}

0 comments on commit 755e645

Please sign in to comment.