Skip to content

Commit

Permalink
a
Browse files Browse the repository at this point in the history
  • Loading branch information
beef9999 committed Jan 5, 2025
1 parent 544177e commit d880030
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions common/test/test_throttle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,31 +354,28 @@ INSTANTIATE_TEST_P(Throttle, ThrottlePriorityTest, testing::Values(
}
));

static void run_real_socket(const std::atomic<bool>& running, const PriorityTestSuite& p,
static void run_real_socket(const std::shared_ptr<std::atomic<bool>>& running, const PriorityTestSuite& p,
uint64_t& bw1, uint64_t& bw2) {
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();
DEFER(delete server);

auto handler = [&](photon::net::ISocketStream* sock) -> int {
auto handler = [&, _running=running](photon::net::ISocketStream* sock) -> int {
char buf[buf_size];
while (running) {
while (_running) {
ssize_t ret = sock->recv(buf, buf_size);
if (ret <= 0) break;
photon::thread_yield();
}
return 0;
};

auto server_th = photon::thread_create11([&] {
server->setsockopt<int>(SOL_SOCKET, SO_REUSEPORT, 1);
server->set_handler(handler);
server->bind_v4any(0);
server->listen();
server->start_loop(true);
});
photon::thread_yield_to(server_th);
server->setsockopt<int>(SOL_SOCKET, SO_REUSEPORT, 1);
server->set_handler(handler);
server->bind_v4any(0);
server->listen();
server->start_loop(false);

photon::semaphore sem;
auto server_ep = server->getsockname();
Expand Down Expand Up @@ -446,16 +443,15 @@ TEST_P(ThrottlePriorityTest, run) {
const uint64_t test_time_sec = 10;
uint64_t bw1 = 0, bw2 = 0;

std::atomic<bool> running{true};
// std::atomic<bool> running{true};
auto running = std::make_shared<std::atomic<bool>>(true);
std::thread([&] {
::sleep(test_time_sec);
running = false;
*running = false;
}).detach();

if (p.type == PriorityTestSuite::Simulate)
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;
Expand Down

0 comments on commit d880030

Please sign in to comment.