[PR Feedback] Use hcore::env for bypass variable check
Only a non-empty value should be accepted. This is in line with the
rest of our environment variable handling.
@@ -24,7 +24,7 @@ use time::Duration;
use butterfly;
use common::ui::UI;
-use env;
+use hcore::env as henv;
use hcore::package::{PackageIdent, PackageInstall, PackageTarget};
use hcore::service::ServiceGroup;
use launcher_client::LauncherCli;
@@ -400,15 +400,11 @@ impl Periodic for Worker {
// instead of re-checking every time.
fn update_period(&self) -> Duration {
let val = ServiceUpdatePeriod::configured_value().into();
- if val < *MIN_ALLOWED_PERIOD {
- if env::var(PERIOD_BYPASS_CHECK_ENVVAR).is_ok() {
+ if val >= *MIN_ALLOWED_PERIOD || henv::var(PERIOD_BYPASS_CHECK_ENVVAR).is_ok() {
val
} else {
*MIN_ALLOWED_PERIOD
}
- } else {
- val
- }
}
}
@@ -594,6 +590,19 @@ mod tests {
assert!(ServiceUpdatePeriod::from_str("5").is_ok());
}
+ #[test]
+ fn worker_period_must_be_bypassed_by_non_empty_value() {
+ let period = lock_period_var();
+ let bypass = lock_bypass_var();
+ let worker = worker();
+
+ period.set("123");
+ bypass.set(""); // empty string isn't allowed
+
+ assert_ne!(worker.update_period(), Duration::milliseconds(123));
+ assert_eq!(ServiceUpdatePeriod::default(), worker.update_period());
+ }
+
#[test]
fn worker_period_defaults_properly() {
let period = lock_period_var();
