Squish: Add common start function to process base

Starting the process is similar for the tools, so extract it
to the base class.
Make it virtual to let the tools still be able to re-init internal
members.
Slightly changes the startup of the server as the Started state
was emitted later manually after the port in use had been known.

Change-Id: Iea88ce88e8a12a7723460adaa25f7b9a5cd9a2b8
Reviewed-by: David Schulz <david.schulz@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Christian Stenger
2023-01-09 11:25:35 +01:00
parent 01f85a1e1e
commit 8f8150db2d
6 changed files with 30 additions and 18 deletions

View File

@@ -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

View File

@@ -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() {}

View File

@@ -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);

View File

@@ -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;

View File

@@ -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) {

View File

@@ -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();