tests: ps number sample walks the divisor's fraction

This commit is contained in:
aiongg
2026-11-24 22:30:45 +00:00
parent 06a4182f28
commit 73ea1f1e34
4 changed files with 15 additions and 6 deletions
Generated
+1
View File
@@ -3841,6 +3841,7 @@ name = "craft-ps"
version = "0.1.0"
dependencies = [
"craft-eps",
"craft-testkit",
"flate2",
"kurbo",
"miniz_oxide 0.8.9",
+3 -3
View File
@@ -29,13 +29,13 @@ fn a_flood_of_long_lines_ends_the_command() {
// 600 lines of 60 KB are more than the 32 MB one command may bring. The gate sends lines that
// are not parsed (the cap counts the text read); nightly sends the lines of a real listing.
let full = craft_testkit::hostile::divisor() == 1;
let server =
flood(600, |n| if full { format!("* {n} FETCH (UID {} FLAGS ({pad}))\r\n", n + 1) } else { format!("* OK {pad}\r\n") }) + "A0001 OK done\r\n";
let ok_lines = format!("* OK {pad}\r\n").repeat(600);
let server = if full { flood(600, |n| format!("* {n} FETCH (UID {} FLAGS ({pad}))\r\n", n + 1)) } else { ok_lines.clone() } + "A0001 OK done\r\n";
let mut s = Script::new(server);
let err = opened(&mut s, 1000, 2000).uid_fetch_flags("1:*").unwrap_err();
assert!(matches!(err, ProtoError::Protocol(ref m) if m.to_string().contains("too much")), "{err:?}");
// The same in a list.
let server = flood(600, |n| if full { format!("* LIST () \"/\" \"{n}{pad}\"\r\n") } else { format!("* OK {pad}\r\n") }) + "A0001 OK done\r\n";
let server = if full { flood(600, |n| format!("* LIST () \"/\" \"{n}{pad}\"\r\n")) } else { ok_lines } + "A0001 OK done\r\n";
let mut s = Script::new(server);
assert!(matches!(opened(&mut s, 0, 0).list(), Err(ProtoError::Protocol(_))));
}
+3
View File
@@ -24,6 +24,9 @@ skrifa = { workspace = true, optional = true }
kurbo = { workspace = true, optional = true }
flate2 = { version = "1.1.10", default-features = false, features = ["rust_backend"], optional = true }
[dev-dependencies]
craft-testkit = { workspace = true }
[[example]]
name = "eps2pdf"
required-features = ["read"]
+8 -3
View File
@@ -602,9 +602,13 @@ mod tests {
#[test]
fn numbers_match_base_formatter() {
let mut integer_path = 0usize;
// The gate walks every `divisor()`-th value (offset by `places` so the places differ); nightly walks all.
let step = craft_testkit::hostile::divisor();
let (mut integer_path, mut visited) = (0usize, 0usize);
let samples = number_samples();
for places in 0..=12 {
for v in number_samples() {
for v in samples.iter().copied().skip(places % step).step_by(step) {
visited += 1;
let mut expected = String::from("x ");
base_push_num_places(&mut expected, v, places);
let mut got = String::from("x ");
@@ -616,7 +620,8 @@ mod tests {
}
}
// The comparison covers the integer path, not only the fallback.
assert!(integer_path > 200_000, "{integer_path} values took the integer path");
eprintln!("DIAG numbers_match_base_formatter: visited {visited}, integer path {integer_path}");
assert!(integer_path * 20 > visited, "{integer_path} of {visited} values took the integer path");
}
#[test]