[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kpty] autotests: unbreak data waiting loops
From:       Oswald Buddenhagen <ossi () kde ! org>
Date:       2014-03-09 11:55:44
Message-ID: E1WMcKW-0004WH-VI () scm ! kde ! org
[Download RAW message or body]

Git commit 45ed3a2fbde9b483a2a9485d21511b7b9aec3cb4 by Oswald Buddenhagen.
Committed on 09/03/2014 at 11:39.
Pushed by ossi into branch 'master'.

unbreak data waiting loops

canReadLine() does not poll any handles, QThread::msleep() does not spin
the main loop, and readAll() reads only from buffers, so all that these
loops would have done is waiting an additional 2.5 seconds in case of
failure.

waitForReadyRead() waits for *more* data to arrive, so the right thing
is calling it in a loop until canReadLine() succeeds.
note that usually one should check that bytesAvailable() is not zero
before waiting for more data, but in this case we know that there was
no way the buffer could have filled up already.

M  +3    -6    autotests/kptyprocesstest.cpp

http://commits.kde.org/kpty/45ed3a2fbde9b483a2a9485d21511b7b9aec3cb4

diff --git a/autotests/kptyprocesstest.cpp b/autotests/kptyprocesstest.cpp
index ec23726..3e388ac 100644
--- a/autotests/kptyprocesstest.cpp
+++ b/autotests/kptyprocesstest.cpp
@@ -75,12 +75,11 @@ void KPtyProcessTest::test_shared_pty()
     p2.start();
 
     // read the second processes greeting from the first process' pty
-    QVERIFY(p.pty()->waitForReadyRead(1500));
     for (int i = 0; i < 5; ++i) {
+        QVERIFY(p.pty()->waitForReadyRead(500));
         if (p.pty()->canReadLine()) {
             break;
         }
-        QThread::msleep(500);
     }
     QCOMPARE(p.pty()->readAll(), QByteArray("hello from me\r\n"));
 
@@ -89,12 +88,11 @@ void KPtyProcessTest::test_shared_pty()
     QVERIFY(p2.pty()->waitForBytesWritten(1000));
 
     // read the result back from the first process' pty
-    QVERIFY(p.pty()->waitForReadyRead(1500));
     for (int i = 0; i < 5; ++i) {
+        QVERIFY(p.pty()->waitForReadyRead(500));
         if (p.pty()->canReadLine()) {
             break;
         }
-        QThread::msleep(500);
     }
     QCOMPARE(p.pty()->readAll(), QByteArray("hello from process 2\r\n"));
 
@@ -103,12 +101,11 @@ void KPtyProcessTest::test_shared_pty()
     QVERIFY(p.pty()->waitForBytesWritten(1000));
 
     // read the result back from the second process' pty
-    QVERIFY(p2.pty()->waitForReadyRead(1500));
     for (int i = 0; i < 5; ++i) {
+        QVERIFY(p2.pty()->waitForReadyRead(500));
         if (p2.pty()->canReadLine()) {
             break;
         }
-        QThread::msleep(500);
     }
     QCOMPARE(p2.pty()->readAll(), QByteArray("hi from process 1\r\n"));
 
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic