Ensure we never encounter the message about destroying QProcess

Until we remove the process launcher / process reaper.

Change-Id: I9c68c40c3c856c0a515277b69fc3084ba2addbee
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Jarek Kobus
2022-03-21 18:02:53 +01:00
parent 1b5c4504af
commit 127ca236a7

View File

@@ -49,6 +49,43 @@
using namespace Utils; using namespace Utils;
// This handler is inspired by the one used in qtbase/tests/auto/corelib/io/qfile/tst_qfile.cpp
class MessageHandler {
public:
MessageHandler(QtMessageHandler messageHandler = handler)
{
s_oldMessageHandler = qInstallMessageHandler(messageHandler);
}
~MessageHandler()
{
qInstallMessageHandler(s_oldMessageHandler);
}
static int destroyCount()
{
return s_destroyCount;
}
protected:
static void handler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
if (msg.contains("QProcess: Destroyed while process")
&& msg.contains("is still running.")) {
++s_destroyCount;
}
// Defer to old message handler.
if (s_oldMessageHandler)
s_oldMessageHandler(type, context, msg);
}
static QtMessageHandler s_oldMessageHandler;
static int s_destroyCount;
};
int MessageHandler::s_destroyCount = 0;
QtMessageHandler MessageHandler::s_oldMessageHandler = 0;
using SubProcessMain = std::function<void ()>; using SubProcessMain = std::function<void ()>;
static QMap<const char *, SubProcessMain> s_subProcesses = {}; static QMap<const char *, SubProcessMain> s_subProcesses = {};
@@ -246,6 +283,8 @@ private:
MacroMapExpander mxUnix; MacroMapExpander mxUnix;
QString homeStr; QString homeStr;
QString home; QString home;
MessageHandler *msgHandler = nullptr;
}; };
void tst_QtcProcess::SimpleTest::main() void tst_QtcProcess::SimpleTest::main()
@@ -256,6 +295,7 @@ void tst_QtcProcess::SimpleTest::main()
void tst_QtcProcess::initTestCase() void tst_QtcProcess::initTestCase()
{ {
msgHandler = new MessageHandler;
Utils::TemporaryDirectory::setMasterTemporaryDirectory(QDir::tempPath() + "/" Utils::TemporaryDirectory::setMasterTemporaryDirectory(QDir::tempPath() + "/"
+ Core::Constants::IDE_CASED_ID + "-XXXXXX"); + Core::Constants::IDE_CASED_ID + "-XXXXXX");
Utils::LauncherInterface::setPathToLauncher(qApp->applicationDirPath() + '/' Utils::LauncherInterface::setPathToLauncher(qApp->applicationDirPath() + '/'
@@ -307,6 +347,11 @@ void tst_QtcProcess::initTestCase()
void tst_QtcProcess::cleanupTestCase() void tst_QtcProcess::cleanupTestCase()
{ {
Utils::Singleton::deleteAll(); Utils::Singleton::deleteAll();
const int destroyCount = msgHandler->destroyCount();
delete msgHandler;
if (destroyCount)
qDebug() << "Received" << destroyCount << "messages about destroying running QProcess!";
QCOMPARE(destroyCount, 0);
} }
Q_DECLARE_METATYPE(ProcessArgs::SplitError) Q_DECLARE_METATYPE(ProcessArgs::SplitError)
@@ -1195,44 +1240,6 @@ void tst_QtcProcess::processChannelForwarding()
QCOMPARE(error.contains(QByteArray(forwardedErrorData)), errorForwarded); QCOMPARE(error.contains(QByteArray(forwardedErrorData)), errorForwarded);
} }
// This handler is inspired by the one used in qtbase/tests/auto/corelib/io/qfile/tst_qfile.cpp
class MessageHandler {
public:
MessageHandler(QtMessageHandler messageHandler = handler)
{
ok = true;
oldMessageHandler = qInstallMessageHandler(messageHandler);
}
~MessageHandler()
{
qInstallMessageHandler(oldMessageHandler);
}
static bool testPassed()
{
return ok;
}
protected:
static void handler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
if (msg.startsWith("QProcess: Destroyed while process")
&& msg.endsWith("is still running.")) {
ok = false;
}
// Defer to old message handler.
if (oldMessageHandler)
oldMessageHandler(type, context, msg);
}
static QtMessageHandler oldMessageHandler;
static bool ok;
};
bool MessageHandler::ok = true;
QtMessageHandler MessageHandler::oldMessageHandler = 0;
enum class BlockType { enum class BlockType {
EndlessLoop, EndlessLoop,
InfiniteSleep, InfiniteSleep,
@@ -1286,16 +1293,11 @@ void tst_QtcProcess::killBlockingProcess()
SubCreatorConfig subConfig(KillBlockingProcess::envVar(), QString::number(int(blockType))); SubCreatorConfig subConfig(KillBlockingProcess::envVar(), QString::number(int(blockType)));
MessageHandler msgHandler; TestProcess process;
{ subConfig.setupSubProcess(&process);
TestProcess process; process.start();
subConfig.setupSubProcess(&process); QVERIFY(process.waitForStarted());
process.start(); QVERIFY(!process.waitForFinished(1000));
QVERIFY(process.waitForStarted());
QVERIFY(!process.waitForFinished(1000));
}
QVERIFY(msgHandler.testPassed());
} }
void tst_QtcProcess::flushFinishedWhileWaitingForReadyRead() void tst_QtcProcess::flushFinishedWhileWaitingForReadyRead()