use super::*;
#[tokio::test(start_paused = true)]
async fn trigger_routes_to_the_flock_and_reports_each_match_within_the_budget() {
let h = harness(vec![ProcScript::never_exits(), ProcScript::never_exits()]);
let mut web = AppConfig::minimal("web", "./srv");
web.channel = true;
let started = reply_of(
dispatch(
envelope(
1,
Request::Start {
apps: vec![AppConfig::minimal("other", "./o"), web],
},
),
&h.ctx,
)
.await,
);
let Response::Started(started) = started.result.unwrap() else {
panic!("expected started")
};
let web_id = started
.iter()
.find(|i| i.name == "web")
.expect("web registered")
.id;
assert_ne!(web_id, 0, "the test's own premise: web must not be id 0");
let reply = reply_of(
dispatch(
envelope(
2,
Request::Trigger {
selector: SelectorSpec::Name("web".to_string()),
action: "gc".to_string(),
params: None,
},
),
&h.ctx,
)
.await,
);
let Response::Triggered(rows) = reply.result.unwrap() else {
panic!("expected triggered")
};
assert_eq!(
rows,
vec![ActionReply {
id: web_id,
name: "web".to_string(),
outcome: ActionOutcome::TimedOut,
}]
);
}
#[tokio::test]
async fn a_signal_name_outside_the_grammar_is_refused_with_the_accepted_list() {
let h = harness(vec![]);
let reply = reply_of(
dispatch(
envelope(
1,
Request::Signal {
selector: SelectorSpec::All,
signal: "SIGHUPP".to_string(),
},
),
&h.ctx,
)
.await,
);
let err = reply.result.unwrap_err();
assert_eq!(err.code, RpcErrorCode::InvalidConfig);
assert!(err.message.contains("SIGHUPP"), "{}", err.message);
assert!(err.message.contains("SIGHUP"), "{}", err.message);
assert!(err.message.contains("SIGUSR2"), "{}", err.message);
}
#[tokio::test]
async fn a_line_carrying_a_newline_is_refused_before_it_reaches_the_supervisor() {
let h = harness(vec![]);
let reply = reply_of(
dispatch(
envelope(
1,
Request::SendLine {
selector: SelectorSpec::All,
line: "reload\nrm -rf /".to_string(),
},
),
&h.ctx,
)
.await,
);
let err = reply.result.unwrap_err();
assert_eq!(err.code, RpcErrorCode::InvalidConfig);
assert!(err.message.contains("newline"), "{}", err.message);
}
#[tokio::test(start_paused = true)]
async fn an_oversized_action_timeout_loses_the_race() {
let h = harness(vec![ProcScript::never_exits()]);
let mut web = AppConfig::minimal("web", "./srv");
web.channel = true;
web.action_timeout = UpDuration::from_millis(9_000); reply_of(dispatch(envelope(1, Request::Start { apps: vec![web] }), &h.ctx).await);
let reply = reply_of(
dispatch(
envelope(
2,
Request::Trigger {
selector: SelectorSpec::Name("web".to_string()),
action: "gc".to_string(),
params: None,
},
),
&h.ctx,
)
.await,
);
assert_eq!(
reply.result.unwrap_err().code,
RpcErrorCode::DeadlineExceeded,
"an action_timeout past the caller's default budget must lose that race, not \
report an honest TimedOut row nobody can reach"
);
}
#[tokio::test(start_paused = true)]
async fn a_bad_trigger_selector_is_invalid_config() {
let h = harness(vec![]);
let reply = reply_of(
dispatch(
envelope(
1,
Request::Trigger {
selector: SelectorSpec::Regex("((".to_string()),
action: "gc".to_string(),
params: None,
},
),
&h.ctx,
)
.await,
);
assert_eq!(reply.result.unwrap_err().code, RpcErrorCode::InvalidConfig);
}
#[tokio::test(start_paused = true)]
async fn a_trigger_matching_nothing_is_not_found() {
let h = harness(vec![]);
let reply = reply_of(
dispatch(
envelope(
1,
Request::Trigger {
selector: SelectorSpec::Name("ghost".to_string()),
action: "gc".to_string(),
params: None,
},
),
&h.ctx,
)
.await,
);
assert_eq!(reply.result.unwrap_err().code, RpcErrorCode::NotFound);
}