diff --git a/tests/auto/qml/debugger/shared/debugutil.cpp b/tests/auto/qml/debugger/shared/debugutil.cpp index 4598e288c7..4e901c7027 100644 --- a/tests/auto/qml/debugger/shared/debugutil.cpp +++ b/tests/auto/qml/debugger/shared/debugutil.cpp @@ -31,25 +31,25 @@ #include -#include #include +#include +#include QQmlDebugTest::QQmlDebugTest(const char *qmlTestDataDir) : QQmlDataTest(qmlTestDataDir) { } -bool QQmlDebugTest::waitForSignal(QObject *receiver, const char *member, int timeout) { - QEventLoop loop; - QTimer timer; - timer.setSingleShot(true); - QObject::connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit())); - QObject::connect(receiver, member, &loop, SLOT(quit())); - timer.start(timeout); - loop.exec(); - if (!timer.isActive()) - qWarning("waitForSignal %s timed out after %d ms", member, timeout); - return timer.isActive(); +bool QQmlDebugTest::waitForSignal(QObject *sender, const char *member, int timeout) +{ + QSignalSpy spy(sender, member); + + // Do not use spy.wait(). We want to avoid nested event loops. + if (QTest::qWaitFor([&]() { return spy.count() > 0; }, timeout)) + return true; + + qWarning("waitForSignal %s timed out after %d ms", member, timeout); + return false; } QList QQmlDebugTest::createOtherClients(QQmlDebugConnection *connection) @@ -154,18 +154,11 @@ QQmlDebugTest::ConnectResult QQmlDebugTest::connectTo( ClientStateHandler stateHandler(m_clients, createOtherClients(m_connection), services.isEmpty() ? QQmlDebugClient::Enabled : QQmlDebugClient::Unavailable); - - const int port = m_process->debugPort(); - m_connection->connectToHost(QLatin1String("127.0.0.1"), port); - - QEventLoop loop; - QTimer timer; - QObject::connect(&stateHandler, &ClientStateHandler::allOk, &loop, &QEventLoop::quit); - QObject::connect(m_connection, &QQmlDebugConnection::disconnected, &loop, &QEventLoop::quit); - QObject::connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit); - - timer.start(5000); - loop.exec(); + QSignalSpy okSpy(&stateHandler, &ClientStateHandler::allOk); + QSignalSpy disconnectSpy(m_connection, &QQmlDebugConnection::disconnected); + m_connection->connectToHost(QLatin1String("127.0.0.1"), m_process->debugPort()); + if (!QTest::qWaitFor([&](){ return okSpy.count() > 0 || disconnectSpy.count() > 0; }, 5000)) + return ConnectionTimeout; if (!stateHandler.allEnabled()) return EnableFailed; @@ -266,3 +259,5 @@ QString debugJsServerPath(const QString &selfPath) return (position == -1 ? appPath : appPath.replace(position, selfPath.length(), debugserver)) + "/" + debugserver; } + +#include "debugutil.moc" diff --git a/tests/auto/qml/debugger/shared/debugutil_p.h b/tests/auto/qml/debugger/shared/debugutil_p.h index 3ef2c56414..826012540e 100644 --- a/tests/auto/qml/debugger/shared/debugutil_p.h +++ b/tests/auto/qml/debugger/shared/debugutil_p.h @@ -62,6 +62,7 @@ public: SessionFailed, ConnectionFailed, ClientsFailed, + ConnectionTimeout, EnableFailed, RestrictFailed };