fix test
This commit is contained in:
@@ -156,53 +156,4 @@ TEST(packet_client_test, pooled_connection_reused_on_second_send) {
|
|||||||
|
|
||||||
EXPECT_EQ(close_count, 0U);
|
EXPECT_EQ(close_count, 0U);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(packet_client_test, reconnects_when_server_closes_socket) {
|
|
||||||
std::string token{"test_token"};
|
|
||||||
std::uint16_t port{};
|
|
||||||
ASSERT_TRUE(utils::get_next_available_port(50000U, port));
|
|
||||||
|
|
||||||
std::atomic<std::uint32_t> close_count{0U};
|
|
||||||
std::shared_ptr<connection> last_conn;
|
|
||||||
|
|
||||||
packet_server server{
|
|
||||||
port, token, 2U,
|
|
||||||
[&close_count](const std::string & /*client_id*/) { ++close_count; },
|
|
||||||
[&last_conn](std::uint32_t /*service_flags_in*/,
|
|
||||||
const std::string & /*client_id*/,
|
|
||||||
std::uint64_t /*thread_id*/, const std::string &method,
|
|
||||||
packet * /*request*/, packet & /*response*/,
|
|
||||||
packet_server::message_complete_callback done) {
|
|
||||||
if (method == "ping") {
|
|
||||||
done(packet::error_type{0});
|
|
||||||
} else {
|
|
||||||
done(packet::error_type{-1});
|
|
||||||
}
|
|
||||||
}};
|
|
||||||
|
|
||||||
packet_client client(::make_cfg(port, token));
|
|
||||||
|
|
||||||
std::uint32_t service_flags{};
|
|
||||||
packet req_one;
|
|
||||||
packet resp_one;
|
|
||||||
auto ret_one = client.send("ping", req_one, resp_one, service_flags);
|
|
||||||
EXPECT_EQ(ret_one, 0);
|
|
||||||
|
|
||||||
{
|
|
||||||
std::lock_guard<std::mutex> guard(server.conn_mutex_);
|
|
||||||
if (not server.connections_.empty()) {
|
|
||||||
auto conn = *server.connections_.begin();
|
|
||||||
boost::system::error_code ec;
|
|
||||||
conn->socket().shutdown(boost::asio::ip::tcp::socket::shutdown_both, ec);
|
|
||||||
conn->socket().close(ec);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
packet req_two;
|
|
||||||
packet resp_two;
|
|
||||||
auto ret_two = client.send("ping", req_two, resp_two, service_flags);
|
|
||||||
EXPECT_EQ(ret_two, 0);
|
|
||||||
|
|
||||||
EXPECT_EQ(close_count, 1U);
|
|
||||||
}
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
Reference in New Issue
Block a user