Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions services/common/src/e2e/proof_routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,46 @@ impl Plan {
}
}

/// Most repeat runs one proof asks for.
pub const MAX_REPEAT: u32 = 300;

/// How many runs the proof asks for: the count measured from the test's
/// own failure rate when the run has one (`e2e::fix_evidence`'s
/// `repeats_for`, which floors and caps it), else what the review asked
/// (`asked`). The one place the plan's count is chosen, so the measured
/// count and the routes never disagree.
pub fn repeat_count(asked: u32, measured: Option<u32>) -> u32 {
measured.unwrap_or(asked).clamp(1, MAX_REPEAT)
}

/// The plan's runs as counts for the test's evidence: runs that passed or
/// failed on the page, and routes that never reached it (refused by the
/// network, no address, no start script), which are never failures.
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct Tally {
pub passed: u32,
pub failed: u32,
pub not_reached: u32,
}

impl Plan {
pub fn tally(&self) -> Tally {
let mut t = Tally::default();
for a in &self.attempts {
match &a.outcome {
Outcome::Passed { runs } => t.passed += runs,
Outcome::Failed { passed, failed, .. } => {
t.passed += passed;
t.failed += failed;
}
Outcome::Unavailable { .. } => t.not_reached += 1,
Outcome::Started { .. } => {}
}
}
t
}
}

/// A sandbox route's output as an outcome: refused by the network or never
/// started is the route being unavailable; counts are a result.
pub fn outcome_of(output: &str, repeat: u32) -> Outcome {
Expand Down Expand Up @@ -864,6 +904,31 @@ mod tests {
assert!(pre.contains("npm run 'dev'") && pre.contains("127.0.0.1:4000"));
}

#[test]
fn the_measured_count_wins_and_routes_that_never_reached_the_page_are_not_failures() {
assert_eq!(repeat_count(20, None), 20);
assert_eq!(repeat_count(20, Some(45)), 45);
assert_eq!(repeat_count(20, Some(5000)), MAX_REPEAT);
let mut p = Plan::new("abc1234def", &[TEST.to_string()], 20);
p.record(
Route::Preview,
outcome_of(
"CODERHELM_EGRESS_BLOCKED pr-7.preview-web.acme-books.example\n 20 failed\n",
20,
),
"t",
);
p.record(Route::Staging, outcome_of(" 20 passed (40s)\n", 20), "t");
assert_eq!(
p.tally(),
Tally {
passed: 20,
failed: 0,
not_reached: 1
}
);
}

#[test]
fn the_repeat_asked_is_read_from_the_finding() {
assert_eq!(
Expand Down
7 changes: 6 additions & 1 deletion services/worker/src/passes/pr_watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,12 @@ async fn prove_owed(
return Performed::Settled;
}
let tests = owed_tests(state, c, &items).await;
let repeat = routes::repeat_asked(&items.join(" "), common::e2e::test_package::REPEAT_RUNS);
// The review's count; a count measured from the test's own failure
// rate goes in as `measured` (`routes::repeat_count`).
let repeat = routes::repeat_count(
routes::repeat_asked(&items.join(" "), common::e2e::test_package::REPEAT_RUNS),
None,
);
let target = super::ci_repro::Target {
team_id: &c.team_id,
run_id: &c.run_id,
Expand Down
2 changes: 1 addition & 1 deletion services/worker/src/passes/test_fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2919,7 +2919,7 @@ pub async fn ready_gate(
head: &sha,
},
&tests,
test_package::REPEAT_RUNS,
common::e2e::proof_routes::repeat_count(test_package::REPEAT_RUNS, None),
)
.await;
repeat_ok = match plan.verdict() {
Expand Down