Flush finished() signal when waitForReadyRead() was called

Apparently the QProcess behaves like that.

Change-Id: Idb1993b8abccbd7943582d41bd456eacc9a1c185
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
Jarek Kobus
2021-11-04 10:27:08 +01:00
parent 4d55fc911d
commit acfe224281
2 changed files with 36 additions and 5 deletions

View File

@@ -141,10 +141,8 @@ QList<CallerHandle::SignalType> CallerHandle::flushFor(CallerHandle::SignalType
{
// 1. If signalType is no signal - flush all
// 2. Flush all if we have any error
// 3. If we are flushing for Finished, flush Started / ReadyRead, too
// 4. If we are flushing for ReadyRead, flush Started, too
// 5. (?) If we have collected Finished, flush it only when flushing
// for ReadyRead / Finished (not for Started)
// 3. If we are flushing for Finished or ReadyRead, flush all, too
// 4. If we are flushing for Started, flush Started only
QMutexLocker locker(&m_mutex);
@@ -154,6 +152,7 @@ QList<CallerHandle::SignalType> CallerHandle::flushFor(CallerHandle::SignalType
});
const bool flushAll = (signalType == CallerHandle::SignalType::NoSignal)
|| (signalType == CallerHandle::SignalType::ReadyRead)
|| (signalType == CallerHandle::SignalType::Finished)
|| storedSignals.contains(CallerHandle::SignalType::Error);
if (flushAll) {

View File

@@ -65,6 +65,7 @@ const char kBlockingProcess[] = "QTC_TST_BLOCKING_PROCESS";
// the recursion, as from the test point of view we meant to execute only our custom code
// without further execution of the test itself.
const char testProcessData[] = "Test process successfully executed.";
const char forwardedOutputData[] = "This is the output message.";
const char forwardedErrorData[] = "This is the error message.";
const char runBlockingStdOutSubProcessMagicWord[] = "42";
@@ -108,7 +109,7 @@ static void lineCallbackMain()
static void testProcessSubProcessMain()
{
std::cout << "Test process successfully executed." << std::endl;
std::cout << testProcessData << std::endl;
exit(0);
}
@@ -207,6 +208,7 @@ private slots:
void processChannelForwarding_data();
void processChannelForwarding();
void killBlockingProcess();
void flushFinishedWhileWaitingForReadyRead();
void cleanupTestCase();
@@ -1175,6 +1177,36 @@ void tst_QtcProcess::killBlockingProcess()
QVERIFY(msgHandler.testPassed());
}
void tst_QtcProcess::flushFinishedWhileWaitingForReadyRead()
{
Environment env = Environment::systemEnvironment();
env.set(kTestProcess, {});
QStringList args = QCoreApplication::arguments();
const QString binary = args.takeFirst();
const CommandLine command(FilePath::fromString(binary), args);
QtcProcess process;
process.setCommand(command);
process.setEnvironment(env);
process.start();
QVERIFY(process.waitForStarted());
QCOMPARE(process.state(), QProcess::Running);
QDeadlineTimer timer(1000);
QByteArray reply;
while (process.state() == QProcess::Running) {
process.waitForReadyRead(500);
reply += process.readAllStandardOutput();
if (timer.hasExpired())
break;
}
QCOMPARE(process.state(), QProcess::NotRunning);
QVERIFY(!timer.hasExpired());
QVERIFY(reply.contains(testProcessData));
}
QTEST_MAIN(tst_QtcProcess)
#include "tst_qtcprocess.moc"