AutoTest: Cancel possible running tasks on shutdown

If tasks are running while shutting down we might end up in a crash,
so cancel all tasks and handle possible invalid accesses of the
current running processing.

Change-Id: I69f7cac5f44390e322fa301af6d6794270c95c2a
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Christian Stenger
2016-07-08 12:53:57 +02:00
parent e70adf820e
commit 48b2af5e77
6 changed files with 32 additions and 4 deletions

View File

@@ -85,6 +85,8 @@ TestCodeParser::~TestCodeParser()
void TestCodeParser::setState(State state)
{
if (m_parserState == Shutdown)
return;
qCDebug(LOG) << "setState(" << state << "), currentState:" << m_parserState;
// avoid triggering parse before code model parsing has finished, but mark as dirty
if (m_codeModelParsing) {
@@ -175,6 +177,8 @@ static bool checkDocumentForTestCode(QFutureInterface<TestParseResultPtr> &futur
const QVector<ITestParser *> &parsers)
{
foreach (ITestParser *currentParser, parsers) {
if (futureInterface.isCanceled())
return false;
if (currentParser->processDocument(futureInterface, fileName))
return true;
}
@@ -253,6 +257,17 @@ void TestCodeParser::onProjectPartsUpdated(ProjectExplorer::Project *project)
emitUpdateTestTree();
}
void TestCodeParser::aboutToShutdown()
{
qCDebug(LOG) << "Disabling (immediately) - shutting down";
State oldState = m_parserState;
m_parserState = Shutdown;
if (oldState == PartialParse || oldState == FullParse) {
m_futureWatcher.cancel();
m_futureWatcher.waitForFinished();
}
}
bool TestCodeParser::postponed(const QStringList &fileList)
{
switch (m_parserState) {
@@ -278,6 +293,7 @@ bool TestCodeParser::postponed(const QStringList &fileList)
}
return true;
case Disabled:
case Shutdown:
break;
}
QTC_ASSERT(false, return false); // should not happen at all
@@ -285,7 +301,7 @@ bool TestCodeParser::postponed(const QStringList &fileList)
void TestCodeParser::scanForTests(const QStringList &fileList)
{
if (m_parserState == Disabled) {
if (m_parserState == Disabled || m_parserState == Shutdown) {
m_dirty = true;
if (fileList.isEmpty()) {
m_fullUpdatePostponed = true;
@@ -390,6 +406,9 @@ void TestCodeParser::onFinished()
qCDebug(LOG) << "emitting parsingFinished (onFinished, Disabled)";
emit parsingFinished();
break;
case Shutdown:
qCDebug(LOG) << "Shutdown complete - not emitting parsingFinished (onFinished)";
break;
default:
qWarning("I should not be here... State: %d", m_parserState);
break;