From 9db793f015d56acbce7a2ed77454a2e341ca9385 Mon Sep 17 00:00:00 2001 From: vgsteiger Date: Thu, 19 Oct 2023 17:13:24 +0200 Subject: [PATCH] Fix tests --- .../filesystem_wrapper/local_filesystem_wrapper.cpp | 11 +++++++++-- .../local_filesystem_wrapper_test.cpp | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/modyn/storage/src/internal/filesystem_wrapper/local_filesystem_wrapper.cpp b/modyn/storage/src/internal/filesystem_wrapper/local_filesystem_wrapper.cpp index 6204f50ba..a842227a6 100644 --- a/modyn/storage/src/internal/filesystem_wrapper/local_filesystem_wrapper.cpp +++ b/modyn/storage/src/internal/filesystem_wrapper/local_filesystem_wrapper.cpp @@ -68,8 +68,15 @@ int64_t LocalFilesystemWrapper::get_modified_time(const std::string& path) { ASSERT(is_valid_path(path), fmt::format("Invalid path: {}", path)); ASSERT(exists(path), fmt::format("Path does not exist: {}", path)); - const std::filesystem::file_time_type time = std::filesystem::last_write_time(path); - return std::chrono::duration_cast(time.time_since_epoch()).count(); + // For the most system reliable way to get the file timestamp, we use stat + struct stat file_stat; + if (stat(path.c_str(), &file_stat) != 0) { + FAIL(fmt::format("File timestamp not readable: {}", path)); + } + + time_t file_timestamp = file_stat.st_mtime; + int64_t int64_file_timestamp = static_cast(file_timestamp); + return int64_file_timestamp; } bool LocalFilesystemWrapper::is_valid_path(const std::string& path) { return std::filesystem::exists(path); } diff --git a/modyn/storage/test/unit/internal/filesystem_wrapper/local_filesystem_wrapper_test.cpp b/modyn/storage/test/unit/internal/filesystem_wrapper/local_filesystem_wrapper_test.cpp index 9e19dcd55..dbc68932d 100644 --- a/modyn/storage/test/unit/internal/filesystem_wrapper/local_filesystem_wrapper_test.cpp +++ b/modyn/storage/test/unit/internal/filesystem_wrapper/local_filesystem_wrapper_test.cpp @@ -93,9 +93,9 @@ TEST_F(LocalFilesystemWrapperTest, TestListRecursive) { std::vector files = filesystem_wrapper.list(test_base_dir, /*recursive=*/true); ASSERT_EQ(files.size(), 2); const std::string file_name = test_base_dir + path_seperator + "test_file.txt"; - ASSERT_EQ((files)[1], file_name); const std::string file_name_2 = test_base_dir + path_seperator + "test_dir_2/test_file_2.txt"; - ASSERT_EQ((files)[0], file_name_2); + ASSERT_TRUE(std::find(files.begin(), files.end(), file_name) != files.end()); + ASSERT_TRUE(std::find(files.begin(), files.end(), file_name_2) != files.end()); } TEST_F(LocalFilesystemWrapperTest, TestIsDirectory) {