QtcProcess: Add a test for crashing app

Ensure that when waitForFinished() didn't timeout
but the process has terminated, it returns true,
like QProcess does, in contrary to what QProcess'
documentation says.

Change-Id: I6af5034f4df7fc2e14a83bab74334a8abefe7a0f
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Jarek Kobus
2022-03-21 16:24:22 +01:00
parent 59cb70e61f
commit 5de5f1cf0a

View File

@@ -202,6 +202,7 @@ private slots:
void killBlockingProcess();
void flushFinishedWhileWaitingForReadyRead();
void emitOneErrorOnCrash();
void crashAfterOneSecond();
void cleanupTestCase();
@@ -221,6 +222,7 @@ private:
SUB_CREATOR_PROCESS(SubProcessChannelForwarding);
SUB_CREATOR_PROCESS(KillBlockingProcess);
SUB_CREATOR_PROCESS(EmitOneErrorOnCrash);
SUB_CREATOR_PROCESS(CrashAfterOneSecond);
// In order to get a value associated with the certain subprocess use SubProcessClass::envVar().
// The classes above define different custom executables. Inside initTestCase()
@@ -1339,6 +1341,28 @@ void tst_QtcProcess::emitOneErrorOnCrash()
QCOMPARE(errorCount, 1);
}
void tst_QtcProcess::CrashAfterOneSecond::main()
{
QThread::sleep(1);
abort();
}
void tst_QtcProcess::crashAfterOneSecond()
{
SubCreatorConfig subConfig(CrashAfterOneSecond::envVar(), {});
TestProcess process;
subConfig.setupSubProcess(&process);
process.start();
QVERIFY(process.waitForStarted(1000));
QElapsedTimer timer;
timer.start();
// Please note that QProcess documentation says it should return false, but apparently
// it doesn't (try running this test with QTC_USE_QPROCESS=)
QVERIFY(process.waitForFinished(2000));
QVERIFY(timer.elapsed() < 2000);
}
QTEST_MAIN(tst_QtcProcess)
#include "tst_qtcprocess.moc"