Add a test for a crash in ModelManagerInterface

Task-number: QTCREATORBUG-25350
Change-Id: I4ea31e7936cc77dcd8f3fc494b5ecbd83858a766
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Jarek Kobus
2021-04-30 16:52:03 +02:00
parent 7e874544e6
commit 5b0889777a
5 changed files with 36 additions and 3 deletions

View File

@@ -1393,6 +1393,12 @@ void PluginManagerPrivate::shutdown()
shutdownEventLoop->exec();
}
deleteAll();
#ifdef WITH_TESTS
if (PluginManager::isScenarioRunning("TestModelManagerInterface")) {
qDebug() << "Point 2: Expect the next call to Point 3 triggers a crash";
QThread::currentThread()->sleep(5);
}
#endif
if (!allObjects.isEmpty()) {
qDebug() << "There are" << allObjects.size() << "objects left in the plugin manager pool.";
// Intentionally split debug info here, since in case the list contains

View File

@@ -40,6 +40,10 @@
#include <utils/runextensions.h>
#include <utils/stringutils.h>
#ifdef WITH_TESTS
#include <extensionsystem/pluginmanager.h>
#endif
#include <QDir>
#include <QDirIterator>
#include <QFile>
@@ -969,6 +973,16 @@ void ModelManagerInterface::parseLoop(QSet<QString> &scannedPaths,
doc->setSource(contents);
doc->parse();
#ifdef WITH_TESTS
if (ExtensionSystem::PluginManager::isScenarioRunning("TestModelManagerInterface")) {
ExtensionSystem::PluginManager::waitForScenarioFullyInitialized();
if (ExtensionSystem::PluginManager::finishScenario()) {
qDebug() << "Point 1: Shutdown triggered";
QThread::currentThread()->sleep(2);
qDebug() << "Point 3: If Point 2 was already reached, expect a crash now";
}
}
#endif
// update snapshot. requires synchronization, but significantly reduces amount of file
// system queries for library imports because queries are cached in libraryInfo
const Snapshot snapshot = modelManager->snapshot();

View File

@@ -280,6 +280,8 @@ bool AutotestPlugin::initialize(const QStringList &arguments, QString *errorStri
#ifdef WITH_TESTS
ExtensionSystem::PluginManager::registerScenario("TestStringTable",
[this]() { return dd->m_loadProjectScenario(); });
ExtensionSystem::PluginManager::registerScenario("TestModelManagerInterface",
[this]() { return dd->m_loadProjectScenario(); });
#endif
return true;
}

View File

@@ -308,13 +308,23 @@ void AutoTestUnitTests::testCodeParserBoostTest_data()
<< QString(m_tmpDir->path() + "/simple_boost/simple_boost.qbs") << QString(".qbs");
}
void AutoTestUnitTests::testStringTable()
static int executeScenario(const QString &scenario)
{
const PluginManager::ProcessData data = PluginManager::creatorProcessData();
QStringList additionalArgs{ "-scenario", "TestStringTable" };
QStringList additionalArgs{ "-scenario", scenario };
if (!data.m_args.contains("-settingspath") && !data.m_settingsPath.isEmpty())
additionalArgs << "-settingspath" << data.m_settingsPath;
QCOMPARE(QProcess::execute(data.m_executable, data.m_args + additionalArgs), 0);
return QProcess::execute(data.m_executable, data.m_args + additionalArgs);
}
void AutoTestUnitTests::testStringTable()
{
QCOMPARE(executeScenario("TestStringTable"), 0);
}
void AutoTestUnitTests::testModelManagerInterface()
{
QCOMPARE(executeScenario("TestModelManagerInterface"), 0);
}
} // namespace Internal

View File

@@ -56,6 +56,7 @@ private slots:
void testCodeParserBoostTest();
void testCodeParserBoostTest_data();
void testStringTable();
void testModelManagerInterface();
private:
TestTreeModel *m_model = nullptr;