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 13:39:42 +0000 |
commit | c7fb1f31b2cf3c3c256aeda499b1858e1820337a (patch) | |
tree | bf99d1fc06d393e9c0b12c5ee0be2dd88614abf7 | |
parent | 0edf084c5da2dd600851134d4327734925e379df (diff) |
test: simplify the timeout logic.
Change-Id: I0c253629b983f2813237536e6e2c6d04d5b97dd1
-rw-r--r-- | test/data/convert-to.xlsx | bin | 6056 -> 6065 bytes | |||
-rw-r--r-- | test/helpers.hpp | 42 |
2 files changed, 11 insertions, 31 deletions
diff --git a/test/data/convert-to.xlsx b/test/data/convert-to.xlsx Binary files differindex 7af9e7063..344ee0d13 100644 --- a/test/data/convert-to.xlsx +++ b/test/data/convert-to.xlsx 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()); } |