Skip to content

Commit

Permalink
fix cmake pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
oathdruid committed Aug 9, 2024
1 parent 4df5d59 commit 6dfd550
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,4 @@ jobs:
- uses: hendrikmuhs/[email protected]
- run: cmake -Bbuild -DBUILD_DEPS=ON -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
- run: cmake --build build --parallel $(nproc)
- run: ctest --test-dir build --exclude-regex MemoryLockerTest --output-on-failure --parallel $(($(nproc) / 2))
- run: ctest --test-dir build --output-on-failure --parallel $(nproc)
23 changes: 13 additions & 10 deletions test/logging/test_rolling_file_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,33 @@ using ::babylon::RollingFileObject;

struct RollingFileObjectTest : public ::testing::Test {
virtual void SetUp() override {
::std::filesystem::remove_all("log");
rolling_object.set_directory("log");
directory = "log_" + ::std::to_string(getpid());
::std::filesystem::remove_all(directory);
rolling_object.set_directory(directory);
rolling_object.set_file_pattern("name.%Y%m%d-%H%M%S");
object = &rolling_object;
}

virtual void TearDown() override {
::std::filesystem::remove_all(directory);
}

::std::string directory;
RollingFileObject rolling_object;
FileObject* object;
};

TEST_F(RollingFileObjectTest, file_first_create_when_get_trigger) {
object->check_and_get_file_descriptor();
{
::std::filesystem::directory_iterator dir {"log"};
::std::filesystem::directory_iterator dir {directory};
ASSERT_EQ(1, ::std::distance(begin(dir), end(dir)));
}
}

TEST_F(RollingFileObjectTest, keep_file_dont_exceed_num) {
::std::filesystem::create_directory("log");
::std::ofstream {"log/name.00000000-000000"};
::std::filesystem::create_directory(directory);
::std::ofstream {directory + "/name.00000000-000000"};

::std::vector<int> old_fds;
rolling_object.set_max_file_number(3);
Expand All @@ -42,11 +48,10 @@ TEST_F(RollingFileObjectTest, keep_file_dont_exceed_num) {
old_fds.emplace_back(old_fd);
}
rolling_object.delete_expire_files();
::usleep(100 * 1000);
}

{
::std::filesystem::directory_iterator dir {"log"};
::std::filesystem::directory_iterator dir {directory};
ASSERT_EQ(3, ::std::distance(begin(dir), end(dir)));
}

Expand All @@ -66,15 +71,13 @@ TEST_F(RollingFileObjectTest, fd_refer_to_latest_file) {
old_fds.emplace_back(old_fd);
}
rolling_object.delete_expire_files();
::usleep(100 * 1000);
last_fd = fd;
}

ASSERT_NE(-1, last_fd);
ASSERT_LT(0, ::dprintf(last_fd, "this should appear in file\n"));
::std::filesystem::directory_iterator dir {"log"};
::std::filesystem::directory_iterator dir {directory};
auto entry = *begin(dir);
::usleep(100 * 1000);
::std::ifstream ifs {entry.path()};
ASSERT_TRUE(ifs);
::std::string line;
Expand Down
14 changes: 8 additions & 6 deletions test/test_mlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,20 @@ const static size_t CEILED_REGION_SIZE =

struct MemoryLockerTest : public ::testing::Test {
virtual void SetUp() override {
fd = ::open("mlock_file", O_CREAT | O_RDWR | O_TRUNC, 0644);
file_name = "mlock_" + ::std::to_string(getpid());
fd = ::open(file_name.c_str(), O_CREAT | O_RDWR | O_TRUNC, 0644);
ASSERT_EQ(0, ::ftruncate(fd, REGION_SIZE));
region = ::mmap(nullptr, REGION_SIZE, PROT_READ, MAP_PRIVATE, fd, 0);
MemoryLocker::instance().set_check_interval(::std::chrono::seconds(1));
MemoryLocker::instance().set_filter([](StringView path) {
return nullptr == strstr(path.data(), "mlock_file");
MemoryLocker::instance().set_filter([this](StringView path) {
return nullptr == strstr(path.data(), file_name.c_str());
});
}

virtual void TearDown() override {
::munmap(region, REGION_SIZE);
::close(fd);
::unlink(file_name.c_str());
}

bool region_in_memory() {
Expand All @@ -56,6 +58,7 @@ struct MemoryLockerTest : public ::testing::Test {
}
}

::std::string file_name;
MemoryLocker& locker = MemoryLocker::instance();
int fd;
void* region;
Expand All @@ -65,7 +68,6 @@ TEST_F(MemoryLockerTest, lock_regions_before_start) {
ASSERT_FALSE(region_in_memory());
ASSERT_EQ(0, MemoryLocker::instance().start());
next_round();
::usleep(1000 * 1000);
BABYLON_LOG(INFO) << "before check region_in_memory";
ASSERT_TRUE(region_in_memory());
ASSERT_EQ(CEILED_REGION_SIZE, MemoryLocker::instance().locked_bytes());
Expand Down Expand Up @@ -123,8 +125,8 @@ TEST_F(MemoryLockerTest, stop_when_destroy) {
{
MemoryLocker locker;
locker.set_check_interval(::std::chrono::seconds(1));
locker.set_filter([](StringView path) {
return nullptr == strstr(path.data(), "mlock_file");
locker.set_filter([this](StringView path) {
return nullptr == strstr(path.data(), file_name.c_str());
});
ASSERT_EQ(0, locker.start());
ASSERT_FALSE(region_in_memory());
Expand Down

0 comments on commit 6dfd550

Please sign in to comment.