From d0b258a5dfba374b557d176307e9665a447df891 Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Mon, 18 Jan 2016 14:37:32 +0100 Subject: [PATCH] Make TestRunner more thread-safe Change-Id: I42e5c9e26a45ef2875cf70e1c5e3b989bcce4de8 Reviewed-by: Eike Ziller --- plugins/autotest/testconfiguration.h | 10 ++++------ plugins/autotest/testrunner.cpp | 17 +++++++++-------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/plugins/autotest/testconfiguration.h b/plugins/autotest/testconfiguration.h index 7b39ae879cb..7fb915fbb55 100644 --- a/plugins/autotest/testconfiguration.h +++ b/plugins/autotest/testconfiguration.h @@ -22,15 +22,13 @@ #include "autotestconstants.h" +#include #include #include +#include #include -namespace ProjectExplorer { -class Project; -} - namespace Autotest { namespace Internal { @@ -68,7 +66,7 @@ public: QString workingDirectory() const { return m_workingDir; } QString displayName() const { return m_displayName; } Utils::Environment environment() const { return m_environment; } - ProjectExplorer::Project *project() const { return m_project; } + ProjectExplorer::Project *project() const { return m_project.data(); } bool unnamedOnly() const { return m_unnamedOnly; } bool guessedConfiguration() const { return m_guessedConfiguration; } TestType testType() const { return m_type; } @@ -85,7 +83,7 @@ private: QString m_workingDir; QString m_displayName; Utils::Environment m_environment; - ProjectExplorer::Project *m_project; + QPointer m_project; bool m_guessedConfiguration; TestType m_type; }; diff --git a/plugins/autotest/testrunner.cpp b/plugins/autotest/testrunner.cpp index 84d500ccdcf..67f9ead4f6a 100644 --- a/plugins/autotest/testrunner.cpp +++ b/plugins/autotest/testrunner.cpp @@ -44,7 +44,7 @@ namespace Internal { static TestRunner *m_instance = 0; -void emitTestResultCreated(TestResult *testResult) +static void emitTestResultCreated(TestResult *testResult) { emit m_instance->testResultCreated(testResult); } @@ -105,9 +105,9 @@ void TestRunner::setSelectedTests(const QList &selected) m_selectedTests = selected; } -void performTestRun(QFutureInterface &futureInterface, - const QList selectedTests, const int timeout, - const QString metricsOption, TestRunner* testRunner) +static void performTestRun(QFutureInterface &futureInterface, + const QList selectedTests, const int timeout, + const QString metricsOption) { int testCaseCount = 0; foreach (TestConfiguration *config, selectedTests) { @@ -124,9 +124,6 @@ void performTestRun(QFutureInterface &futureInterface, QProcess testProcess; testProcess.setReadChannelMode(QProcess::MergedChannels); testProcess.setReadChannel(QProcess::StandardOutput); - QObject::connect(testRunner, &TestRunner::requestStopTestRun, &testProcess, [&] () { - futureInterface.cancel(); // this kills the process if that is still in the running loop - }); TestOutputReader outputReader(&testProcess); QObject::connect(&outputReader, &TestOutputReader::increaseProgress, [&] () { @@ -278,11 +275,15 @@ void TestRunner::runTests() Qt::QueuedConnection); QFuture future = QtConcurrent::run(&performTestRun, m_selectedTests, settings->timeout, - metricsOption, this); + metricsOption); + Core::FutureProgress *progress = Core::ProgressManager::addTask(future, tr("Running Tests"), Autotest::Constants::TASK_INDEX); connect(progress, &Core::FutureProgress::finished, TestRunner::instance(), &TestRunner::onFinished); + connect(this, &TestRunner::requestStopTestRun, progress, [progress]() { + progress->future().cancel(); + }); } void TestRunner::buildProject(ProjectExplorer::Project *project)