Skip to content

Commit

Permalink
Fix test-throttle CI
Browse files Browse the repository at this point in the history
  • Loading branch information
beef9999 committed Jan 6, 2025
1 parent 83a6ffb commit 11f5df9
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 49 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.linux.arm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
40 changes: 20 additions & 20 deletions .github/workflows/ci.linux.x86_64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down
68 changes: 41 additions & 27 deletions common/test/test_throttle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -250,6 +250,8 @@ struct PriorityTestSuite {
};

class ThrottlePriorityTest : public testing::TestWithParam<PriorityTestSuite> {
protected:
std::atomic<bool> running_{true};
};

INSTANTIATE_TEST_P(Throttle, ThrottlePriorityTest, testing::Values(
Expand Down Expand Up @@ -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,
}
Expand All @@ -333,6 +335,7 @@ static void run_real_socket(const std::atomic<bool>& 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 {
Expand All @@ -344,46 +347,56 @@ static void run_real_socket(const std::atomic<bool>& running, const PriorityTest
}
return 0;
};
server->setsockopt<int>(SOL_SOCKET, SO_REUSEPORT, 1);

int ret = server->setsockopt<int>(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);
if (ret <= 0) break;
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);
if (ret <= 0) break;
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<bool>& running, const PriorityTestSuite& p,
Expand Down Expand Up @@ -416,26 +429,27 @@ TEST_P(ThrottlePriorityTest, run) {
const uint64_t test_time_sec = 10;
uint64_t bw1 = 0, bw2 = 0;

std::atomic<bool> 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

Expand Down

0 comments on commit 11f5df9

Please sign in to comment.