S006: resume test checks the ranges asked for

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
astar76 2026-11-25 02:47:04 -06:00
commit e0ee812160
2 changed files with 21 additions and 4 deletions

View file

@ -3,7 +3,7 @@
use medlar_core::adapt::Timing;
use medlar_core::events::Event;
use medlar_core::host::{self, Caps, Hosts};
use medlar_core::http::{ClientOptions, Options, Shared, client};
use medlar_core::http::{ClientOptions, OVERLAP, Options, Shared, client};
use medlar_core::manager::*;
use medlar_core::model::*;
use medlar_core::segment::Rules;
@ -316,11 +316,18 @@ async fn an_empty_file_still_belongs_to_its_download() {
async fn removed_and_back() {
let b = Bench::new(LIMITS).await;
let trash = b.dir.path().join("Trash/files");
let id = b.add(&b.slow(1)).await;
b.until_bytes(id).await;
let path = b.slow(1);
let id = b.add(&path).await;
// Much more than is compared.
b.until("well under way", |s| s.get(id).is_some_and(|v| v.downloaded > 60_000)).await;
let seen = b.view(id).downloaded;
for _ in 0..2 {
b.run(Command::Remove { id, files: Files::Bin }).await;
}
let kept = b.store.parts(id).unwrap();
let on_disk: u64 = kept.iter().map(|p| p.done).sum();
assert!(on_disk >= seen, "{on_disk} of {seen} bytes kept");
b.server.clear_log();
assert!(b.manager.snapshot().is_empty());
assert_eq!((std::fs::read_dir(b.files()).unwrap().count(), std::fs::read_dir(&trash).unwrap().count()), (0, 1));
assert!(b.manager.send(Command::Resume(id)).await.is_err());
@ -330,7 +337,16 @@ async fn removed_and_back() {
}
b.until_state(id, State::Done).await;
b.check(id, 1, 1 << 20);
assert!(b.view(id).counters.received < (1 << 20) + 100_000, "it went on where it was");
// It went on where it was: nothing kept is asked for again, but the probe's byte and the bytes to compare. The bytes that
// came say less: a connection whose part is split brings up to one read beyond its new end.
let received = b.view(id).counters.received;
println!("{received} bytes for {}, {on_disk} kept", 1 << 20);
for r in b.server.requests_for(&path) {
let range = r.header("range").and_then(|r| r.strip_prefix("bytes=")).unwrap_or_else(|| panic!("no range: {r:?}"));
let (first, last) = range.split_once('-').map(|(a, b)| (a.parse::<u64>().unwrap(), b.parse::<u64>().unwrap())).unwrap();
let again = kept.iter().map(|p| (p.start + p.done).min(last + 1).saturating_sub(first.max(p.start))).sum::<u64>();
assert!(again <= OVERLAP, "{range} asks for {again} kept bytes: {kept:?}, {received} received");
}
b.run(Command::Remove { id, files: Files::Keep }).await;
b.run(Command::Restore(id)).await;
b.check(id, 1, 1 << 20);

View file

@ -86,6 +86,7 @@ Verified: `nice cargo test -j 2 -p medlar-core` green (76 unit, 16 http, 12 mana
- `begin_close()` doesn't wait; `close()` and drop do (under 2 s). Error text of `http::Error` is raw: S007 fills `words()` and the kinds at the end of `manager/actor.rs`; Retry-After and Waiting are its too.
Not done: part events (`Split`…) don't leave the manager; `PartView.id` tells parts apart within a run. Counters and logs are for this session only. Cookies and logins from the keyring are not added to `Source` yet. Queue `paused`, `max_active`, `schedule`, `after`, `start_at` are not looked at (S009); Done files are not checked for being gone; `Only` does not pause what can't resume.
Seen: connections of a host are first come, first served: with more downloads than fit, some run without any until others end (S010). `http::name::no_name_gets_out_of_its_folder` took over 60 s on an overloaded CPU. Boxes were ticked together at the end, against rule 3.
Fixed after review: `removed_and_back` had a wrong bound. `received` also counts up to one read beyond the new end of a split part (seen: 147 kB); nothing on disk is fetched again. The test now checks the ranges asked for (60 of 60 runs under load, with 61 kB or more kept).
## Later
-