diff --git a/src/plugins/squish/squishprocessbase.cpp b/src/plugins/squish/squishprocessbase.cpp index 7b68f70a553..23d3a49aa70 100644 --- a/src/plugins/squish/squishprocessbase.cpp +++ b/src/plugins/squish/squishprocessbase.cpp @@ -22,4 +22,22 @@ void SquishProcessBase::setState(SquishProcessState state) emit stateChanged(state); } +void SquishProcessBase::start(const Utils::CommandLine &cmdline, const Utils::Environment &env) +{ + QTC_ASSERT(m_process.state() == QProcess::NotRunning, return); + // avoid crashes on fast re-use + m_process.close(); + + m_process.setCommand(cmdline); + m_process.setEnvironment(env); + + setState(Starting); + m_process.start(); + if (!m_process.waitForStarted()) { + setState(StartFailed); + qWarning() << "squishprocess did not start within 30s"; + } + setState(Started); +} + } // namespace Squish::Internal diff --git a/src/plugins/squish/squishprocessbase.h b/src/plugins/squish/squishprocessbase.h index 946d5aa40de..088eca8a73b 100644 --- a/src/plugins/squish/squishprocessbase.h +++ b/src/plugins/squish/squishprocessbase.h @@ -32,6 +32,7 @@ signals: protected: void setState(SquishProcessState state); + virtual void start(const Utils::CommandLine &cmdline, const Utils::Environment &env); virtual void onDone() {} virtual void onErrorOutput() {} diff --git a/src/plugins/squish/squishserverprocess.cpp b/src/plugins/squish/squishserverprocess.cpp index 006eeb594b6..4d7bb2ef97f 100644 --- a/src/plugins/squish/squishserverprocess.cpp +++ b/src/plugins/squish/squishserverprocess.cpp @@ -18,20 +18,8 @@ void SquishServerProcess::start(const Utils::CommandLine &commandLine, const Utils::Environment &environment) { QTC_ASSERT(m_process.state() == QProcess::NotRunning, return); - // especially when writing server config we re-use the process fast and start the server - // several times and may crash as the process may not have been cleanly destructed yet - m_process.close(); - m_serverPort = -1; - m_process.setCommand(commandLine); - m_process.setEnvironment(environment); - - setState(Starting); - m_process.start(); - if (!m_process.waitForStarted()) { - setState(StartFailed); - qWarning() << "squishserver did not start within 30s"; - } + SquishProcessBase::start(commandLine, environment); } void SquishServerProcess::stop() @@ -68,7 +56,7 @@ void SquishServerProcess::onStandardOutput() int port = trimmed.mid(6).toInt(&ok); if (ok) { m_serverPort = port; - setState(Started); + emit portRetrieved(); } else { qWarning() << "could not get port number" << trimmed.mid(6); setState(StartFailed); diff --git a/src/plugins/squish/squishserverprocess.h b/src/plugins/squish/squishserverprocess.h index 3503dfbd0cc..2be419c1e75 100644 --- a/src/plugins/squish/squishserverprocess.h +++ b/src/plugins/squish/squishserverprocess.h @@ -19,9 +19,12 @@ public: int port() const { return m_serverPort; } void start(const Utils::CommandLine &commandLine, - const Utils::Environment &environment); + const Utils::Environment &environment) override; void stop(); +signals: + void portRetrieved(); + private: void onStandardOutput(); void onErrorOutput() override; diff --git a/src/plugins/squish/squishtools.cpp b/src/plugins/squish/squishtools.cpp index 9266c9dd2ca..194a9c85f14 100644 --- a/src/plugins/squish/squishtools.cpp +++ b/src/plugins/squish/squishtools.cpp @@ -111,6 +111,8 @@ SquishTools::SquishTools(QObject *parent) this, &SquishTools::onServerStateChanged); connect(&m_serverProcess, &SquishServerProcess::logOutputReceived, this, &SquishTools::logOutputReceived); + connect(&m_serverProcess, &SquishServerProcess::portRetrieved, + this, &SquishTools::onServerPortRetrieved); s_instance = this; m_perspective.initPerspective(); @@ -336,7 +338,6 @@ void SquishTools::onServerStateChanged(SquishProcessState state) break; case Started: logAndChangeToolsState(SquishTools::ServerStarted); - onServerStarted(); break; case StartFailed: logAndChangeToolsState(SquishTools::ServerStartFailed); @@ -356,8 +357,9 @@ void SquishTools::onServerStateChanged(SquishProcessState state) } } -void SquishTools::onServerStarted() +void SquishTools::onServerPortRetrieved() { + QTC_ASSERT(m_state == ServerStarted, return); if (m_request == RunnerQueryRequested) { executeRunnerQuery(); } else if (m_request == RunTestRequested || m_request == RecordTestRequested) { diff --git a/src/plugins/squish/squishtools.h b/src/plugins/squish/squishtools.h index 7b29386ea63..52c6aa4d66f 100644 --- a/src/plugins/squish/squishtools.h +++ b/src/plugins/squish/squishtools.h @@ -92,7 +92,7 @@ private: void logAndChangeRunnerState(RunnerState to); void logAndChangeToolsState(SquishTools::State to); void onServerStateChanged(SquishProcessState state); - void onServerStarted(); + void onServerPortRetrieved(); void onServerStopped(); void onServerStartFailed(); void onServerStopFailed();