feat: track uploads with progress and cancellation
serve_file streams in chunks, updating a shared byte counter and aborting with Interrupted when a cancel flag is set. Each served upload is registered (peer, virtual path, size, live progress, status) and exposed via Client::uploads(); Client::cancel_upload flags a matching in-progress transfer. e2e: the download test now also asserts the uploader recorded a completed upload with the right peer and byte count.
This commit is contained in:
@@ -1245,6 +1245,24 @@ fn two_real_clients_search_and_download() {
|
||||
.expect("downloaded file should exist");
|
||||
assert_eq!(written, content, "downloaded bytes should match the source");
|
||||
|
||||
// The uploader side tracked the transfer and saw it complete.
|
||||
let deadline = Instant::now() + Duration::from_secs(5);
|
||||
let mut uploads = sharer.uploads();
|
||||
while Instant::now() < deadline
|
||||
&& !uploads
|
||||
.iter()
|
||||
.any(|u| u.status == soulseek_rs::types::UploadStatus::Completed)
|
||||
{
|
||||
std::thread::sleep(Duration::from_millis(200));
|
||||
uploads = sharer.uploads();
|
||||
}
|
||||
let upload = uploads
|
||||
.iter()
|
||||
.find(|u| u.status == soulseek_rs::types::UploadStatus::Completed)
|
||||
.expect("uploader should record a completed upload");
|
||||
assert_eq!(upload.username, "e2e_leecher");
|
||||
assert_eq!(upload.bytes_sent, size);
|
||||
|
||||
let _ = std::fs::remove_dir_all(share_dir);
|
||||
let _ = std::fs::remove_dir_all(download_dir);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user