From feff7386c2bae240c04b3ebdd2d4bf15e6429c56 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 2 May 2022 13:48:07 +0100 Subject: Add test cases that daemonstrate large writes do actually fail --- netfs/unittests/defaultFuseNoAsync.xml | 15 ++++++++++++++ netfs/unittests/testEdgeCases.cpp | 36 ++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 netfs/unittests/defaultFuseNoAsync.xml diff --git a/netfs/unittests/defaultFuseNoAsync.xml b/netfs/unittests/defaultFuseNoAsync.xml new file mode 100644 index 0000000..5350180 --- /dev/null +++ b/netfs/unittests/defaultFuseNoAsync.xml @@ -0,0 +1,15 @@ + + + + + testvol + + testvol + false + + overridden + + + + + diff --git a/netfs/unittests/testEdgeCases.cpp b/netfs/unittests/testEdgeCases.cpp index 51a1931..5249aed 100644 --- a/netfs/unittests/testEdgeCases.cpp +++ b/netfs/unittests/testEdgeCases.cpp @@ -120,3 +120,39 @@ BOOST_AUTO_TEST_CASE(manyThreads) BOOST_CHECK_GT(success, 800); BOOST_CHECK_EQUAL(failure, 0); } + +BOOST_AUTO_TEST_CASE(bigWritesAsync) +{ + MockDaemonHost daemon(testEndpoint, {"--NetFSD.ConfigPath=" + (rootDir / "defaultDaemon.xml").string()}); + FuseMockHost fuse(testEndpoint, {(rootDir / "defaultFuse.xml").string() + ":testvol", (rootDir / "test").string()}); + + std::vector buf(1 * 1024 * 1024); + fuse_file_info fi {}; + fi.flags = O_RDWR; + auto fd = fuse.fuse->create("/big", 0600, &fi); + BOOST_REQUIRE_GE(fd, 0); + BOOST_REQUIRE_NE(fi.fh, 0); + // async success + BOOST_CHECK_EQUAL(buf.size(), fuse.fuse->write("/big", buf.data(), buf.size(), 0, &fi)); + // failure on flush/close + BOOST_REQUIRE_EQUAL(-EIO, fuse.fuse->release("/big", &fi)); + BOOST_CHECK_EQUAL(0, std::filesystem::file_size(daemon.TestExportRoot / "big")); +} + +BOOST_AUTO_TEST_CASE(bigWritesNoAsync) +{ + MockDaemonHost daemon(testEndpoint, {"--NetFSD.ConfigPath=" + (rootDir / "defaultDaemon.xml").string()}); + FuseMockHost fuse( + testEndpoint, {(rootDir / "defaultFuseNoAsync.xml").string() + ":testvol", (rootDir / "test").string()}); + + std::vector buf(1 * 1024 * 1024); + fuse_file_info fi {}; + fi.flags = O_RDWR; + auto fd = fuse.fuse->create("/big", 0600, &fi); + BOOST_REQUIRE_GE(fd, 0); + BOOST_REQUIRE_NE(fi.fh, 0); + // sync fail + BOOST_CHECK_EQUAL(-EIO, fuse.fuse->write("/big", buf.data(), buf.size(), 0, &fi)); + BOOST_REQUIRE_EQUAL(0, fuse.fuse->release("/big", &fi)); + BOOST_CHECK_EQUAL(0, std::filesystem::file_size(daemon.TestExportRoot / "big")); +} -- cgit v1.2.3