Commit 182cbc72 authored by Georgios Bitzes's avatar Georgios Bitzes
Browse files

Add test for QClient configurable TCP timeout

parent 7164b32f
Pipeline #882035 passed with stages
in 39 minutes
Subproject commit 8c6c8cac07e5ab036188bd9d07828cd57c1d0edd
Subproject commit 29865fbb7f0b977057f9f8727f9575ec558c1c10
......@@ -25,11 +25,10 @@
#include <gtest/gtest.h>
#include <chrono>
TEST(QClient, HostDroppingIncomingPackets) {
TEST(QClient, HostDroppingIncomingPacketsConstructor) {
ASSERT_EQ(system("iptables -I OUTPUT -p tcp --dest 127.0.0.1 --dport 56789 -j DROP"), 0);
qclient::Options opts;
std::unique_ptr<qclient::QClient> qcl;
std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now();
......@@ -53,3 +52,26 @@ TEST(QClient, HostDroppingIncomingPackets) {
ASSERT_EQ(system("iptables -I OUTPUT -p tcp --dest 127.0.0.1 --dport 56789 -j ACCEPT"), 0);
}
TEST(QClient, HostDroppingIncomingPacketsFutureTimeout) {
ASSERT_EQ(system("iptables -I OUTPUT -p tcp --dest 127.0.0.1 --dport 56789 -j DROP"), 0);
qclient::Options opts;
opts.tcpTimeout = std::chrono::seconds(3);
auto start = std::chrono::steady_clock::now();
std::unique_ptr<qclient::QClient> qcl;
qcl.reset(new qclient::QClient("localhost", 56789, std::move(opts)));
qclient::redisReplyPtr reply = qcl->exec("PING").get();
ASSERT_EQ(reply, nullptr);
auto end = std::chrono::steady_clock::now();
std::chrono::milliseconds dur = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
std::cout << "Duration: " << dur.count() << std::endl;
ASSERT_GE(dur, std::chrono::seconds(3));
ASSERT_LE(dur, std::chrono::seconds(4));
ASSERT_EQ(system("iptables -I OUTPUT -p tcp --dest 127.0.0.1 --dport 56789 -j ACCEPT"), 0);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment