aboutsummaryrefslogtreecommitdiff
path: root/tests/unit/libstore
diff options
context:
space:
mode:
authoreldritch horrors <pennae@lix.systems>2024-05-04 01:39:06 +0200
committereldritch horrors <pennae@lix.systems>2024-05-05 18:09:31 +0000
commit6b081389290a5a6a6d143ee7fa4d12ea1296a8d0 (patch)
tree04f2e21120b1ea83ace986816f71694b0d225a73 /tests/unit/libstore
parent03a20ef1ff11f7ed785f02d2965a1f8314d06132 (diff)
filetransfer: abort transfer on receiver exception
not doing this will cause transfers that had their readers disappear to linger. with lingering transfers the curl thread can't shut down, which will cause nix itself to not shut down until the transfer finishes some other way (most likely network timeouts). also add a new test for this. Change-Id: Id2401b3ac85731c824db05918d4079125be25b57
Diffstat (limited to 'tests/unit/libstore')
-rw-r--r--tests/unit/libstore/filetransfer.cc32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/unit/libstore/filetransfer.cc b/tests/unit/libstore/filetransfer.cc
new file mode 100644
index 000000000..192bf81ef
--- /dev/null
+++ b/tests/unit/libstore/filetransfer.cc
@@ -0,0 +1,32 @@
+#include "filetransfer.hh"
+
+#include <future>
+#include <gtest/gtest.h>
+
+using namespace std::chrono_literals;
+
+namespace nix {
+
+TEST(FileTransfer, exceptionAbortsDownload)
+{
+ struct Done
+ {};
+
+ auto ft = makeFileTransfer();
+
+ LambdaSink broken([](auto block) { throw Done(); });
+
+ ASSERT_THROW(ft->download(FileTransferRequest("file:///dev/zero"), broken), Done);
+
+ // makeFileTransfer returns a ref<>, which cannot be cleared. since we also
+ // can't default-construct it we'll have to overwrite it instead, but we'll
+ // take the raw pointer out first so we can destroy it in a detached thread
+ // (otherwise a failure will stall the process and have it killed by meson)
+ auto reset = std::async(std::launch::async, [&]() { ft = makeFileTransfer(); });
+ EXPECT_EQ(reset.wait_for(10s), std::future_status::ready);
+ // if this did time out we have to leak `reset`.
+ if (reset.wait_for(0s) == std::future_status::timeout) {
+ (void) new auto(std::move(reset));
+ }
+}
+}