Skip to content

Commit

Permalink
Fix for "open_succeeds_twice" test failure on second run
Browse files Browse the repository at this point in the history
- Use std::filesystem for temp files and folders operation. For some
reason rcpputils::fs::delete_all(folder_name) wasn't able to delete temp
folder with subfolders.

Signed-off-by: Michael Orlov <[email protected]>
  • Loading branch information
MichaelOrlov committed May 21, 2024
1 parent 1ad354a commit a64af18
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@

#include <gmock/gmock.h>

#include <filesystem>
#include <fstream>
#include <memory>
#include <string>
#include <utility>
#include <vector>

#include "rcpputils/asserts.hpp"
#include "rcpputils/filesystem_helper.hpp"

#include "rosbag2_compression/compression_options.hpp"
#include "rosbag2_compression/sequential_compression_writer.hpp"
Expand All @@ -39,6 +39,8 @@

using namespace testing; // NOLINT

namespace fs = std::filesystem;

static constexpr const char * DefaultTestCompressor = "fake_comp";

class SequentialCompressionWriterTest : public TestWithParam<uint64_t>
Expand All @@ -49,12 +51,12 @@ class SequentialCompressionWriterTest : public TestWithParam<uint64_t>
storage_{std::make_shared<NiceMock<MockStorage>>()},
converter_factory_{std::make_shared<StrictMock<MockConverterFactory>>()},
metadata_io_{std::make_unique<NiceMock<MockMetadataIo>>()},
tmp_dir_{rcpputils::fs::temp_directory_path() / "SequentialCompressionWriterTest"},
tmp_dir_{fs::temp_directory_path() / "SequentialCompressionWriterTest"},
tmp_dir_storage_options_{},
serialization_format_{"rmw_format"}
{
tmp_dir_storage_options_.uri = tmp_dir_.string();
rcpputils::fs::remove_all(tmp_dir_);
fs::remove_all(tmp_dir_);
ON_CALL(*storage_factory_, open_read_write(_)).WillByDefault(Return(storage_));
EXPECT_CALL(*storage_factory_, open_read_write(_)).Times(AtLeast(0));
// intercept the metadata write so we can analyze it.
Expand All @@ -71,7 +73,7 @@ class SequentialCompressionWriterTest : public TestWithParam<uint64_t>

~SequentialCompressionWriterTest() override
{
rcpputils::fs::remove_all(tmp_dir_);
fs::remove_all(tmp_dir_);
}

void initializeFakeFileStorage()
Expand Down Expand Up @@ -131,7 +133,7 @@ class SequentialCompressionWriterTest : public TestWithParam<uint64_t>
std::shared_ptr<StrictMock<MockConverterFactory>> converter_factory_;
std::unique_ptr<MockMetadataIo> metadata_io_;

rcpputils::fs::path tmp_dir_;
fs::path tmp_dir_;
rosbag2_storage::StorageOptions tmp_dir_storage_options_;
rosbag2_storage::BagMetadata intercepted_write_metadata_;
std::vector<rosbag2_storage::BagMetadata> v_intercepted_update_metadata_;
Expand Down Expand Up @@ -199,7 +201,7 @@ TEST_F(SequentialCompressionWriterTest, open_succeeds_on_supported_compression_f
kDefaultCompressionQueueSize, kDefaultCompressionQueueThreads};
initializeWriter(compression_options);

auto tmp_dir = rcpputils::fs::temp_directory_path() / "path_not_empty";
auto tmp_dir = tmp_dir_ / "path_not_empty";
auto storage_options = rosbag2_storage::StorageOptions();
storage_options.uri = tmp_dir.string();

Expand All @@ -214,8 +216,8 @@ TEST_F(SequentialCompressionWriterTest, open_succeeds_twice)
kDefaultCompressionQueueSize, kDefaultCompressionQueueThreads};
initializeWriter(compression_options);

auto tmp_dir = rcpputils::fs::temp_directory_path() / "path_not_empty";
auto tmp_dir_next = rcpputils::fs::temp_directory_path() / "path_not_empty_next";
auto tmp_dir = tmp_dir_ / "path_not_empty";
auto tmp_dir_next = tmp_dir_ / "path_not_empty_next";

auto storage_options = rosbag2_storage::StorageOptions();
auto storage_options_next = rosbag2_storage::StorageOptions();
Expand Down

0 comments on commit a64af18

Please sign in to comment.