Cancel the download test's transfer only once its part file is made

link::tests::a_file_is_downloaded_through_the_connection_the_link_opens waited
for the Started state and then cancelled, expecting the part file to be gone
100 ms later. The download reports Started just before it opens the part file
(files::download, then receive), and the open runs on tokio's blocking pool. A
cancel that arrives in between finds no part file to remove (link cancel()
removes it at once and reports Cancelled), the aborted task cannot stop the
open that is already going on, and the part file is made after the cancel:
`assert!(!part.exists())` failed. It did so in the second of the final runs of
the CI test step in the runner image of this task, and in 10 of 100 runs of
the voelin-core lib tests with three of them at a time and 16 busy loops
beside them on a 32-core machine (none in 200 such runs with this change).

The test now waits for the part file itself, which is what "the transfer
waits in the middle" means, and checks that Started was reported.

This is a real, if small, defect of the product that the test exposed: a
cancel in the moment between Started and the end of the open leaves an empty
`<name>.part` next to the target. It is not fixed here: closing it takes
reporting Started after the open (it also feeds the chat and the preview size
limit) or waiting for the aborted task before the part is removed, which is a
change of the transfer code and not of a test. Recorded in the report of this
branch.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
faumarayandClaude Sonnet 5.5 committed 2026-10-24 21:41:37 +03:00
1 parent 637ee58979
commit 61458df625
1 file changed
+7 -2
+7 -2
View File
@@ -598,15 +598,20 @@ async fn a_file_is_downloaded_through_the_connection_the_link_opens() {
report, report,
}); });
let LinkCmd::OpenRead { reply, .. } = rig.inner_cmd().await else { panic!("a connection") }; let LinkCmd::OpenRead { reply, .. } = rig.inner_cmd().await else { panic!("a connection") };
// A file whose bytes do not come: the transfer waits in the middle. // A file whose bytes do not come: the transfer waits in the middle, with
// its part file made. `Started` is reported just before the part file is
// opened, and a cancel in between would find nothing to remove while the
// open still goes on, so the part file is what is waited for.
let (server, client) = tokio::io::duplex(64); let (server, client) = tokio::io::duplex(64);
let _ = reply.send(Ok((1 << 20, Box::pin(client)))); let _ = reply.send(Ok((1 << 20, Box::pin(client))));
for _ in 0..500 { for _ in 0..500 {
if states.lock().unwrap().iter().any(|s| matches!(s, TransferState::Started { .. })) { if part.exists() {
break; break;
} }
tokio::time::sleep(Duration::from_millis(10)).await; tokio::time::sleep(Duration::from_millis(10)).await;
} }
assert!(part.exists(), "the transfer made its part file: {:?}", states.lock().unwrap());
assert!(states.lock().unwrap().iter().any(|s| matches!(s, TransferState::Started { .. })));
rig.give(LinkCmd::CancelTransfer(3)); rig.give(LinkCmd::CancelTransfer(3));
assert_eq!(final_state(&states).await, TransferState::Cancelled); assert_eq!(final_state(&states).await, TransferState::Cancelled);
rig.quiet(); rig.quiet();