tests: Allow specifying timeout factor
The timeout factor is read from environment variable SYNCTHING_TEST_TIMEOUT_FACTOR
This commit is contained in:
parent
471fb7c363
commit
1ed4905139
|
@ -14,6 +14,7 @@ set(HEADER_FILES
|
|||
syncthingtestinstance.h
|
||||
)
|
||||
set(SRC_FILES
|
||||
helper.cpp
|
||||
syncthingtestinstance.cpp
|
||||
)
|
||||
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
#include "./helper.h"
|
||||
|
||||
namespace TestUtilities {
|
||||
|
||||
/*!
|
||||
* \brief Specifies the factor for multiplying all timeouts passed to functions declared in helper.h.
|
||||
*
|
||||
* The default factor is 1.0.
|
||||
*/
|
||||
double timeoutFactor = 1.0;
|
||||
}
|
|
@ -21,8 +21,7 @@ using namespace ConversionUtilities;
|
|||
*/
|
||||
inline std::ostream &operator<<(std::ostream &o, const QString &qstring)
|
||||
{
|
||||
o << qstring.toLocal8Bit().data();
|
||||
return o;
|
||||
return o << qstring.toLocal8Bit().data();
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -30,8 +29,7 @@ inline std::ostream &operator<<(std::ostream &o, const QString &qstring)
|
|||
*/
|
||||
inline std::ostream &operator<<(std::ostream &o, const QStringList &qstringlist)
|
||||
{
|
||||
o << qstringlist.join(QStringLiteral(", ")).toLocal8Bit().data();
|
||||
return o;
|
||||
return o << qstringlist.join(QStringLiteral(", ")).toLocal8Bit().data();
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -39,17 +37,20 @@ inline std::ostream &operator<<(std::ostream &o, const QStringList &qstringlist)
|
|||
*/
|
||||
inline std::ostream &operator<<(std::ostream &o, const QSet<QString> &qstringset)
|
||||
{
|
||||
o << qstringset.toList().join(QStringLiteral(", ")).toLocal8Bit().data();
|
||||
return o;
|
||||
return o << qstringset.toList().join(QStringLiteral(", ")).toLocal8Bit().data();
|
||||
}
|
||||
|
||||
namespace TestUtilities {
|
||||
|
||||
extern double timeoutFactor;
|
||||
|
||||
/*!
|
||||
* \brief Waits for the\a duration specified in ms while keeping the event loop running.
|
||||
*/
|
||||
inline void wait(int duration)
|
||||
{
|
||||
QEventLoop loop;
|
||||
QTimer::singleShot(duration, &loop, &QEventLoop::quit);
|
||||
QTimer::singleShot(duration * timeoutFactor, &loop, &QEventLoop::quit);
|
||||
loop.exec();
|
||||
}
|
||||
|
||||
|
@ -282,7 +283,7 @@ template <typename Action, typename... SignalInfos> void waitForSignals(Action a
|
|||
if (timeout) {
|
||||
QObject::connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit, Qt::DirectConnection);
|
||||
timer.setSingleShot(true);
|
||||
timer.setInterval(timeout);
|
||||
timer.setInterval(timeout * timeoutFactor);
|
||||
timer.start();
|
||||
}
|
||||
|
||||
|
@ -294,9 +295,10 @@ template <typename Action, typename... SignalInfos> void waitForSignals(Action a
|
|||
|
||||
// check whether a timeout occured
|
||||
if (!allSignalsEmitted && timeout && !timer.isActive()) {
|
||||
CPPUNIT_FAIL(
|
||||
argsToString("Signal(s) ", failedSignalNames(signalInfos...).data(), " has/have not emmitted within at least ", timeout, " ms."));
|
||||
CPPUNIT_FAIL(argsToString("Signal(s) ", failedSignalNames(signalInfos...).data(), " has/have not emmitted within at least ", timer.interval(),
|
||||
" ms.", timeoutFactor != 1.0 ? argsToString(" (original timeout: ", timeout, " ms)") : std::string()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // SYNCTHINGTESTHELPER_H
|
||||
|
|
|
@ -1,13 +1,17 @@
|
|||
#include "./syncthingtestinstance.h"
|
||||
#include "./helper.h"
|
||||
|
||||
#include <c++utilities/conversion/conversionexception.h>
|
||||
#include <c++utilities/conversion/stringconversion.h>
|
||||
#include <c++utilities/tests/testutils.h>
|
||||
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
|
||||
using namespace std;
|
||||
using namespace TestUtilities;
|
||||
using namespace ConversionUtilities;
|
||||
|
||||
namespace TestUtilities {
|
||||
|
||||
static int dummy1 = 0;
|
||||
static char *dummy2;
|
||||
|
@ -23,7 +27,18 @@ SyncthingTestInstance::SyncthingTestInstance()
|
|||
*/
|
||||
void SyncthingTestInstance::start()
|
||||
{
|
||||
cerr << "\n - Launching Syncthing ..." << endl;
|
||||
cerr << "\n - Setup configuration for Syncthing tests ..." << endl;
|
||||
|
||||
// set timeout factor for helper
|
||||
const QByteArray timeoutFactorEnv(qgetenv("SYNCTHING_TEST_TIMEOUT_FACTOR"));
|
||||
if (!timeoutFactorEnv.isEmpty()) {
|
||||
try {
|
||||
timeoutFactor = stringToNumber<double>(string(timeoutFactorEnv.data()));
|
||||
cerr << " - Using timeout factor " << timeoutFactor << endl;
|
||||
} catch (const ConversionException &) {
|
||||
cerr << " - Specified SYNCTHING_TEST_TIMEOUT_FACTOR \"" << timeoutFactorEnv.data() << "\" is no valid double and hence ignored" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
// setup st config
|
||||
const string configFilePath = workingCopyPath("testconfig/config.xml");
|
||||
|
@ -55,6 +70,7 @@ void SyncthingTestInstance::start()
|
|||
m_syncthingPort = !syncthingPortFromEnv ? QStringLiteral("4001") : QString::number(syncthingPortFromEnv);
|
||||
|
||||
// start st
|
||||
cerr << "\n - Launching Syncthing ..." << endl;
|
||||
QStringList args;
|
||||
args.reserve(2);
|
||||
args << QStringLiteral("-gui-address=http://localhost:") + m_syncthingPort;
|
||||
|
@ -81,3 +97,4 @@ void SyncthingTestInstance::stop()
|
|||
cerr << "\n - Syncthing stderr during the testrun:\n" << m_syncthingProcess.readAllStandardError().data();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
|
||||
using namespace std;
|
||||
|
||||
namespace TestUtilities {
|
||||
|
||||
/*!
|
||||
* \brief The SyncthingTestInstance class provides running a test instance of Syncthing.
|
||||
*
|
||||
|
@ -57,5 +59,6 @@ inline QProcess &SyncthingTestInstance::syncthingProcess()
|
|||
{
|
||||
return m_syncthingProcess;
|
||||
}
|
||||
}
|
||||
|
||||
#endif // SYNCTHINGTESTHELPER_SYNCTHINGTESTINSTANCE_H
|
||||
|
|
Loading…
Reference in New Issue