From 3a61d6c7459b8c26ffd28187891d529ce76bbda3 Mon Sep 17 00:00:00 2001 From: Alex Andres Date: Tue, 10 Nov 2026 23:47:06 +0100 Subject: [PATCH] test: write the stale partial file before the offer is accepted The test wrote it after send(), racing the receiver, which opens the partial file once the offer is accepted: written over an open one, the received file ended up with the stale 10 KiB. --- .../client/transfer/FileTransfersTests.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/webrtc/src/test/java/dev/onvoid/webrtc/client/transfer/FileTransfersTests.java b/webrtc/src/test/java/dev/onvoid/webrtc/client/transfer/FileTransfersTests.java index c4958c0ee..4316b100c 100644 --- a/webrtc/src/test/java/dev/onvoid/webrtc/client/transfer/FileTransfersTests.java +++ b/webrtc/src/test/java/dev/onvoid/webrtc/client/transfer/FileTransfersTests.java @@ -337,12 +337,20 @@ void notResumableStartsOver() throws Exception { Path source = randomFile("fresh", 50 * 1024); Path target = dir.resolve("fresh.out"); - CompletableFuture incoming = acceptInto(receiver, target); + CompletableFuture incoming = new CompletableFuture<>(); + receiver.onOffer(offer -> { + // A partial file of the same transfer, from before, is not continued. + // Written before the accept, which opens it. + try { + Files.write(dir.resolve("fresh.out." + offer.id().substring(0, 16) + ".part"), new byte[10 * 1024]); + incoming.complete(offer.accept(target)); + } + catch (IOException e) { + incoming.completeExceptionally(e); + } + }); OutgoingTransfer outgoing = sender.send(source); - // A partial file of the same transfer, from before, is not continued. - Files.write(dir.resolve("fresh.out." + outgoing.id().substring(0, 16) + ".part"), new byte[10 * 1024]); - await(outgoing.whenDone()); await(await(incoming).whenDone()); assertArrayEquals(Files.readAllBytes(source), Files.readAllBytes(target));