Prevent waiting forever also in CLI tests

This commit is contained in:
Martchus 2019-01-13 23:39:37 +01:00
parent 2370fe1ef5
commit bb513c0a61
1 changed files with 8 additions and 6 deletions

View File

@ -106,16 +106,18 @@ void ApplicationTests::test()
{ {
cerr << "\nWaiting till Syncthing GUI becomes available ..."; cerr << "\nWaiting till Syncthing GUI becomes available ...";
QByteArray syncthingOutput; QByteArray syncthingOutput;
constexpr auto syncthingCheckInterval = TimeSpan::fromMilliseconds(200.0);
const auto maxSyncthingStartupTime = TimeSpan::fromSeconds(15.0 * max(timeoutFactor, 5.0));
auto remainingTimeForSyncthingToComeUp = maxSyncthingStartupTime;
do { do {
// wait for output // wait for output
const auto timeout = static_cast<int>(15000 * TestUtilities::timeoutFactor);
if (!syncthingProcess().bytesAvailable()) { if (!syncthingProcess().bytesAvailable()) {
// fail when already waiting for over 15 seconds // consider test failed if Syncthing takes too long to come up (or we fail to connect)
const auto waitingTime(DateTime::gmtNow() - m_startTime); if ((remainingTimeForSyncthingToComeUp -= syncthingCheckInterval).isNegative()) {
if (waitingTime.milliseconds() > timeout) { CPPUNIT_FAIL(
CPPUNIT_FAIL(argsToString("Syncthing needs longer than ", (timeout / 1000), " seconds to become available.")); argsToString("unable to connect to Syncthing within ", maxSyncthingStartupTime.toString(TimeSpanOutputFormat::WithMeasures)));
} }
syncthingProcess().waitForReadyRead(timeout - waitingTime.milliseconds()); syncthingProcess().waitForReadyRead(static_cast<int>(syncthingCheckInterval.totalMilliseconds()));
} }
syncthingOutput.append(syncthingProcess().readAll()); syncthingOutput.append(syncthingProcess().readAll());
} while (!syncthingOutput.contains("Access the GUI via the following URL")); } while (!syncthingOutput.contains("Access the GUI via the following URL"));