tests: increase tolerance in several time-sensitive test cases
To avoid spurious failures when CI build bots are overloaded.
Change-Id: If6ec5579dfef1f9fdbd57723e6aeec0a46221a3f
diff --git a/tests/daemon/face/tcp-transport.t.cpp b/tests/daemon/face/tcp-transport.t.cpp
index ef23ca6..96cba88 100644
--- a/tests/daemon/face/tcp-transport.t.cpp
+++ b/tests/daemon/face/tcp-transport.t.cpp
@@ -80,7 +80,7 @@
limitedIo.afterOp();
});
remoteSocket.close();
- BOOST_REQUIRE_EQUAL(limitedIo.run(1, time::seconds(1)), LimitedIo::EXCEED_OPS);
+ BOOST_REQUIRE_EQUAL(limitedIo.run(1, 1_s), LimitedIo::EXCEED_OPS);
bool didStateChange = false;
transport->afterStateChange.connectSingleShot(
@@ -104,7 +104,7 @@
this->limitedIo.afterOp();
});
this->remoteSocket.close();
- BOOST_REQUIRE_EQUAL(this->limitedIo.run(1, time::seconds(1)), LimitedIo::EXCEED_OPS);
+ BOOST_REQUIRE_EQUAL(this->limitedIo.run(1, 1_s), LimitedIo::EXCEED_OPS);
this->transport->afterStateChange.connectSingleShot(
[this] (TransportState oldState, TransportState newState) {
@@ -112,7 +112,7 @@
BOOST_CHECK_EQUAL(newState, TransportState::UP);
this->limitedIo.afterOp();
});
- BOOST_REQUIRE_EQUAL(this->limitedIo.run(1, time::seconds(1)), LimitedIo::EXCEED_OPS);
+ BOOST_REQUIRE_EQUAL(this->limitedIo.run(1, 1_s), LimitedIo::EXCEED_OPS);
}
class PermanentTcpTransportReconnectObserver : public TcpTransport
@@ -174,7 +174,7 @@
BOOST_REQUIRE_EQUAL(error, boost::system::errc::success);
this->limitedIo.afterOp();
});
- BOOST_REQUIRE_EQUAL(this->limitedIo.run(2, time::seconds(1)), LimitedIo::EXCEED_OPS);
+ BOOST_REQUIRE_EQUAL(this->limitedIo.run(2, 1_s), LimitedIo::EXCEED_OPS);
auto transportObserver =
make_unique<PermanentTcpTransportReconnectObserver>(std::move(sock), std::ref(this->limitedIo));
@@ -188,23 +188,23 @@
auto retryTime1 = time::steady_clock::now();
auto expectedWait1 = TcpTransport::s_initialReconnectWait;
- BOOST_REQUIRE_EQUAL(this->limitedIo.run(2, expectedWait1 + time::seconds(1)), // add some slack
+ BOOST_REQUIRE_EQUAL(this->limitedIo.run(2, expectedWait1 + 1_s), // add some slack
LimitedIo::EXCEED_OPS);
auto retryTime2 = time::steady_clock::now();
BOOST_CHECK_EQUAL(transportObserver->getState(), TransportState::DOWN);
auto expectedWait2 = time::duration_cast<time::nanoseconds>(expectedWait1 *
TcpTransport::s_reconnectWaitMultiplier);
- BOOST_REQUIRE_EQUAL(this->limitedIo.run(2, expectedWait2 + time::seconds(1)), // add some slack
+ BOOST_REQUIRE_EQUAL(this->limitedIo.run(2, expectedWait2 + 1_s), // add some slack
LimitedIo::EXCEED_OPS);
auto retryTime3 = time::steady_clock::now();
BOOST_CHECK_EQUAL(transportObserver->getState(), TransportState::DOWN);
// check that the backoff algorithm works
BOOST_CHECK_CLOSE(asFloatMilliseconds(retryTime2 - retryTime1),
- asFloatMilliseconds(expectedWait1), 10.0);
+ asFloatMilliseconds(expectedWait1), 20.0); // 200ms tolerance
BOOST_CHECK_CLOSE(asFloatMilliseconds(retryTime3 - retryTime2),
- asFloatMilliseconds(expectedWait2), 10.0);
+ asFloatMilliseconds(expectedWait2), 10.0); // 200ms tolerance
// reestablish the TCP connection
this->startAccept(remoteEp);
@@ -212,7 +212,7 @@
auto expectedWait3 = time::duration_cast<time::nanoseconds>(expectedWait2 *
TcpTransport::s_reconnectWaitMultiplier);
BOOST_REQUIRE_EQUAL(this->limitedIo.run(3, // reconnect, handleReconnect, async_accept
- expectedWait3 + time::seconds(1)), LimitedIo::EXCEED_OPS);
+ expectedWait3 + 1_s), LimitedIo::EXCEED_OPS);
BOOST_CHECK_EQUAL(transportObserver->getState(), TransportState::UP);
// break the TCP connection again
@@ -221,14 +221,14 @@
// measure retry intervals
auto retryTime4 = time::steady_clock::now();
- BOOST_REQUIRE_EQUAL(this->limitedIo.run(2, expectedWait1 + time::seconds(1)), // add some slack
+ BOOST_REQUIRE_EQUAL(this->limitedIo.run(2, expectedWait1 + 1_s), // add some slack
LimitedIo::EXCEED_OPS);
auto retryTime5 = time::steady_clock::now();
BOOST_CHECK_EQUAL(transportObserver->getState(), TransportState::DOWN);
// check that the timeout restarts from the initial value after a successful reconnection
BOOST_CHECK_CLOSE(asFloatMilliseconds(retryTime5 - retryTime4),
- asFloatMilliseconds(expectedWait1), 10.0);
+ asFloatMilliseconds(expectedWait1), 20.0); // 200ms tolerance
}
BOOST_AUTO_TEST_SUITE_END() // TestTcpTransport
diff --git a/tests/daemon/face/websocket-channel.t.cpp b/tests/daemon/face/websocket-channel.t.cpp
index 439422f..5c4f433 100644
--- a/tests/daemon/face/websocket-channel.t.cpp
+++ b/tests/daemon/face/websocket-channel.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2017, Regents of the University of California,
+ * Copyright (c) 2014-2018, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -49,8 +49,8 @@
void
listen(const ip::address& addr,
- const time::milliseconds& pingInterval = time::seconds(10),
- const time::milliseconds& pongTimeout = time::seconds(1))
+ const time::milliseconds& pingInterval = 10_s,
+ const time::milliseconds& pongTimeout = 1_s)
{
listenerEp = websocket::Endpoint(addr, 20030);
listenerChannel = makeChannel(addr, 20030);
@@ -80,13 +80,13 @@
void
initialize(const ip::address& addr,
- const time::milliseconds& pingInterval = time::seconds(10),
- const time::milliseconds& pongTimeout = time::seconds(1))
+ const time::milliseconds& pingInterval = 10_s,
+ const time::milliseconds& pongTimeout = 1_s)
{
listen(addr, pingInterval, pongTimeout);
clientConnect(client);
BOOST_REQUIRE_EQUAL(limitedIo.run(2, // listenerOnFaceCreated, clientHandleOpen
- time::seconds(1)), LimitedIo::EXCEED_OPS);
+ 1_s), LimitedIo::EXCEED_OPS);
BOOST_REQUIRE_EQUAL(listenerChannel->size(), 1);
}
@@ -150,8 +150,9 @@
std::vector<std::string> clientReceivedMessages;
time::steady_clock::Duration measuredPingInterval;
- bool clientShouldPong = true; // set clientShouldPong false to disable the pong response,
- // which will cause timeout in listenerChannel
+ // set clientShouldPong to false to disable the pong response,
+ // which will eventually cause a timeout in listenerChannel
+ bool clientShouldPong = true;
private:
time::steady_clock::TimePoint m_prevPingRecvTime;
@@ -193,7 +194,7 @@
this->clientConnect(client1);
BOOST_CHECK_EQUAL(limitedIo.run(2, // listenerOnFaceCreated, clientHandleOpen
- time::seconds(1)), LimitedIo::EXCEED_OPS);
+ 1_s), LimitedIo::EXCEED_OPS);
BOOST_CHECK_EQUAL(listenerChannel->size(), 1);
websocket::Client client2;
@@ -202,7 +203,7 @@
this->clientConnect(client3);
BOOST_CHECK_EQUAL(limitedIo.run(4, // 2 listenerOnFaceCreated, 2 clientHandleOpen
- time::seconds(2)), LimitedIo::EXCEED_OPS);
+ 2_s), LimitedIo::EXCEED_OPS);
BOOST_CHECK_EQUAL(listenerChannel->size(), 3);
// check face persistency
@@ -219,14 +220,14 @@
auto transport = listenerFaces.front()->getTransport();
Block pkt1 = ndn::encoding::makeStringBlock(300, "hello");
- transport->send(face::Transport::Packet(Block(pkt1)));
+ transport->send(Transport::Packet(Block(pkt1)));
BOOST_CHECK_EQUAL(limitedIo.run(1, // clientHandleMessage
- time::seconds(1)), LimitedIo::EXCEED_OPS);
+ 1_s), LimitedIo::EXCEED_OPS);
Block pkt2 = ndn::encoding::makeStringBlock(301, "world!");
- transport->send(face::Transport::Packet(Block(pkt2)));
+ transport->send(Transport::Packet(Block(pkt2)));
BOOST_CHECK_EQUAL(limitedIo.run(1, // clientHandleMessage
- time::seconds(1)), LimitedIo::EXCEED_OPS);
+ 1_s), LimitedIo::EXCEED_OPS);
BOOST_REQUIRE_EQUAL(clientReceivedMessages.size(), 2);
BOOST_CHECK_EQUAL_COLLECTIONS(
@@ -252,11 +253,11 @@
clientSendInterest(*interest1);
BOOST_CHECK_EQUAL(limitedIo.run(1, // faceAfterReceiveInterest
- time::seconds(1)), LimitedIo::EXCEED_OPS);
+ 1_s), LimitedIo::EXCEED_OPS);
clientSendInterest(*interest2);
BOOST_CHECK_EQUAL(limitedIo.run(1, // faceAfterReceiveInterest
- time::seconds(1)), LimitedIo::EXCEED_OPS);
+ 1_s), LimitedIo::EXCEED_OPS);
BOOST_REQUIRE_EQUAL(faceReceivedInterests.size(), 2);
BOOST_CHECK_EQUAL(faceReceivedInterests[0].getName(), interest1->getName());
@@ -281,19 +282,19 @@
client.close(clientHandle, websocketpp::close::status::going_away, "");
BOOST_CHECK_EQUAL(limitedIo.run(1, // faceClosedSignal
- time::seconds(1)), LimitedIo::EXCEED_OPS);
+ 1_s), LimitedIo::EXCEED_OPS);
BOOST_CHECK_EQUAL(listenerChannel->size(), 0);
}
BOOST_AUTO_TEST_CASE(SetPingInterval)
{
- const time::milliseconds pingInterval(800);
auto address = getTestIp(AddressFamily::V4, AddressScope::Loopback);
SKIP_IF_IP_UNAVAILABLE(address);
- this->initialize(address, pingInterval, time::milliseconds(1000));
+ const auto pingInterval = 1200_ms;
+ this->initialize(address, pingInterval);
BOOST_CHECK_EQUAL(limitedIo.run(2, // clientHandlePing
- pingInterval * 3), LimitedIo::EXCEED_OPS);
+ pingInterval * 3), LimitedIo::EXCEED_OPS);
BOOST_CHECK_LE(measuredPingInterval, pingInterval * 1.1);
BOOST_CHECK_GE(measuredPingInterval, pingInterval * 0.9);
}
@@ -302,17 +303,18 @@
{
auto address = getTestIp(AddressFamily::V4, AddressScope::Loopback);
SKIP_IF_IP_UNAVAILABLE(address);
- this->initialize(address, time::milliseconds(500), time::milliseconds(300));
+ this->initialize(address, 600_ms, 300_ms);
clientShouldPong = false;
BOOST_CHECK_EQUAL(limitedIo.run(2, // clientHandlePing, faceClosedSignal
- time::seconds(2)), LimitedIo::EXCEED_OPS);
+ 2_s), LimitedIo::EXCEED_OPS);
BOOST_CHECK_EQUAL(listenerChannel->size(), 0);
- auto transport = static_cast<face::WebSocketTransport*>(listenerFaces.front()->getTransport());
- BOOST_CHECK(transport->getState() == face::TransportState::FAILED ||
- transport->getState() == face::TransportState::CLOSED);
- BOOST_CHECK_EQUAL(transport->getCounters().nOutPings, 1);
+ auto transport = static_cast<WebSocketTransport*>(listenerFaces.front()->getTransport());
+ BOOST_CHECK(transport->getState() == TransportState::FAILED ||
+ transport->getState() == TransportState::CLOSED);
+ BOOST_CHECK_GE(transport->getCounters().nOutPings, 1);
+ BOOST_CHECK_LE(transport->getCounters().nOutPings, 2);
BOOST_CHECK_EQUAL(transport->getCounters().nInPongs, 0);
}