Prevent tests from accumulating thousands of tmp directories (#770)
This commit is contained in:
parent
67d211569f
commit
d106aa4180
3 changed files with 39 additions and 1 deletions
|
@ -1,5 +1,6 @@
|
|||
#include <boost/property_tree/json_parser.hpp>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <cstdlib>
|
||||
#include <rai/node/common.hpp>
|
||||
#include <rai/node/testing.hpp>
|
||||
|
||||
|
@ -50,6 +51,14 @@ rai::system::~system ()
|
|||
{
|
||||
i->stop ();
|
||||
}
|
||||
|
||||
// Clean up tmp directories created by the tests. Since it's sometimes useful to
|
||||
// see log files after test failures, an environment variable is supported to
|
||||
// retain the files.
|
||||
if (std::getenv ("TEST_KEEP_TMPDIRS") == nullptr)
|
||||
{
|
||||
rai::remove_temporary_directories ();
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<rai::wallet> rai::system::wallet (size_t index_a)
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
#include <ed25519-donna/ed25519.h>
|
||||
|
||||
static std::vector<boost::filesystem::path> all_unique_paths;
|
||||
|
||||
boost::filesystem::path rai::working_path ()
|
||||
{
|
||||
auto result (rai::app_path ());
|
||||
|
@ -27,9 +29,33 @@ boost::filesystem::path rai::working_path ()
|
|||
boost::filesystem::path rai::unique_path ()
|
||||
{
|
||||
auto result (working_path () / boost::filesystem::unique_path ());
|
||||
all_unique_paths.push_back (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<boost::filesystem::path> rai::remove_temporary_directories ()
|
||||
{
|
||||
for (auto & path : all_unique_paths)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
boost::filesystem::remove_all (path, ec);
|
||||
if (ec)
|
||||
{
|
||||
std::cerr << "Could not remove temporary directory: " << ec.message () << std::endl;
|
||||
}
|
||||
|
||||
// lmdb creates a -lock suffixed file for its MDB_NOSUBDIR databases
|
||||
auto lockfile = path;
|
||||
lockfile += "-lock";
|
||||
boost::filesystem::remove (lockfile, ec);
|
||||
if (ec)
|
||||
{
|
||||
std::cerr << "Could not remove temporary lock file: " << ec.message () << std::endl;
|
||||
}
|
||||
}
|
||||
return all_unique_paths;
|
||||
}
|
||||
|
||||
rai::mdb_env::mdb_env (bool & error_a, boost::filesystem::path const & path_a, int max_dbs)
|
||||
{
|
||||
boost::system::error_code error;
|
||||
|
|
|
@ -24,8 +24,11 @@ using bufferstream = boost::iostreams::stream_buffer<boost::iostreams::basic_arr
|
|||
using vectorstream = boost::iostreams::stream_buffer<boost::iostreams::back_insert_device<std::vector<uint8_t>>>;
|
||||
// OS-specific way of finding a path to a home directory.
|
||||
boost::filesystem::path working_path ();
|
||||
// Get a unique path within the home directory, used for testing
|
||||
// Get a unique path within the home directory, used for testing.
|
||||
// Any directories created at this location will be removed when a test finishes.
|
||||
boost::filesystem::path unique_path ();
|
||||
// Remove all unique tmp directories created by the process. The list of unique paths are returned.
|
||||
std::vector<boost::filesystem::path> remove_temporary_directories ();
|
||||
// C++ stream are absolutely horrible so I need this helper function to do the most basic operation of creating a file if it doesn't exist or truncating it.
|
||||
void open_or_create (std::fstream &, std::string const &);
|
||||
// Reads a json object from the stream and if was changed, write the object back to the stream
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue