mirror of
https://github.com/facebook/sapling.git
synced 2024-10-10 00:45:18 +03:00
tunables: fix ByRepoBool to allow more than 1 tunable
Summary: Please see added test. Without this diff such test does not even compile, as `new_values_by_repo` is moved out by `self.#names.swap(Arc::new(new_values_by_repo));` after processing the first tunable (line 202). Reviewed By: StanislavGlebik Differential Revision: D26168371 fbshipit-source-id: 3cd9d77b72554eb97927662bc631611fa91eaecb
This commit is contained in:
parent
1b71b6af3d
commit
f0f9bc10ba
@ -19,4 +19,5 @@ slog = { version = "2.5", features = ["max_level_debug"] }
|
||||
|
||||
[dev-dependencies]
|
||||
fbinit = { git = "https://github.com/facebookexperimental/rust-shed.git", branch = "master", version = "0.1.0" }
|
||||
maplit = "1.0"
|
||||
tokio-compat = "0.1"
|
||||
|
@ -237,6 +237,7 @@ pub fn with_tunables_async<Out, Fut: Future<Output = Out> + Unpin>(
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use maplit::hashmap;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::atomic::AtomicBool;
|
||||
|
||||
@ -247,6 +248,7 @@ mod test {
|
||||
string: TunableString,
|
||||
|
||||
repobool: TunableBoolByRepo,
|
||||
repobool2: TunableBoolByRepo,
|
||||
}
|
||||
|
||||
#[derive(Tunables, Default)]
|
||||
@ -352,6 +354,35 @@ mod test {
|
||||
assert_eq!(test.get_by_repo_repobool(&"repo".to_string()), Some(false));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn update_by_repo_two_bools() {
|
||||
let test = TestTunables::default();
|
||||
assert_eq!(test.get_by_repo_repobool(&"repo".to_string()), None);
|
||||
assert_eq!(test.get_by_repo_repobool2(&"repo".to_string()), None);
|
||||
|
||||
let r = hashmap! {
|
||||
"repo".to_string() => hashmap! {
|
||||
"repobool".to_string() => true,
|
||||
"repobool2".to_string() => true,
|
||||
}
|
||||
};
|
||||
test.update_by_repo_bools(&r);
|
||||
|
||||
assert_eq!(test.get_by_repo_repobool(&"repo".to_string()), Some(true));
|
||||
assert_eq!(test.get_by_repo_repobool2(&"repo".to_string()), Some(true));
|
||||
|
||||
let r = hashmap! {
|
||||
"repo".to_string() => hashmap! {
|
||||
"repobool".to_string() => true,
|
||||
"repobool2".to_string() => false,
|
||||
}
|
||||
};
|
||||
test.update_by_repo_bools(&r);
|
||||
|
||||
assert_eq!(test.get_by_repo_repobool(&"repo".to_string()), Some(true));
|
||||
assert_eq!(test.get_by_repo_repobool2(&"repo".to_string()), Some(false));
|
||||
}
|
||||
|
||||
#[fbinit::compat_test]
|
||||
async fn test_with_tunables_async(_fb: fbinit::FacebookInit) {
|
||||
let res = with_tunables_async(
|
||||
|
@ -187,8 +187,8 @@ where
|
||||
}
|
||||
TunableType::ByRepoBool => {
|
||||
body.extend(quote! {
|
||||
let mut new_values_by_repo: HashMap<String, bool> = HashMap::new();
|
||||
#(
|
||||
let mut new_values_by_repo: HashMap<String, bool> = HashMap::new();
|
||||
for (repo, val_by_tunable) in tunables {
|
||||
for (tunable, val) in val_by_tunable {
|
||||
match tunable.as_ref() {
|
||||
|
Loading…
Reference in New Issue
Block a user