AutoTest: Fix handling of enabled state for code parser

Avoid unintentional re-enabling of the code parser.
Handling of the enabled state broke several times before,
therefore separate it from other states of the parser to
avoid breaking it again when not taking enough care while
refactoring or adding features related to states.

Change-Id: If1eb0dd649225f10bfc3bf06f09851649da75983
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Stenger
2016-11-08 16:00:21 +01:00
parent b5f587efb5
commit f967545c5a
5 changed files with 18 additions and 22 deletions

View File

@@ -178,6 +178,7 @@ void AutotestPlugin::onRunSelectedTriggered()
void AutotestPlugin::updateMenuItemsEnabledState() void AutotestPlugin::updateMenuItemsEnabledState()
{ {
const bool enabled = !TestRunner::instance()->isTestRunning() const bool enabled = !TestRunner::instance()->isTestRunning()
&& TestTreeModel::instance()->parser()->enabled()
&& TestTreeModel::instance()->parser()->state() == TestCodeParser::Idle; && TestTreeModel::instance()->parser()->state() == TestCodeParser::Idle;
const bool hasTests = TestTreeModel::instance()->hasTests(); const bool hasTests = TestTreeModel::instance()->hasTests();

View File

@@ -81,7 +81,7 @@ TestCodeParser::~TestCodeParser()
void TestCodeParser::setState(State state) void TestCodeParser::setState(State state)
{ {
if (m_parserState == Shutdown) if (m_parserState == Shutdown || !m_enabled)
return; return;
qCDebug(LOG) << "setState(" << state << "), currentState:" << m_parserState; qCDebug(LOG) << "setState(" << state << "), currentState:" << m_parserState;
// avoid triggering parse before code model parsing has finished, but mark as dirty // avoid triggering parse before code model parsing has finished, but mark as dirty
@@ -91,17 +91,13 @@ void TestCodeParser::setState(State state)
return; return;
} }
if ((state == Disabled || state == Idle) if ((state == Idle) && (m_parserState == PartialParse || m_parserState == FullParse)) {
&& (m_parserState == PartialParse || m_parserState == FullParse)) {
qCDebug(LOG) << "Not setting state, parse is running"; qCDebug(LOG) << "Not setting state, parse is running";
return; return;
} }
m_parserState = state; m_parserState = state;
if (m_parserState == Disabled) { if (m_parserState == Idle && ProjectExplorer::SessionManager::startupProject()) {
m_fullUpdatePostponed = m_partialUpdatePostponed = false;
m_postponedFiles.clear();
} else if (m_parserState == Idle && ProjectExplorer::SessionManager::startupProject()) {
if (m_fullUpdatePostponed || m_dirty) { if (m_fullUpdatePostponed || m_dirty) {
emitUpdateTestTree(); emitUpdateTestTree();
} else if (m_partialUpdatePostponed) { } else if (m_partialUpdatePostponed) {
@@ -115,7 +111,7 @@ void TestCodeParser::setState(State state)
void TestCodeParser::syncTestFrameworks(const QVector<Core::Id> &frameworkIds) void TestCodeParser::syncTestFrameworks(const QVector<Core::Id> &frameworkIds)
{ {
if (m_parserState != Disabled && m_parserState != Idle) { if (m_enabled && m_parserState != Idle) {
// there's a running parse // there's a running parse
m_fullUpdatePostponed = m_partialUpdatePostponed = false; m_fullUpdatePostponed = m_partialUpdatePostponed = false;
m_postponedFiles.clear(); m_postponedFiles.clear();
@@ -129,7 +125,7 @@ void TestCodeParser::syncTestFrameworks(const QVector<Core::Id> &frameworkIds)
QTC_ASSERT(testParser, continue); QTC_ASSERT(testParser, continue);
m_testCodeParsers.append(testParser); m_testCodeParsers.append(testParser);
} }
if (m_parserState != Disabled) if (m_enabled)
updateTestTree(); updateTestTree();
} }
@@ -211,7 +207,7 @@ void TestCodeParser::onProjectPartsUpdated(ProjectExplorer::Project *project)
{ {
if (project != ProjectExplorer::SessionManager::startupProject()) if (project != ProjectExplorer::SessionManager::startupProject())
return; return;
if (m_codeModelParsing || m_parserState == Disabled) if (m_codeModelParsing || !m_enabled)
m_fullUpdatePostponed = true; m_fullUpdatePostponed = true;
else else
emitUpdateTestTree(); emitUpdateTestTree();
@@ -276,7 +272,6 @@ bool TestCodeParser::postponed(const QStringList &fileList)
m_partialUpdatePostponed = true; m_partialUpdatePostponed = true;
} }
return true; return true;
case Disabled:
case Shutdown: case Shutdown:
break; break;
} }
@@ -297,7 +292,9 @@ static void parseFileForTests(const QVector<ITestParser *> &parsers,
void TestCodeParser::scanForTests(const QStringList &fileList) void TestCodeParser::scanForTests(const QStringList &fileList)
{ {
if (m_parserState == Disabled || m_parserState == Shutdown) { if (m_parserState == Shutdown)
return;
if (!m_enabled) {
m_dirty = true; m_dirty = true;
if (fileList.isEmpty()) { if (fileList.isEmpty()) {
m_fullUpdatePostponed = true; m_fullUpdatePostponed = true;
@@ -419,11 +416,6 @@ void TestCodeParser::onFinished()
} }
m_dirty = false; m_dirty = false;
break; break;
case Disabled: // can happen if all Test related widgets become hidden while parsing
qCDebug(LOG) << "emitting parsingFinished (onFinished, Disabled)";
emit parsingFinished();
qCDebug(LOG) << QDateTime::currentDateTime().toString("hh:mm:ss.zzz") << "ParsingFin";
break;
case Shutdown: case Shutdown:
qCDebug(LOG) << "Shutdown complete - not emitting parsingFinished (onFinished)"; qCDebug(LOG) << "Shutdown complete - not emitting parsingFinished (onFinished)";
break; break;

View File

@@ -49,7 +49,6 @@ public:
Idle, Idle,
PartialParse, PartialParse,
FullParse, FullParse,
Disabled,
Shutdown Shutdown
}; };
@@ -57,6 +56,8 @@ public:
virtual ~TestCodeParser(); virtual ~TestCodeParser();
void setState(State state); void setState(State state);
State state() const { return m_parserState; } State state() const { return m_parserState; }
void setEnabled(bool enabled) { m_enabled = enabled; }
bool enabled() const { return m_enabled; }
bool isParsing() const { return m_parserState == PartialParse || m_parserState == FullParse; } bool isParsing() const { return m_parserState == PartialParse || m_parserState == FullParse; }
void setDirty() { m_dirty = true; } void setDirty() { m_dirty = true; }
void syncTestFrameworks(const QVector<Core::Id> &frameworkIds); void syncTestFrameworks(const QVector<Core::Id> &frameworkIds);
@@ -95,6 +96,7 @@ private:
TestTreeModel *m_model; TestTreeModel *m_model;
bool m_enabled = false;
bool m_codeModelParsing = false; bool m_codeModelParsing = false;
bool m_fullUpdatePostponed = false; bool m_fullUpdatePostponed = false;
bool m_partialUpdatePostponed = false; bool m_partialUpdatePostponed = false;
@@ -102,7 +104,7 @@ private:
bool m_singleShotScheduled = false; bool m_singleShotScheduled = false;
bool m_reparseTimerTimedOut = false; bool m_reparseTimerTimedOut = false;
QSet<QString> m_postponedFiles; QSet<QString> m_postponedFiles;
State m_parserState = Disabled; State m_parserState = Idle;
QFutureWatcher<TestParseResultPtr> m_futureWatcher; QFutureWatcher<TestParseResultPtr> m_futureWatcher;
QVector<ITestParser *> m_testCodeParsers; // ptrs are still owned by TestFrameworkManager QVector<ITestParser *> m_testCodeParsers; // ptrs are still owned by TestFrameworkManager
QTimer m_reparseTimer; QTimer m_reparseTimer;

View File

@@ -115,7 +115,7 @@ TestNavigationWidget::~TestNavigationWidget()
void TestNavigationWidget::contextMenuEvent(QContextMenuEvent *event) void TestNavigationWidget::contextMenuEvent(QContextMenuEvent *event)
{ {
const bool enabled = !TestRunner::instance()->isTestRunning() const bool enabled = !TestRunner::instance()->isTestRunning()
&& m_model->parser()->state() == TestCodeParser::Idle; && m_model->parser()->enabled() && m_model->parser()->state() == TestCodeParser::Idle;
const bool hasTests = m_model->hasTests(); const bool hasTests = m_model->hasTests();
QMenu menu; QMenu menu;

View File

@@ -90,6 +90,7 @@ void TestTreeModel::setupParsingConnections()
if (!m_connectionsInitialized) if (!m_connectionsInitialized)
m_parser->setDirty(); m_parser->setDirty();
m_parser->setEnabled(true);
m_parser->setState(TestCodeParser::Idle); m_parser->setState(TestCodeParser::Idle);
if (m_connectionsInitialized) if (m_connectionsInitialized)
return; return;
@@ -117,13 +118,13 @@ void TestTreeModel::setupParsingConnections()
void TestTreeModel::disableParsing() void TestTreeModel::disableParsing()
{ {
if (!m_refCounter.deref() && !AutotestPlugin::instance()->settings()->alwaysParse) if (!m_refCounter.deref() && !AutotestPlugin::instance()->settings()->alwaysParse)
m_parser->setState(TestCodeParser::Disabled); m_parser->setEnabled(false);
} }
void TestTreeModel::disableParsingFromSettings() void TestTreeModel::disableParsingFromSettings()
{ {
if (!m_refCounter.load()) if (!m_refCounter.load())
m_parser->setState(TestCodeParser::Disabled); m_parser->setEnabled(false);
} }
bool TestTreeModel::setData(const QModelIndex &index, const QVariant &value, int role) bool TestTreeModel::setData(const QModelIndex &index, const QVariant &value, int role)