diff options
author | Dan Goodliffe <dan.goodliffe@octal.co.uk> | 2022-04-14 10:44:42 +0100 |
---|---|---|
committer | Dan Goodliffe <dan.goodliffe@octal.co.uk> | 2022-04-14 10:44:46 +0100 |
commit | fb57563f701c985ff6e9c3624cdfc2b6afc3e6f8 (patch) | |
tree | 5f80b0ef0ab1e3292059713b1df5a9e7e93aa33c | |
parent | Add missing override (diff) | |
download | netfs-fb57563f701c985ff6e9c3624cdfc2b6afc3e6f8.tar.bz2 netfs-fb57563f701c985ff6e9c3624cdfc2b6afc3e6f8.tar.xz netfs-fb57563f701c985ff6e9c3624cdfc2b6afc3e6f8.zip |
Fix Glacier tests
Creates a class which is usable as a global fixture for handling a
Glacier instance. Fixes the issue in the previous version where flock
was used, but in conjunction with --daemon and a pidfile, so it only
prevented concurrent startup, not concurrent execution.
-rw-r--r-- | netfs/unittests/mockGlacier.cpp | 29 | ||||
-rw-r--r-- | netfs/unittests/mockGlacier.h | 19 | ||||
-rw-r--r-- | netfs/unittests/testGlacier.cpp | 35 |
3 files changed, 59 insertions, 24 deletions
diff --git a/netfs/unittests/mockGlacier.cpp b/netfs/unittests/mockGlacier.cpp new file mode 100644 index 0000000..f1e8e72 --- /dev/null +++ b/netfs/unittests/mockGlacier.cpp @@ -0,0 +1,29 @@ +#include "mockGlacier.h" +#include <boost/test/test_tools.hpp> +#include <csignal> +#include <sys/file.h> +#include <sys/prctl.h> +#include <sys/wait.h> + +Glacier::Glacier() : lockdir(open("/tmp", O_DIRECTORY)) +{ + BOOST_REQUIRE_GE(lockdir, 0); + BOOST_REQUIRE_EQUAL(0, flock(lockdir, LOCK_EX)); + if (glacier = fork(); glacier == 0) { + prctl(PR_SET_PDEATHSIG, SIGINT); + execl("/usr/bin/glacier2router", "--Glacier2.Client.Endpoints=tcp -p 14063", + "--Glacier2.PermissionsVerifier=Glacier2/NullPermissionsVerifier", nullptr); + BOOST_FAIL("Should never get here"); + } + BOOST_REQUIRE_GT(glacier, 0); + sleep(1); +} + +Glacier::~Glacier() +{ + BOOST_CHECK_EQUAL(0, kill(glacier, SIGINT)); + int status {}; + BOOST_CHECK_EQUAL(glacier, waitpid(glacier, &status, 0)); + BOOST_CHECK_EQUAL(0, status); + BOOST_CHECK_EQUAL(0, close(lockdir)); +} diff --git a/netfs/unittests/mockGlacier.h b/netfs/unittests/mockGlacier.h new file mode 100644 index 0000000..007715d --- /dev/null +++ b/netfs/unittests/mockGlacier.h @@ -0,0 +1,19 @@ +#ifndef MOCKGLACIER_H +#define MOCKGLACIER_H + +#include <c++11Helpers.h> +#include <sys/types.h> +#include <visibility.h> + +class DLL_PUBLIC Glacier { +public: + Glacier(); + ~Glacier(); + SPECIAL_MEMBERS_DELETE(Glacier); + +private: + const int lockdir; + pid_t glacier; +}; + +#endif diff --git a/netfs/unittests/testGlacier.cpp b/netfs/unittests/testGlacier.cpp index 5467c41..afe3475 100644 --- a/netfs/unittests/testGlacier.cpp +++ b/netfs/unittests/testGlacier.cpp @@ -1,35 +1,22 @@ #define BOOST_TEST_MODULE TestNetFSGlacier +#include <boost/test/unit_test.hpp> + #include "mockDaemon.h" #include "mockFuse.h" -#include <boost/scope_exit.hpp> -#include <boost/test/unit_test.hpp> +#include "mockGlacier.h" #include <definedDirs.h> const std::string testEndpoint("tcp -h localhost -p 12013"); -#define PID "/tmp/glacier.pid" + +BOOST_TEST_GLOBAL_FIXTURE(Glacier); BOOST_AUTO_TEST_CASE(withRouter) { - std::filesystem::remove(PID); - BOOST_REQUIRE_EQUAL(0, - system("flock /tmp/glacier.lock /usr/bin/glacier2router --Glacier2.Client.Endpoints='tcp -p 14063' " - "--Glacier2.PermissionsVerifier=Glacier2/NullPermissionsVerifier --daemon --pidfile " PID)); - sleep(1); - - BOOST_SCOPE_EXIT(void) - { - BOOST_REQUIRE_EQUAL(0, system("kill $(cat " PID ")")); - std::filesystem::remove(PID); - } - BOOST_SCOPE_EXIT_END; - - { - MockDaemonHost daemon(testEndpoint, {"--NetFSD.ConfigPath=" + (rootDir / "defaultDaemon.xml").string()}); - FuseMockHost fuse(testEndpoint, - {(rootDir / "defaultFuse.xml:testvol").string(), (rootDir / "test").string(), - "--Ice.Default.Router=Glacier2/router:tcp -h localhost -p 14063"}); + MockDaemonHost daemon(testEndpoint, {"--NetFSD.ConfigPath=" + (rootDir / "defaultDaemon.xml").string()}); + FuseMockHost fuse(testEndpoint, + {(rootDir / "defaultFuse.xml:testvol").string(), (rootDir / "test").string(), + "--Ice.Default.Router=Glacier2/router:tcp -h localhost -p 14063"}); - struct statvfs s { }; - BOOST_REQUIRE_EQUAL(0, fuse.fuse->statfs("/", &s)); - } + struct statvfs s { }; + BOOST_CHECK_EQUAL(0, fuse.fuse->statfs("/", &s)); } |