This repository has no description
2.7 kB
77 lines
1#![cfg(feature = "instrument")]
2
3use knot_bench::{ChurnCount, CommitCount, HistorySpec, PathCount, build_history};
4use knot_git::instrument::measure;
5use knot_git::{Filter, PackBudget};
6use knot_pack::upload_pack;
7use knot_types::Oid;
8
9fn gate_spec() -> HistorySpec {
10 HistorySpec {
11 commits: CommitCount::new(32),
12 paths: PathCount::new(64),
13 churn: ChurnCount::new(4),
14 }
15}
16
17const SELECTION_ODB_READS: u64 = 129;
18const SERVER_FETCH_ODB_READS: u64 = 2;
19
20fn pkt(payload: &[u8]) -> Vec<u8> {
21 let mut out = format!("{:04x}", payload.len() + 4).into_bytes();
22 out.extend_from_slice(payload);
23 out
24}
25
26fn fetch_request(want: Oid) -> Vec<u8> {
27 let mut request = pkt(b"command=fetch\n");
28 request.extend_from_slice(b"0001");
29 request.extend(pkt(format!("want {}\n", want.to_hex()).as_bytes()));
30 request.extend(pkt(b"done\n"));
31 request.extend_from_slice(b"0000");
32 request
33}
34
35#[test]
36fn a_single_selection_walk_has_an_exact_odb_read_count() {
37 let history = build_history(gate_spec());
38 let tips = history.tips();
39 let (_selection, reads) = measure(|| {
40 history
41 .repo()
42 .select_pack_objects_filtered(&tips, &[], Filter::None, PackBudget::unbounded())
43 .unwrap()
44 });
45 assert_eq!(
46 reads.get(),
47 SELECTION_ODB_READS,
48 "the selection walk made {} explicit object loads through Repo::load_object. \
49 The gate pins this at {SELECTION_ODB_READS}. A lower count means the single-pass \
50 commit-walk fix landed. A higher count is a regression. The counter records loads \
51 on the calling thread only. gix's internal rev-walk decodes never reach load_object \
52 and stay uncounted. Update the constant only when the change is deliberate",
53 reads.get()
54 );
55}
56
57#[test]
58fn the_upload_pack_server_path_has_an_exact_odb_read_count() {
59 let history = build_history(gate_spec());
60 let walk = history.repo().rev_walk(&history.tips(), &[]).unwrap();
61 let hidden = walk
62 .iter()
63 .copied()
64 .find(|commit| *commit != history.tip())
65 .expect("multi-commit history has a non-tip commit to want");
66 let request = fetch_request(hidden);
67 let (_response, reads) = measure(|| upload_pack(history.repo(), &request).unwrap());
68 assert_eq!(
69 reads.get(),
70 SERVER_FETCH_ODB_READS,
71 "server fetch made {} Repo::load_object calls, gate pins {SERVER_FETCH_ODB_READS}. \
72 No-haves fetch enumerates inside gix, so only the want check and root peel reach \
73 load_object. A count near the old manual-walk figure means the full-clone fast path \
74 stopped firing",
75 reads.get()
76 );
77}