From 11f5df937475fd824e52af90ff9fff75a15cf107 Mon Sep 17 00:00:00 2001 From: Bob Chen Date: Sun, 5 Jan 2025 16:05:45 +0800 Subject: [PATCH] Fix test-throttle CI --- .github/workflows/ci.linux.arm.yml | 4 +- .github/workflows/ci.linux.x86_64.yml | 40 ++++++++-------- common/test/test_throttle.cpp | 68 ++++++++++++++++----------- 3 files changed, 63 insertions(+), 49 deletions(-) diff --git a/.github/workflows/ci.linux.arm.yml b/.github/workflows/ci.linux.arm.yml index d5b4fe96..1f061969 100644 --- a/.github/workflows/ci.linux.arm.yml +++ b/.github/workflows/ci.linux.arm.yml @@ -34,13 +34,13 @@ jobs: -D PHOTON_ENABLE_URING=ON \ -D PHOTON_ENABLE_LIBCURL=ON \ -D PHOTON_ENABLE_EXTFS=ON - cmake --build build -j $(nproc) -- VERBOSE=1 + cmake --build build -j $(nproc) - name: Test run: | cd build nohup redis-server & - ctest -E test-lockfree --timeout 3600 -V + ctest --timeout 3600 -V pkill redis-server debug-build-from-source: diff --git a/.github/workflows/ci.linux.x86_64.yml b/.github/workflows/ci.linux.x86_64.yml index ba6ab9a4..6f17a798 100644 --- a/.github/workflows/ci.linux.x86_64.yml +++ b/.github/workflows/ci.linux.x86_64.yml @@ -29,23 +29,23 @@ jobs: -D PHOTON_ENABLE_URING=ON \ -D PHOTON_ENABLE_LIBCURL=ON \ -D PHOTON_ENABLE_EXTFS=ON - cmake --build build -j $(nproc) -- VERBOSE=1 + cmake --build build -j $(nproc) - name: Test epoll run: | nohup redis-server & - cd build && ctest -E test-lockfree --timeout 3600 -V + cd build && ctest --timeout 3600 -V pkill redis-server - name: Test io_uring run: | nohup redis-server & export PHOTON_CI_EV_ENGINE=io_uring - cd build && ctest -E test-lockfree --timeout 3600 -V + cd build && ctest --timeout 3600 -V pkill redis-server - name: Test epoll_ng run: | nohup redis-server & export PHOTON_CI_EV_ENGINE=epoll_ng - cd build && ctest -E test-lockfree --timeout 3600 -V + cd build && ctest --timeout 3600 -V pkill redis-server gcc921: @@ -71,23 +71,23 @@ jobs: -D PHOTON_ENABLE_URING=ON \ -D PHOTON_ENABLE_LIBCURL=ON \ -D PHOTON_ENABLE_EXTFS=ON - cmake --build build -j $(nproc) -- VERBOSE=1 + cmake --build build -j $(nproc) - name: Test epoll run: | nohup redis-server & - cd build && ctest -E test-lockfree --timeout 3600 -V + cd build && ctest --timeout 3600 -V pkill redis-server - name: Test io_uring run: | nohup redis-server & export PHOTON_CI_EV_ENGINE=io_uring - cd build && ctest -E test-lockfree --timeout 3600 -V + cd build && ctest --timeout 3600 -V pkill redis-server - name: Test epoll_ng run: | nohup redis-server & export PHOTON_CI_EV_ENGINE=epoll_ng - cd build && ctest -E test-lockfree --timeout 3600 -V + cd build && ctest --timeout 3600 -V pkill redis-server gcc1031: @@ -113,23 +113,23 @@ jobs: -D PHOTON_ENABLE_URING=ON \ -D PHOTON_ENABLE_LIBCURL=ON \ -D PHOTON_ENABLE_EXTFS=ON - cmake --build build -j $(nproc) -- VERBOSE=1 + cmake --build build -j $(nproc) - name: Test epoll run: | nohup redis-server & - cd build && ctest -E test-lockfree --timeout 3600 -V + cd build && ctest --timeout 3600 -V pkill redis-server - name: Test io_uring run: | nohup redis-server & export PHOTON_CI_EV_ENGINE=io_uring - cd build && ctest -E test-lockfree --timeout 3600 -V + cd build && ctest --timeout 3600 -V pkill redis-server - name: Test epoll_ng run: | nohup redis-server & export PHOTON_CI_EV_ENGINE=epoll_ng - cd build && ctest -E test-lockfree --timeout 3600 -V + cd build && ctest --timeout 3600 -V pkill redis-server gcc1121: @@ -155,23 +155,23 @@ jobs: -D PHOTON_ENABLE_URING=ON \ -D PHOTON_ENABLE_LIBCURL=ON \ -D PHOTON_ENABLE_EXTFS=ON - cmake --build build -j $(nproc) -- VERBOSE=1 + cmake --build build -j $(nproc) - name: Test epoll run: | nohup redis-server & - cd build && ctest -E test-lockfree --timeout 3600 -V + cd build && ctest --timeout 3600 -V pkill redis-server - name: Test io_uring run: | nohup redis-server & export PHOTON_CI_EV_ENGINE=io_uring - cd build && ctest -E test-lockfree --timeout 3600 -V + cd build && ctest --timeout 3600 -V pkill redis-server - name: Test epoll_ng run: | nohup redis-server & export PHOTON_CI_EV_ENGINE=epoll_ng - cd build && ctest -E test-lockfree --timeout 3600 -V + cd build && ctest --timeout 3600 -V pkill redis-server gcc1211: @@ -197,23 +197,23 @@ jobs: -D PHOTON_ENABLE_URING=ON \ -D PHOTON_ENABLE_LIBCURL=ON \ -D PHOTON_ENABLE_EXTFS=ON - cmake --build build -j $(nproc) -- VERBOSE=1 + cmake --build build -j $(nproc) - name: Test epoll run: | nohup redis-server & - cd build && ctest -E test-lockfree --timeout 3600 -V + cd build && ctest --timeout 3600 -V pkill redis-server - name: Test io_uring run: | nohup redis-server & export PHOTON_CI_EV_ENGINE=io_uring - cd build && ctest -E test-lockfree --timeout 3600 -V + cd build && ctest --timeout 3600 -V pkill redis-server - name: Test epoll_ng run: | nohup redis-server & export PHOTON_CI_EV_ENGINE=epoll_ng - cd build && ctest -E test-lockfree --timeout 3600 -V + cd build && ctest --timeout 3600 -V pkill redis-server fstack: diff --git a/common/test/test_throttle.cpp b/common/test/test_throttle.cpp index 18ebe18d..f528987b 100644 --- a/common/test/test_throttle.cpp +++ b/common/test/test_throttle.cpp @@ -205,10 +205,10 @@ TEST_P(FindAppropriateSliceNumTest, run) { t.consume(bs_per_io); bytes += bs_per_io; } - auto goal = bw * 10; + auto goal = bw * test_time_sec; auto diff = int64_t(bytes) - int64_t(goal); auto loss = double(std::abs(diff)) / double(goal); - LOG_INFO("Consume ` bytes in 10 seconds, loss ratio `", bytes, loss); + LOG_INFO("Consume ` bytes in ` seconds, loss ratio `", bytes, test_time_sec, loss); GTEST_ASSERT_LE(loss, p.performance_loss_max_ratio); } @@ -250,6 +250,8 @@ struct PriorityTestSuite { }; class ThrottlePriorityTest : public testing::TestWithParam { +protected: + std::atomic running_{true}; }; INSTANTIATE_TEST_P(Throttle, ThrottlePriorityTest, testing::Values( @@ -320,9 +322,9 @@ INSTANTIATE_TEST_P(Throttle, ThrottlePriorityTest, testing::Values( PriorityTestSuite{ // 7. Real socket. Low priority gets the rest BW that high priority doesn't need PriorityTestSuite::RealSocket, - 10'000'000, - {5'000'000, 10'000, photon::throttle::Priority::High}, - {100'000'000, 4'000'000, photon::throttle::Priority::Low}, + 100'000'000, + {50'000'000, 10'000, photon::throttle::Priority::High}, + {1'000'000'000, 4'000'000, photon::throttle::Priority::Low}, 0.4, 0.6, 0.4, 0.6, } @@ -333,6 +335,7 @@ static void run_real_socket(const std::atomic& running, const PriorityTest photon::throttle t(p.limit_bw); uint64_t buf_size = std::max(p.io1.bs, p.io2.bs); auto server = photon::net::new_tcp_socket_server(); + ASSERT_NE(nullptr, server); DEFER(delete server); auto handler = [&](photon::net::ISocketStream* sock) -> int { @@ -344,22 +347,28 @@ static void run_real_socket(const std::atomic& running, const PriorityTest } return 0; }; - server->setsockopt(SOL_SOCKET, SO_REUSEPORT, 1); + + int ret = server->setsockopt(SOL_SOCKET, SO_REUSEPORT, 1); + ASSERT_EQ(0, ret); server->set_handler(handler); - server->bind_v4any(0); - server->listen(); - server->start_loop(false); + ret = server->bind_v4any(0); + ASSERT_EQ(0, ret); + ret = server->listen(); + ASSERT_EQ(0, ret); + ret = server->start_loop(false); + ASSERT_EQ(0, ret); - photon::semaphore sem; auto server_ep = server->getsockname(); auto cli = photon::net::new_tcp_socket_client(); + ASSERT_NE(nullptr, cli); DEFER(delete cli); - photon::thread_create11([&] { + auto client_th1 = photon::thread_create11([&] { photon::throttle src(p.io1.bw); auto conn = cli->connect(server_ep); + if (!conn) exit(1); DEFER(delete conn); - char buf[buf_size]; + char buf[buf_size] = {}; while (running) { src.consume(p.io1.bs); ssize_t ret = conn->send(buf, p.io1.bs); @@ -367,13 +376,15 @@ static void run_real_socket(const std::atomic& running, const PriorityTest bw1 += p.io1.bs; t.consume(p.io1.bs, p.io1.prio); } - sem.signal(1); }); - photon::thread_create11([&] { + thread_enable_join(client_th1); + + auto client_th2 = photon::thread_create11([&] { photon::throttle src(p.io2.bw); auto conn = cli->connect(server_ep); + if (!conn) exit(1); DEFER(delete conn); - char buf[buf_size]; + char buf[buf_size] = {}; while (running) { src.consume(p.io2.bs); ssize_t ret = conn->send(buf, p.io2.bs); @@ -381,9 +392,11 @@ static void run_real_socket(const std::atomic& running, const PriorityTest bw2 += p.io2.bs; t.consume(p.io2.bs, p.io2.prio); } - sem.signal(1); }); - sem.wait(2); + thread_enable_join(client_th2); + + photon::thread_join((photon::join_handle*) client_th1); + photon::thread_join((photon::join_handle*) client_th2); } static void run_simulate(const std::atomic& running, const PriorityTestSuite& p, @@ -416,26 +429,27 @@ TEST_P(ThrottlePriorityTest, run) { const uint64_t test_time_sec = 10; uint64_t bw1 = 0, bw2 = 0; - std::atomic running{true}; - std::thread([&] { + std::thread watcher([&] { ::sleep(test_time_sec); - running = false; - }).detach(); + running_ = false; + }); if (p.type == PriorityTestSuite::Simulate) - run_simulate(running, p, bw1, bw2); + run_simulate(running_, p, bw1, bw2); else if (p.type == PriorityTestSuite::RealSocket) - run_real_socket(running, p, bw1, bw2); + run_real_socket(running_, p, bw1, bw2); bw1 /= test_time_sec; bw2 /= test_time_sec; double ratio1 = double(bw1) / double(p.limit_bw); double ratio2 = double(bw2) / double(p.limit_bw); LOG_INFO(VALUE(bw1), VALUE(bw2), VALUE(ratio1), VALUE(ratio2)); - GTEST_ASSERT_GE(ratio1, p.bw1_ratio_min); - GTEST_ASSERT_LE(ratio1, p.bw1_ratio_max); - GTEST_ASSERT_GE(ratio2, p.bw2_ratio_min); - GTEST_ASSERT_LE(ratio2, p.bw2_ratio_max); + EXPECT_GE(ratio1, p.bw1_ratio_min); + EXPECT_LE(ratio1, p.bw1_ratio_max); + EXPECT_GE(ratio2, p.bw2_ratio_min); + EXPECT_LE(ratio2, p.bw2_ratio_max); + + watcher.join(); } #endif