hive-c0re: queue another knowledge pull soon after a failed one, backing off to 5 minutes
This commit is contained in:
parent
52ba0a996f
commit
530137a7bb
1 changed files with 298 additions and 19 deletions
|
|
@ -11,15 +11,17 @@ use hive_jobq::NodeId;
|
|||
use hive_jobq::scheduler::Scheduler;
|
||||
|
||||
use super::{
|
||||
Host, dispatch, run_create, run_destroy_bookkeeping, run_destroy_container, run_drain,
|
||||
run_emit_rebuilt, run_knowledge_pull, run_meta_sync, run_pause_drain, run_pause_signal,
|
||||
run_prebuild, run_provision, run_purge_state, run_rebuild_bookkeeping, run_reconcile,
|
||||
run_set_wanted, run_signal, run_start, run_stop, run_stop_for_update, run_swap,
|
||||
run_wanted_pull, run_write_dropin,
|
||||
Host, KNOWLEDGE_WARN_AFTER, PullRetry, dispatch, run_create, run_destroy_bookkeeping,
|
||||
run_destroy_container, run_drain, run_emit_rebuilt, run_knowledge_pull, run_meta_sync,
|
||||
run_pause_drain, run_pause_signal, run_prebuild, run_provision, run_purge_state,
|
||||
run_rebuild_bookkeeping, run_reconcile, run_set_wanted, run_signal, run_start, run_stop,
|
||||
run_stop_for_update, run_swap, run_wanted_pull, run_write_dropin,
|
||||
};
|
||||
use crate::coordinator::{AgentPaths, Coordinator, HiveEnv};
|
||||
use crate::job_queue::model::NodeKind;
|
||||
use crate::power::Wanted;
|
||||
use crate::stats::sweep_health::SweepHealth;
|
||||
use crate::warnings::snapshot;
|
||||
use swarm_wire::agent_closures::AgentClosure;
|
||||
|
||||
const REV: &str = "2222222222222222222222222222222222222222";
|
||||
|
|
@ -1056,16 +1058,30 @@ async fn emit_rebuilt_reports_success_and_failure_under_one_key() {
|
|||
|
||||
// --- Sweeps and pulls ---------------------------------------------------------
|
||||
|
||||
/// A pull's health tracker, as production builds it, under a `kind` of its own
|
||||
/// so tests do not share the warning.
|
||||
fn pull_health(kind: &'static str) -> Mutex<SweepHealth> {
|
||||
Mutex::new(SweepHealth::new(kind, "warn", KNOWLEDGE_WARN_AFTER))
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn knowledge_pull_passes_the_result_through_and_times_out() {
|
||||
static RETRY: PullRetry = PullRetry::new();
|
||||
let health = pull_health("pull_result");
|
||||
let (_dir, coord) = coordinator();
|
||||
let secs = Duration::from_secs(5);
|
||||
run_knowledge_pull(&FakeHost::up(), &coord, secs)
|
||||
run_knowledge_pull(&FakeHost::up(), &coord, secs, &health, &RETRY)
|
||||
.await
|
||||
.expect("ok");
|
||||
let err = run_knowledge_pull(&FakeHost::up().failing("knowledge_pull"), &coord, secs)
|
||||
.await
|
||||
.expect_err("pull fails");
|
||||
let err = run_knowledge_pull(
|
||||
&FakeHost::up().failing("knowledge_pull"),
|
||||
&coord,
|
||||
secs,
|
||||
&health,
|
||||
&RETRY,
|
||||
)
|
||||
.await
|
||||
.expect_err("pull fails");
|
||||
assert!(
|
||||
format!("{err:#}").contains("knowledge_pull failed"),
|
||||
"{err:#}"
|
||||
|
|
@ -1074,12 +1090,144 @@ async fn knowledge_pull_passes_the_result_through_and_times_out() {
|
|||
hang: true,
|
||||
..FakeHost::up()
|
||||
};
|
||||
let err = run_knowledge_pull(&hang, &coord, Duration::from_millis(50))
|
||||
let err = run_knowledge_pull(&hang, &coord, Duration::from_millis(50), &health, &RETRY)
|
||||
.await
|
||||
.expect_err("deadline");
|
||||
assert!(format!("{err:#}").contains("timed out"), "{err:#}");
|
||||
}
|
||||
|
||||
fn queued_pulls(coord: &Arc<Coordinator>) -> usize {
|
||||
let sched = coord.job_queue.sched().lock().expect("job_queue mutex");
|
||||
sched
|
||||
.graph()
|
||||
.nodes()
|
||||
.filter(|n| matches!(n.payload, NodeKind::KnowledgePull))
|
||||
.count()
|
||||
}
|
||||
|
||||
/// A failed pull queues one more after the first retry wait, however many
|
||||
/// pulls fail meanwhile.
|
||||
#[tokio::test(start_paused = true)]
|
||||
async fn a_failed_pull_queues_one_retry_after_a_wait() {
|
||||
static RETRY: PullRetry = PullRetry::new();
|
||||
let health = pull_health("pull_retry");
|
||||
let (_dir, coord) = coordinator();
|
||||
let secs = Duration::from_secs(5);
|
||||
let failing = FakeHost::up().failing("knowledge_pull");
|
||||
run_knowledge_pull(&failing, &coord, secs, &health, &RETRY)
|
||||
.await
|
||||
.expect_err("pull fails");
|
||||
run_knowledge_pull(&failing, &coord, secs, &health, &RETRY)
|
||||
.await
|
||||
.expect_err("pull fails");
|
||||
tokio::time::sleep(Duration::from_secs(4)).await;
|
||||
assert_eq!(queued_pulls(&coord), 0, "queued before the wait ran out");
|
||||
tokio::time::sleep(Duration::from_secs(2)).await;
|
||||
assert_eq!(queued_pulls(&coord), 1, "one retry after the wait");
|
||||
}
|
||||
|
||||
/// A pull that succeeds queues nothing, and cancels the retry a failed one
|
||||
/// left waiting.
|
||||
#[tokio::test(start_paused = true)]
|
||||
async fn a_pull_that_succeeds_queues_no_retry() {
|
||||
static RETRY: PullRetry = PullRetry::new();
|
||||
let health = pull_health("pull_ok");
|
||||
let (_dir, coord) = coordinator();
|
||||
let secs = Duration::from_secs(5);
|
||||
run_knowledge_pull(&FakeHost::up(), &coord, secs, &health, &RETRY)
|
||||
.await
|
||||
.expect("ok");
|
||||
run_knowledge_pull(
|
||||
&FakeHost::up().failing("knowledge_pull"),
|
||||
&coord,
|
||||
secs,
|
||||
&health,
|
||||
&RETRY,
|
||||
)
|
||||
.await
|
||||
.expect_err("pull fails");
|
||||
run_knowledge_pull(&FakeHost::up(), &coord, secs, &health, &RETRY)
|
||||
.await
|
||||
.expect("ok");
|
||||
tokio::time::sleep(Duration::from_mins(10)).await;
|
||||
assert_eq!(queued_pulls(&coord), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_retry_wait_doubles_up_to_its_cap_and_starts_over_after_a_success() {
|
||||
let retry = PullRetry::new();
|
||||
let mut waits = Vec::new();
|
||||
for _ in 0..8 {
|
||||
let (wait, generation) = retry.record_err().expect("no retry is waiting");
|
||||
waits.push(wait.as_secs());
|
||||
assert!(retry.queued(generation));
|
||||
}
|
||||
assert_eq!(waits, [5, 10, 20, 40, 80, 160, 300, 300]);
|
||||
retry.record_ok();
|
||||
let first = retry.record_err().map(|(wait, _)| wait.as_secs());
|
||||
assert_eq!(first, Some(5));
|
||||
assert_eq!(retry.record_err(), None, "a retry is already waiting");
|
||||
}
|
||||
|
||||
/// A retry that a success has cancelled does not queue, and does not stop the
|
||||
/// next failure from scheduling its own.
|
||||
#[test]
|
||||
fn a_success_cancels_the_waiting_retry() {
|
||||
let retry = PullRetry::new();
|
||||
let (_, stale) = retry.record_err().expect("first retry");
|
||||
retry.record_ok();
|
||||
let (_, current) = retry.record_err().expect("a new retry after the success");
|
||||
assert!(!retry.queued(stale), "the cancelled retry queued a pull");
|
||||
assert!(retry.queued(current));
|
||||
}
|
||||
|
||||
/// The warning waits for a failure that has lasted minutes, which the first
|
||||
/// few quick retries are not: the forge still starting at boot raises nothing.
|
||||
#[tokio::test]
|
||||
async fn the_warning_waits_for_a_sustained_failure() {
|
||||
static RETRY: PullRetry = PullRetry::new();
|
||||
let health = pull_health("pull_warning");
|
||||
let (_dir, coord) = coordinator();
|
||||
let failing = FakeHost::up().failing("knowledge_pull");
|
||||
let raised = || snapshot().iter().any(|w| w.kind == "pull_warning");
|
||||
// The first three quick failures, then the rest short of the threshold.
|
||||
for _ in (1..=3).chain(4..KNOWLEDGE_WARN_AFTER) {
|
||||
run_knowledge_pull(&failing, &coord, Duration::from_secs(5), &health, &RETRY)
|
||||
.await
|
||||
.expect_err("pull fails");
|
||||
assert!(!raised(), "raised before the failure was sustained");
|
||||
}
|
||||
run_knowledge_pull(&failing, &coord, Duration::from_secs(5), &health, &RETRY)
|
||||
.await
|
||||
.expect_err("pull fails");
|
||||
assert!(raised(), "not raised after a sustained failure");
|
||||
run_knowledge_pull(
|
||||
&FakeHost::up(),
|
||||
&coord,
|
||||
Duration::from_secs(5),
|
||||
&health,
|
||||
&RETRY,
|
||||
)
|
||||
.await
|
||||
.expect("ok");
|
||||
assert!(!raised(), "not cleared by the next success");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_seventh_failure_comes_minutes_after_the_first() {
|
||||
let retry = PullRetry::new();
|
||||
let mut elapsed = Duration::ZERO;
|
||||
for _ in 1..KNOWLEDGE_WARN_AFTER {
|
||||
let (wait, generation) = retry.record_err().expect("no retry is waiting");
|
||||
elapsed += wait;
|
||||
assert!(retry.queued(generation));
|
||||
}
|
||||
assert!(
|
||||
elapsed >= Duration::from_mins(5),
|
||||
"the warning would come after {elapsed:?}"
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn wanted_pull_passes_the_result_through() {
|
||||
let (_dir, coord) = coordinator();
|
||||
|
|
|
|||
Loading…
Reference in a new issue