From 1ceee31ae0f552d128fa77be79c9be135f9c6972 Mon Sep 17 00:00:00 2001 From: Alex Trotsenko Date: Wed, 3 Aug 2016 20:20:54 +0300 Subject: Fix tst_QProcess::closeWriteChannel() under Windows Sometimes, this test fails in CI due to notifications arriving asynchronously from the OS. This happens inside closeWriteChannel() call, where we are flushing the write buffer and I/O completion on the read pipe could occur there as well. So, take this into account before waiting for the new incoming data. Also, improve the checks on successful reading and writing. Change-Id: Iabe875fc346eb4420c72d03208d22ea861a570c6 Reviewed-by: Edward Welbourne --- tests/auto/corelib/io/qprocess/tst_qprocess.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp index 7e1d5487ba..3c4bc79cde 100644 --- a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp +++ b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp @@ -764,6 +764,7 @@ void tst_QProcess::restartProcess() // Reading and writing to a process is not supported on Qt/CE void tst_QProcess::closeWriteChannel() { + QByteArray testData("Data to read"); QProcess more; more.start("testProcessEOF/testProcessEOF"); @@ -771,19 +772,21 @@ void tst_QProcess::closeWriteChannel() QVERIFY(!more.waitForReadyRead(250)); QCOMPARE(more.error(), QProcess::Timedout); - QVERIFY(more.write("Data to read") != -1); + QCOMPARE(more.write(testData), qint64(testData.size())); QVERIFY(!more.waitForReadyRead(250)); QCOMPARE(more.error(), QProcess::Timedout); more.closeWriteChannel(); - - QVERIFY(more.waitForReadyRead(5000)); - QVERIFY(more.readAll().startsWith("Data to read")); + // During closeWriteChannel() call, we might also get an I/O completion + // on the read pipe. So, take this into account before waiting for + // the new incoming data. + while (more.bytesAvailable() < testData.size()) + QVERIFY(more.waitForReadyRead(5000)); + QCOMPARE(more.readAll(), testData); if (more.state() == QProcess::Running) - more.write("q"); - QVERIFY(more.waitForFinished(5000)); + QVERIFY(more.waitForFinished(5000)); QCOMPARE(more.exitStatus(), QProcess::NormalExit); QCOMPARE(more.exitCode(), 0); } -- cgit v1.2.3