diff options
author | Michael Meeks <michael.meeks@collabora.com> | 2020-01-20 15:16:36 +0000 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2020-01-21 15:07:54 +0000 |
commit | e844b89d6c4499934576558ff86ba7a34edd827d (patch) | |
tree | 07e6c33ec9a0283a8322e8343620e548b5d9b1bc /test/helpers.hpp | |
parent | 8f91659ae08290c30a56143cb2f0400739a2bafd (diff) |
test: simplify the timeout logic.
Change-Id: I0c253629b983f2813237536e6e2c6d04d5b97dd1
Diffstat (limited to 'test/helpers.hpp')
-rw-r--r-- | test/helpers.hpp | 42 |
1 files changed, 11 insertions, 31 deletions
diff --git a/test/helpers.hpp b/test/helpers.hpp index 19bd8804d..32608b5a2 100644 --- a/test/helpers.hpp +++ b/test/helpers.hpp @@ -261,22 +261,22 @@ std::vector<char> getResponseMessage(LOOLWebSocket& ws, const std::string& prefi try { int flags = 0; - int retries = timeoutMs / 500; - const Poco::Timespan waitTime(retries ? timeoutMs * 1000 / retries : timeoutMs * 1000); std::vector<char> response; - bool timedout = false; + auto endTime = std::chrono::steady_clock::now() + std::chrono::milliseconds(timeoutMs); + ws.setReceiveTimeout(0); do { - if (ws.poll(waitTime, Poco::Net::Socket::SELECT_READ)) + auto now = std::chrono::steady_clock::now(); + if (now > endTime) // timedout + { + TST_LOG("Timeout."); + break; + } + long waitTimeUs = std::chrono::duration_cast<std::chrono::microseconds>(endTime - now).count(); + if (ws.poll(Poco::Timespan(waitTimeUs), Poco::Net::Socket::SELECT_READ)) { - if (timedout) - { - TST_LOG_END; - timedout = false; - } - response.resize(READ_BUFFER_SIZE * 8); const int bytes = ws.receiveFrame(response.data(), response.size(), flags); response.resize(std::max(bytes, 0)); @@ -312,31 +312,11 @@ std::vector<char> getResponseMessage(LOOLWebSocket& ws, const std::string& prefi LOOLProtocol::getAbbreviatedFrameDump(response.data(), bytes, flags)); } } - else - { - if (!timedout) - { - TST_LOG_BEGIN("Timeout (" << (retries > 1 ? "retrying" : "giving up") << ") "); - } - else - { - TST_LOG_APPEND(retries << ' '); - } - - --retries; - timedout = true; - } - } - while (retries > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE); - - if (timedout) - { - TST_LOG_END; } + while ((flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE); } catch (const Poco::Net::WebSocketException& exc) { - TST_LOG_END; TST_LOG(exc.message()); } |