diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2017-08-16 12:47:07 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2017-09-06 09:19:52 +0000 |
commit | bb72fddebcf5ef6bed9d9c77d2317383a2a096ce (patch) | |
tree | 9ba98fe57b81c8640456de73295af02a722c3daf /tests/auto/qml/debugger/shared | |
parent | c915f03303f53b0e1aa2796ae980b9ec63984105 (diff) |
Fix remaining race conditions in QQmlDebugProcess
If the process generated a "Cannot listen" message before we
waitForSessionStart(), we would never quit the nested event loop. Also,
unrelated output was not always forwarded, and the event loop was not
terminated when the process unexpectedly stopped.
Also, the timer was started when the process started, not when we
started waiting and we don't want to report the process as crashed if we
kill it ourselves.
In turn, we remove the remaining blacklists.
Task-number: QTQAINFRA-1334
Change-Id: I711aea373911d380f882b00f6d88627edc9f2415
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'tests/auto/qml/debugger/shared')
-rw-r--r-- | tests/auto/qml/debugger/shared/qqmldebugprocess.cpp | 32 | ||||
-rw-r--r-- | tests/auto/qml/debugger/shared/qqmldebugprocess_p.h | 8 |
2 files changed, 25 insertions, 15 deletions
diff --git a/tests/auto/qml/debugger/shared/qqmldebugprocess.cpp b/tests/auto/qml/debugger/shared/qqmldebugprocess.cpp index e9ba7c3957..816fec6a2f 100644 --- a/tests/auto/qml/debugger/shared/qqmldebugprocess.cpp +++ b/tests/auto/qml/debugger/shared/qqmldebugprocess.cpp @@ -35,7 +35,7 @@ QQmlDebugProcess::QQmlDebugProcess(const QString &executable, QObject *parent) : QObject(parent) , m_executable(executable) - , m_started(false) + , m_state(SessionUnknown) , m_port(0) , m_maximumBindErrors(0) , m_receivedBindErrors(0) @@ -47,6 +47,11 @@ QQmlDebugProcess::QQmlDebugProcess(const QString &executable, QObject *parent) this, &QQmlDebugProcess::processAppOutput); connect(&m_process, &QProcess::errorOccurred, this, &QQmlDebugProcess::processError); + connect(&m_process, static_cast<void(QProcess::*)(int)>(&QProcess::finished), + this, [this]() { + m_timer.stop(); + m_eventLoop.quit(); + }); connect(&m_timer, &QTimer::timeout, this, &QQmlDebugProcess::timeout); } @@ -99,8 +104,6 @@ void QQmlDebugProcess::start(const QStringList &arguments) qWarning() << "QML Debug Client: Could not launch app " << m_executable << ": " << m_process.errorString(); m_eventLoop.quit(); - } else { - m_timer.start(); } m_mutex.unlock(); } @@ -108,6 +111,7 @@ void QQmlDebugProcess::start(const QStringList &arguments) void QQmlDebugProcess::stop() { if (m_process.state() != QProcess::NotRunning) { + disconnect(&m_process, &QProcess::errorOccurred, this, &QQmlDebugProcess::processError); m_process.kill(); m_process.waitForFinished(5000); } @@ -131,12 +135,16 @@ bool QQmlDebugProcess::waitForSessionStart() if (m_process.state() != QProcess::Running) { qWarning() << "Could not start up " << m_executable; return false; - } else if (m_started) { + } else if (m_state == SessionStarted) { return true; + } else if (m_state == SessionFailed) { + return false; } + + m_timer.start(); m_eventLoop.exec(); - return m_started; + return m_state == SessionStarted; } int QQmlDebugProcess::debugPort() const @@ -186,7 +194,7 @@ void QQmlDebugProcess::processAppOutput() if (portRx.indexIn(line) != -1) { m_port = portRx.cap(1).toInt(); m_timer.stop(); - m_started = true; + m_state = SessionStarted; m_eventLoop.quit(); continue; } @@ -195,14 +203,15 @@ void QQmlDebugProcess::processAppOutput() if (m_maximumBindErrors == 0) qWarning() << "App was unable to bind to port!"; m_timer.stop(); + m_state = SessionFailed; m_eventLoop.quit(); } continue; } - } else { - // set to true if there is output not coming from the debugger - outputFromAppItself = true; } + + // set to true if there is output not coming from the debugger or we don't understand it + outputFromAppItself = true; } m_mutex.unlock(); @@ -212,9 +221,6 @@ void QQmlDebugProcess::processAppOutput() void QQmlDebugProcess::processError(QProcess::ProcessError error) { - if (!m_eventLoop.isRunning()) - return; - qDebug() << "An error occurred while waiting for debug process to become available:"; switch (error) { case QProcess::FailedToStart: @@ -236,6 +242,4 @@ void QQmlDebugProcess::processError(QProcess::ProcessError error) qDebug() << "Unknown process error."; break; } - - m_eventLoop.exit(); } diff --git a/tests/auto/qml/debugger/shared/qqmldebugprocess_p.h b/tests/auto/qml/debugger/shared/qqmldebugprocess_p.h index 8e4602ace1..fd2c89bb41 100644 --- a/tests/auto/qml/debugger/shared/qqmldebugprocess_p.h +++ b/tests/auto/qml/debugger/shared/qqmldebugprocess_p.h @@ -76,6 +76,12 @@ private slots: void processError(QProcess::ProcessError error); private: + enum SessionState { + SessionUnknown, + SessionStarted, + SessionFailed + }; + QString m_executable; QProcess m_process; QString m_outputBuffer; @@ -83,7 +89,7 @@ private: QTimer m_timer; QEventLoop m_eventLoop; QMutex m_mutex; - bool m_started; + SessionState m_state; QStringList m_environment; int m_port; int m_maximumBindErrors; |