1use std::collections::BTreeMap;
44use std::path::Path;
45
46use crate::gate_stamp::{GateNames, Note, Run, RunOutcome};
47
48pub fn now() -> u64 {
52 std::time::SystemTime::now()
53 .duration_since(std::time::UNIX_EPOCH)
54 .map(|d| d.as_secs())
55 .unwrap_or(0)
56}
57
58#[derive(Debug, Clone, Default, PartialEq, Eq)]
65pub struct History {
66 pub runs: Vec<(String, Run)>,
67}
68
69impl History {
70 pub fn is_empty(&self) -> bool {
71 self.runs.is_empty()
72 }
73
74 fn within(&self, now: u64, window_days: u64) -> Vec<(&str, &Run)> {
77 let floor = if window_days == 0 {
78 0
79 } else {
80 now.saturating_sub(window_days.saturating_mul(86_400))
81 };
82 let mut runs: Vec<(&str, &Run)> = self
83 .runs
84 .iter()
85 .filter(|(_, r)| r.at >= floor)
86 .map(|(fp, r)| (fp.as_str(), r))
87 .collect();
88 runs.sort_by(|a, b| a.1.at.cmp(&b.1.at).then_with(|| a.1.gate.cmp(&b.1.gate)));
91 runs
92 }
93}
94
95pub fn history_in(repo: &Path) -> History {
103 history_under(repo, &crate::gate_stamp::WRITE)
107}
108
109fn history_under(repo: &Path, set: &GateNames) -> History {
111 let Some(list) = crate::git::stdout_in(repo, &["notes", "--ref", set.notes_ref, "list"]) else {
112 return History::default();
113 };
114 let mut keyed: BTreeMap<String, String> = BTreeMap::new();
117 let mut stdin = String::new();
118 for line in list.lines() {
119 let mut t = line.split_whitespace();
120 if let (Some(blob), Some(object)) = (t.next(), t.next()) {
121 keyed.insert(blob.to_string(), object.to_string());
122 stdin.push_str(blob);
123 stdin.push('\n');
124 }
125 }
126 if keyed.is_empty() {
127 return History::default();
128 }
129 let Some(batch) = crate::git::stdout_piped_in(repo, &["cat-file", "--batch"], stdin.as_bytes())
130 else {
131 return History::default();
132 };
133 let mut history = History::default();
134 for (blob, body) in parse_batch(&batch) {
135 let Some(fingerprint) = keyed.get(&blob) else {
136 continue;
137 };
138 for run in Note::parse_as(&body, set.format).runs {
139 history.runs.push((fingerprint.clone(), run));
140 }
141 }
142 history
143}
144
145fn parse_batch(out: &str) -> Vec<(String, String)> {
155 let mut found = Vec::new();
156 let mut current: Option<(String, Vec<&str>)> = None;
157 for line in out.lines() {
158 let mut t = line.split_whitespace();
159 let (oid, kind, size) = (t.next(), t.next(), t.next());
160 let is_header = matches!((oid, kind, size), (Some(o), Some("blob"), Some(s))
161 if o.len() >= 40
162 && o.chars().all(|c| c.is_ascii_hexdigit())
163 && s.parse::<u64>().is_ok()
164 && t.next().is_none());
165 if is_header {
166 if let Some((oid, body)) = current.take() {
167 found.push((oid, body.join("\n")));
168 }
169 current = Some((oid.unwrap_or_default().to_string(), Vec::new()));
170 continue;
171 }
172 if let Some((_, body)) = current.as_mut() {
173 body.push(line);
174 }
175 }
176 if let Some((oid, body)) = current.take() {
177 found.push((oid, body.join("\n")));
178 }
179 found
180}
181
182#[derive(Debug, Clone, Copy, PartialEq, Eq)]
185pub struct Thresholds {
186 pub window_days: u64,
188 pub min_runs: usize,
190 pub noop_ratio_percent: u64,
192 pub noop_median_secs: u64,
195 pub fast_pass_ms: u64,
198 pub stale_runs: usize,
201 pub stale_days: u64,
203}
204
205impl Default for Thresholds {
206 fn default() -> Self {
207 Thresholds {
208 window_days: 90,
209 min_runs: 5,
210 noop_ratio_percent: 10,
211 noop_median_secs: 30,
212 fast_pass_ms: 1_000,
213 stale_runs: 10,
214 stale_days: 30,
215 }
216 }
217}
218
219#[derive(Debug, Clone, Copy, PartialEq, Eq)]
220pub enum FlagKind {
221 NoOpSuspect,
223 Flaky,
225 Stale,
227}
228
229impl FlagKind {
230 pub fn as_str(self) -> &'static str {
231 match self {
232 FlagKind::NoOpSuspect => "no-op suspect",
233 FlagKind::Flaky => "flaky",
234 FlagKind::Stale => "stale",
235 }
236 }
237}
238
239#[derive(Debug, Clone, PartialEq, Eq)]
243pub struct Flag {
244 pub kind: FlagKind,
245 pub why: String,
246}
247
248#[derive(Debug, Clone, PartialEq, Eq)]
250pub struct GateReport {
251 pub gate: String,
252 pub runs: usize,
254 pub passed: usize,
255 pub failed: usize,
256 pub unavailable: usize,
260 pub median_ms: u64,
262 pub last_ms: u64,
263 pub last_at: u64,
264 pub last_outcome: Option<RunOutcome>,
265 pub fingerprints: usize,
267 pub missed: usize,
270 pub flags: Vec<Flag>,
271 pub abstained: Option<String>,
275}
276
277impl GateReport {
278 pub fn last_age_days(&self, now: u64) -> u64 {
280 now.saturating_sub(self.last_at) / 86_400
281 }
282}
283
284pub fn summarise(history: &History, now: u64, t: &Thresholds) -> Vec<GateReport> {
291 let runs = history.within(now, t.window_days);
292 let mut by_gate: BTreeMap<&str, Vec<(&str, &Run)>> = BTreeMap::new();
293 for &(fp, run) in &runs {
294 by_gate
295 .entry(run.gate.as_str())
296 .or_default()
297 .push((fp, run));
298 }
299 by_gate
300 .into_iter()
301 .map(|(gate, mine)| one_gate(gate, &mine, &runs, now, t))
302 .collect()
303}
304
305fn one_gate(
306 gate: &str,
307 mine: &[(&str, &Run)],
308 all: &[(&str, &Run)],
309 now: u64,
310 t: &Thresholds,
311) -> GateReport {
312 let verdicts: Vec<(&str, &Run)> = mine
313 .iter()
314 .filter(|(_, r)| r.outcome.is_verdict())
315 .copied()
316 .collect();
317 let passed = verdicts
318 .iter()
319 .filter(|(_, r)| r.outcome == RunOutcome::Passed)
320 .count();
321 let failed = verdicts.len() - passed;
322 let unavailable = mine
323 .iter()
324 .filter(|(_, r)| r.outcome == RunOutcome::Unavailable)
325 .count();
326 let median_ms = median(&verdicts.iter().map(|(_, r)| r.ms).collect::<Vec<_>>());
327 let last = mine.last().copied();
328 let mut fingerprints: Vec<&str> = mine.iter().map(|(fp, _)| *fp).collect();
329 fingerprints.sort_unstable();
330 fingerprints.dedup();
331
332 let last_at = last.map(|(_, r)| r.at).unwrap_or(0);
336 let mut later: Vec<&str> = all
337 .iter()
338 .filter(|(_, r)| r.at > last_at && r.gate != gate)
339 .map(|(fp, _)| *fp)
340 .collect();
341 later.sort_unstable();
342 later.dedup();
343 let missed = later
344 .iter()
345 .filter(|fp| !fingerprints.contains(*fp))
346 .count();
347
348 let mut report = GateReport {
349 gate: gate.to_string(),
350 runs: mine.len(),
351 passed,
352 failed,
353 unavailable,
354 median_ms,
355 last_ms: last.map(|(_, r)| r.ms).unwrap_or(0),
356 last_at,
357 last_outcome: last.map(|(_, r)| r.outcome),
358 fingerprints: fingerprints.len(),
359 missed,
360 flags: Vec::new(),
361 abstained: None,
362 };
363
364 if let Some(flag) = stale_flag(&report, all, now, t) {
368 report.flags.push(flag);
369 }
370
371 if verdicts.len() < t.min_runs {
372 report.abstained = Some(format!(
373 "insufficient history ({} verdict{})",
374 verdicts.len(),
375 if verdicts.len() == 1 { "" } else { "s" }
376 ));
377 return report;
378 }
379
380 if let Some(flag) = noop_flag(&verdicts, median_ms, t) {
381 report.flags.push(flag);
382 }
383 if let Some(flag) = flaky_flag(gate, &verdicts) {
384 report.flags.push(flag);
385 }
386 report
387}
388
389fn noop_flag(verdicts: &[(&str, &Run)], median_ms: u64, t: &Thresholds) -> Option<Flag> {
397 let (_, last) = *verdicts.last()?;
398 if median_ms >= t.noop_median_secs.saturating_mul(1_000)
399 && last.ms.saturating_mul(100) < median_ms.saturating_mul(t.noop_ratio_percent)
400 {
401 return Some(Flag {
402 kind: FlagKind::NoOpSuspect,
403 why: format!(
404 "last run {} against a median of {} ({}% of it, threshold {}%)",
405 duration(last.ms),
406 duration(median_ms),
407 last.ms.saturating_mul(100) / median_ms.max(1),
408 t.noop_ratio_percent
409 ),
410 });
411 }
412 if last.outcome == RunOutcome::Passed
413 && last.ms < t.fast_pass_ms
414 && verdicts[..verdicts.len() - 1]
415 .iter()
416 .all(|(_, r)| r.ms >= t.fast_pass_ms)
417 {
418 return Some(Flag {
419 kind: FlagKind::NoOpSuspect,
420 why: format!(
421 "passed in {}, and none of the {} earlier runs ever finished under {}",
422 duration(last.ms),
423 verdicts.len() - 1,
424 duration(t.fast_pass_ms)
425 ),
426 });
427 }
428 None
429}
430
431fn flaky_flag(gate: &str, verdicts: &[(&str, &Run)]) -> Option<Flag> {
434 let mut by_fp: BTreeMap<&str, (usize, usize)> = BTreeMap::new();
435 for &(fp, run) in verdicts {
436 let e = by_fp.entry(fp).or_insert((0, 0));
437 if run.outcome == RunOutcome::Passed {
438 e.0 += 1;
439 } else {
440 e.1 += 1;
441 }
442 }
443 let split: Vec<(&str, usize, usize)> = by_fp
444 .into_iter()
445 .filter(|(_, (pass, fail))| *pass > 0 && *fail > 0)
446 .map(|(fp, (pass, fail))| (fp, pass, fail))
447 .collect();
448 let (fp, pass, fail) = *split.first()?;
449 Some(Flag {
450 kind: FlagKind::Flaky,
451 why: format!(
452 "{gate} both passed ({pass}) and failed ({fail}) on tree {}{}",
453 short(fp),
454 if split.len() > 1 {
455 format!(", and on {} other tree(s)", split.len() - 1)
456 } else {
457 String::new()
458 }
459 ),
460 })
461}
462
463fn stale_flag(report: &GateReport, all: &[(&str, &Run)], now: u64, t: &Thresholds) -> Option<Flag> {
465 if report.runs == 0 {
466 return None;
467 }
468 let newest_other = all
469 .iter()
470 .filter(|(_, r)| r.gate != report.gate)
471 .map(|(_, r)| r.at)
472 .max()?;
473 if newest_other <= report.last_at {
474 return None;
475 }
476 if report.missed >= t.stale_runs {
477 return Some(Flag {
478 kind: FlagKind::Stale,
479 why: format!(
480 "{} later tree(s) were judged by other gates and not by this one (threshold {})",
481 report.missed, t.stale_runs
482 ),
483 });
484 }
485 let age = report.last_age_days(now);
486 if age >= t.stale_days {
487 return Some(Flag {
488 kind: FlagKind::Stale,
489 why: format!(
490 "last ran {age} days ago (threshold {}), while another gate ran {} days ago",
491 t.stale_days,
492 now.saturating_sub(newest_other) / 86_400
493 ),
494 });
495 }
496 None
497}
498
499pub fn order_by_evidence(
521 gates: &[String],
522 history: &History,
523 now: u64,
524 window_days: u64,
525) -> Vec<usize> {
526 let runs = history.within(now, window_days);
527 let mut stats: BTreeMap<&str, (u64, u64, Vec<u64>)> = BTreeMap::new();
528 for (_, run) in &runs {
529 if !run.outcome.is_verdict() {
530 continue;
531 }
532 let e = stats.entry(run.gate.as_str()).or_insert((0, 0, Vec::new()));
533 e.0 += 1;
534 if run.outcome == RunOutcome::Failed {
535 e.1 += 1;
536 }
537 e.2.push(run.ms);
538 }
539 let weight = |name: &String| -> Option<(u64, u64, u64)> {
541 let (runs, fails, ms) = stats.get(name.as_str())?;
542 (*fails > 0).then(|| (*fails, *runs, median(ms).max(1)))
543 };
544 let mut order: Vec<usize> = (0..gates.len()).collect();
545 order.sort_by(|&a, &b| {
546 match (weight(&gates[a]), weight(&gates[b])) {
547 (Some((fa, ra, ma)), Some((fb, rb, mb))) => {
548 let left = u128::from(fa) * u128::from(rb) * u128::from(mb);
551 let right = u128::from(fb) * u128::from(ra) * u128::from(ma);
552 right.cmp(&left).then(a.cmp(&b))
553 }
554 (Some(_), None) => std::cmp::Ordering::Less,
555 (None, Some(_)) => std::cmp::Ordering::Greater,
556 (None, None) => a.cmp(&b),
557 }
558 });
559 order
560}
561
562fn median(values: &[u64]) -> u64 {
563 if values.is_empty() {
564 return 0;
565 }
566 let mut v = values.to_vec();
567 v.sort_unstable();
568 let mid = v.len() / 2;
569 if v.len() % 2 == 1 {
570 v[mid]
571 } else {
572 v[mid - 1]
576 }
577}
578
579pub fn duration(ms: u64) -> String {
582 if ms < 1_000 {
583 return format!("{ms} ms");
584 }
585 if ms < 60_000 {
586 return format!("{}.{} s", ms / 1000, (ms % 1000) / 100);
587 }
588 format!("{} m {:02} s", ms / 60_000, (ms % 60_000) / 1000)
589}
590
591pub(crate) fn short(oid: &str) -> &str {
593 oid.get(..8).unwrap_or(oid)
594}
595
596#[cfg(test)]
597mod tests {
598 use super::*;
599
600 fn run(at: u64, gate: &str, outcome: RunOutcome, ms: u64) -> Run {
601 Run {
602 at,
603 gate: gate.to_string(),
604 outcome,
605 ms,
606 }
607 }
608
609 fn history(rows: &[(&str, Run)]) -> History {
610 History {
611 runs: rows
612 .iter()
613 .map(|(fp, r)| ((*fp).to_string(), r.clone()))
614 .collect(),
615 }
616 }
617
618 fn owned_history(rows: Vec<(String, Run)>) -> History {
621 History { runs: rows }
622 }
623
624 const NOW: u64 = 1_800_000_000;
625 const DAY: u64 = 86_400;
626
627 fn of<'a>(reports: &'a [GateReport], gate: &str) -> &'a GateReport {
628 reports
629 .iter()
630 .find(|r| r.gate == gate)
631 .unwrap_or_else(|| panic!("no report for {gate}: {reports:?}"))
632 }
633
634 fn kinds(r: &GateReport) -> Vec<FlagKind> {
635 r.flags.iter().map(|f| f.kind).collect()
636 }
637
638 #[test]
643 fn a_suite_that_collapsed_to_milliseconds_is_a_no_op_suspect() {
644 let mut rows: Vec<(&str, Run)> = (0..8)
645 .map(|i| {
646 (
647 "tree0",
648 run(
649 NOW - (10 - i) * DAY,
650 "pre-push-cargo-test",
651 RunOutcome::Passed,
652 600_000,
653 ),
654 )
655 })
656 .collect();
657 rows.push((
658 "tree9",
659 run(NOW - DAY, "pre-push-cargo-test", RunOutcome::Passed, 400),
660 ));
661 let reports = summarise(&history(&rows), NOW, &Thresholds::default());
662 let r = of(&reports, "pre-push-cargo-test");
663 assert_eq!(kinds(r), vec![FlagKind::NoOpSuspect]);
664 assert!(
665 r.flags[0].why.contains("400 ms") && r.flags[0].why.contains("threshold 10%"),
666 "the flag must carry the comparison it made: {:?}",
667 r.flags[0].why
668 );
669 }
670
671 #[test]
675 fn a_gate_that_never_once_took_real_time_is_also_suspect() {
676 let rows: Vec<(&str, Run)> = (0..6)
677 .map(|i| {
678 (
679 "tree0",
680 run(
681 NOW - (7 - i) * DAY,
682 "pre-push-audit-python",
683 RunOutcome::Passed,
684 if i == 5 { 30 } else { 4_000 },
685 ),
686 )
687 })
688 .collect();
689 let reports = summarise(&history(&rows), NOW, &Thresholds::default());
690 assert_eq!(
691 kinds(of(&reports, "pre-push-audit-python")),
692 vec![FlagKind::NoOpSuspect]
693 );
694 }
695
696 #[test]
699 fn one_fingerprint_with_two_answers_is_flaky() {
700 let rows = [
701 (
702 "treeA",
703 run(NOW - 6 * DAY, "pre-push-pytest", RunOutcome::Passed, 90_000),
704 ),
705 (
706 "treeA",
707 run(NOW - 5 * DAY, "pre-push-pytest", RunOutcome::Failed, 88_000),
708 ),
709 (
710 "treeA",
711 run(NOW - 4 * DAY, "pre-push-pytest", RunOutcome::Passed, 91_000),
712 ),
713 (
714 "treeB",
715 run(NOW - 3 * DAY, "pre-push-pytest", RunOutcome::Passed, 92_000),
716 ),
717 (
718 "treeB",
719 run(NOW - 2 * DAY, "pre-push-pytest", RunOutcome::Passed, 90_500),
720 ),
721 ];
722 let r = summarise(&history(&rows), NOW, &Thresholds::default());
723 let r = of(&r, "pre-push-pytest");
724 assert_eq!(kinds(r), vec![FlagKind::Flaky]);
725 assert!(r.flags[0].why.contains("treeA"), "{:?}", r.flags[0].why);
726 }
727
728 #[test]
731 fn a_gate_left_behind_by_its_neighbours_is_stale() {
732 let mut rows = vec![(
733 "tree0".to_string(),
734 run(
735 NOW - 40 * DAY,
736 "pre-push-go-test",
737 RunOutcome::Passed,
738 5_000,
739 ),
740 )];
741 for i in 0..12u64 {
742 rows.push((
743 format!("tree{}", i + 1),
744 run(
745 NOW - (12 - i) * DAY,
746 "pre-push-cargo-test",
747 RunOutcome::Passed,
748 5_000,
749 ),
750 ));
751 }
752 let reports = summarise(&owned_history(rows), NOW, &Thresholds::default());
753 let stale = of(&reports, "pre-push-go-test");
754 assert!(kinds(stale).contains(&FlagKind::Stale), "{:?}", stale.flags);
755 assert!(
756 of(&reports, "pre-push-cargo-test").flags.is_empty(),
757 "the gate that kept running is not stale"
758 );
759 }
760
761 #[test]
764 fn too_little_history_abstains_out_loud() {
765 let rows = [
766 (
767 "tree0",
768 run(
769 NOW - 2 * DAY,
770 "pre-push-cargo-test",
771 RunOutcome::Passed,
772 600_000,
773 ),
774 ),
775 (
776 "tree1",
777 run(NOW - DAY, "pre-push-cargo-test", RunOutcome::Passed, 300),
778 ),
779 ];
780 let reports = summarise(&history(&rows), NOW, &Thresholds::default());
781 let r = of(&reports, "pre-push-cargo-test");
782 assert_eq!(
783 r.abstained.as_deref(),
784 Some("insufficient history (2 verdicts)")
785 );
786 assert!(
787 r.flags.is_empty(),
788 "a two-run history must not raise a flag: {:?}",
789 r.flags
790 );
791 assert_eq!((r.runs, r.passed), (2, 2), "the counts are still reported");
792 }
793
794 #[test]
798 fn an_unavailable_run_is_never_counted_as_a_pass() {
799 let rows = [
800 (
801 "tree0",
802 run(
803 NOW - 2 * DAY,
804 "pre-push-audit-go",
805 RunOutcome::Unavailable,
806 200,
807 ),
808 ),
809 (
810 "tree1",
811 run(NOW - DAY, "pre-push-audit-go", RunOutcome::Unavailable, 210),
812 ),
813 ];
814 let reports = summarise(&history(&rows), NOW, &Thresholds::default());
815 let r = of(&reports, "pre-push-audit-go");
816 assert_eq!((r.passed, r.failed, r.unavailable), (0, 0, 2));
817 }
818
819 #[test]
821 fn the_window_excludes_what_is_older_than_it() {
822 let rows = [
823 (
824 "tree0",
825 run(
826 NOW - 200 * DAY,
827 "pre-push-cargo-test",
828 RunOutcome::Failed,
829 500,
830 ),
831 ),
832 (
833 "tree1",
834 run(NOW - DAY, "pre-push-cargo-test", RunOutcome::Passed, 500),
835 ),
836 ];
837 let reports = summarise(&history(&rows), NOW, &Thresholds::default());
838 assert_eq!(of(&reports, "pre-push-cargo-test").runs, 1);
839 }
840
841 #[test]
845 fn ordering_prefers_failures_per_second_not_failure_rate() {
846 let gates: Vec<String> = ["suite", "audit"].iter().map(|s| s.to_string()).collect();
847 let mut rows: Vec<(&str, Run)> = Vec::new();
848 for i in 0..6u64 {
849 rows.push((
850 "tree0",
851 run(
852 NOW - (10 - i) * DAY,
853 "suite",
854 if i < 2 {
855 RunOutcome::Failed
856 } else {
857 RunOutcome::Passed
858 },
859 1_200_000,
860 ),
861 ));
862 rows.push((
863 "tree0",
864 run(
865 NOW - (10 - i) * DAY,
866 "audit",
867 if i < 1 {
868 RunOutcome::Failed
869 } else {
870 RunOutcome::Passed
871 },
872 5_000,
873 ),
874 ));
875 }
876 let order = order_by_evidence(&gates, &history(&rows), NOW, 90);
877 assert_eq!(order, vec![1, 0], "the cheap audit runs first");
878 }
879
880 #[test]
883 fn with_no_history_the_declared_order_is_kept() {
884 let gates: Vec<String> = ["a", "b", "c"].iter().map(|s| s.to_string()).collect();
885 assert_eq!(
886 order_by_evidence(&gates, &History::default(), NOW, 90),
887 vec![0, 1, 2]
888 );
889 }
890
891 #[test]
894 fn only_gates_that_actually_failed_are_promoted() {
895 let gates: Vec<String> = ["a", "b", "c"].iter().map(|s| s.to_string()).collect();
896 let rows = [
897 ("t", run(NOW - 3 * DAY, "a", RunOutcome::Passed, 1_000)),
898 ("t", run(NOW - 3 * DAY, "b", RunOutcome::Passed, 1_000)),
899 ("t", run(NOW - 2 * DAY, "c", RunOutcome::Failed, 1_000)),
900 ("t", run(NOW - DAY, "c", RunOutcome::Passed, 1_000)),
901 ];
902 assert_eq!(
903 order_by_evidence(&gates, &history(&rows), NOW, 90),
904 vec![2, 0, 1]
905 );
906 }
907
908 #[test]
911 fn ordering_is_a_permutation_and_never_drops_a_gate() {
912 let gates: Vec<String> = ["a", "b", "c", "d"].iter().map(|s| s.to_string()).collect();
913 let rows = [
914 ("t", run(NOW - DAY, "b", RunOutcome::Failed, 10)),
915 ("t", run(NOW - DAY, "d", RunOutcome::Failed, 10_000)),
916 ];
917 let mut order = order_by_evidence(&gates, &history(&rows), NOW, 90);
918 assert_eq!(order.len(), gates.len());
919 order.sort_unstable();
920 assert_eq!(order, vec![0, 1, 2, 3]);
921 }
922
923 #[test]
925 fn cat_file_batch_output_splits_into_bodies() {
926 let oid = "0123456789abcdef0123456789abcdef01234567";
927 let other = "89abcdef0123456789abcdef0123456789abcdef";
928 let out = format!(
929 "{oid} blob 42\ngreengate-gate-v1 pre-push-cargo-test\nrun 10 pre-push-cargo-test pass 5\n\
930 {other} blob 14\ngreengate-gate-v1\n"
931 );
932 let got = parse_batch(&out);
933 assert_eq!(got.len(), 2);
934 assert_eq!(got[0].0, oid);
935 assert!(got[0].1.contains("run 10"));
936 assert_eq!(got[1].0, other);
937 }
938
939 #[test]
940 fn durations_read_like_durations() {
941 assert_eq!(duration(400), "400 ms");
942 assert_eq!(duration(5_400), "5.4 s");
943 assert_eq!(duration(662_000), "11 m 02 s");
944 }
945}