Skip to content

Commit

Permalink
updates from code review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rjloura committed Mar 6, 2020
1 parent 7578c30 commit e4d9317
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 23 deletions.
2 changes: 1 addition & 1 deletion manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ signal-hook = "0.1.13"

[dev-dependencies]
# Unfortuantely there is a long standing bug in mustache version 0.9.0 that has
# fix which hasn't been integrated yet. We are only using this for testing so
# a fix which hasn't been integrated yet. We are only using this for testing so
# it should be fine to grab this crate from the branch for now.
# https://github.com/nickel-org/rust-mustache/issues/60
mustache = {git = "https://github.com/nickel-org/rust-mustache", branch = "issue-60" }
Expand Down
34 changes: 20 additions & 14 deletions manager/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ pub struct Shard {
pub struct Config {
pub domain_name: String,
pub shards: Vec<Shard>,
pub snaplinks_cleanup_required: Option<bool>,
#[serde(default)]
pub snaplinks_cleanup_required: bool,
}

impl Config {
Expand Down Expand Up @@ -379,11 +380,14 @@ fn _config_update_signal_handler(
// (i.e. TrySendError::Full), then the updater
// thread will be doing an update anyway so no
// sense in clogging things up further.
if let Err(TrySendError::Disconnected(_)) =
config_update_tx.try_send(())
{
warn!("config_update listener is closed");
break;
match config_update_tx.try_send(()) {
Err(TrySendError::Disconnected(_)) => {
warn!("config_update listener is closed");
break;
}
Ok(()) | Err(TrySendError::Full(_)) => {
continue;
}
}
}
_ => unreachable!(), // Ignore other signals
Expand Down Expand Up @@ -422,7 +426,8 @@ mod tests {
thread::spawn(move || {
let _guard = util::init_global_logger();
loop {
std::thread::sleep(std::time::Duration::from_millis(1))
// Loop around ::park() in the event of spurious wake ups.
std::thread::park();
}
});
}
Expand Down Expand Up @@ -491,7 +496,7 @@ mod tests {

let config = update_test_config_with_vars(&vars);

assert!(config.snaplinks_cleanup_required.is_none());
assert_eq!(config.snaplinks_cleanup_required, false);
}

#[test]
Expand All @@ -508,11 +513,12 @@ mod tests {
// Generate a config with snaplinks_cleanup_required=true.
let config = Arc::new(Mutex::new(config_init()));

assert!(config
.lock()
.expect("config lock")
.snaplinks_cleanup_required
.expect("Some SLCR"));
assert!(
config
.lock()
.expect("config lock")
.snaplinks_cleanup_required
);

let update_config = Arc::clone(&config);

Expand Down Expand Up @@ -543,7 +549,7 @@ mod tests {
// Assert that our in memory config's snaplinks_cleanup_required field
// has changed to false.
let check_config = config.lock().expect("config lock");
assert!(check_config.snaplinks_cleanup_required.is_none());
assert_eq!(check_config.snaplinks_cleanup_required, false);

config_fini();
}
Expand Down
14 changes: 6 additions & 8 deletions manager/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,12 @@ impl Handler for JobCreateHandler {
let domain_name = config.domain_name.clone();

// If snaplinks are still in play then we immediately return failure.
if let Some(sl_cleanup_req) = config.snaplinks_cleanup_required {
if sl_cleanup_req {
let error = invalid_server_error(
&state,
String::from("Snaplinks Cleanup Required"),
);
return Box::new(future::ok((state, error)));
}
if config.snaplinks_cleanup_required {
let error = invalid_server_error(
&state,
String::from("Snaplinks Cleanup Required"),
);
return Box::new(future::ok((state, error)));
}

let job_builder = JobBuilder::new(config);
Expand Down

0 comments on commit e4d9317

Please sign in to comment.