diff --git a/src/libs/utils/launchersocket.cpp b/src/libs/utils/launchersocket.cpp index 28dfee23469..fc7b865e676 100644 --- a/src/libs/utils/launchersocket.cpp +++ b/src/libs/utils/launchersocket.cpp @@ -141,10 +141,8 @@ QList 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::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) { diff --git a/tests/auto/utils/qtcprocess/tst_qtcprocess.cpp b/tests/auto/utils/qtcprocess/tst_qtcprocess.cpp index 2ad9eba89d1..ac0bf2f862a 100644 --- a/tests/auto/utils/qtcprocess/tst_qtcprocess.cpp +++ b/tests/auto/utils/qtcprocess/tst_qtcprocess.cpp @@ -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"