From 328f22561d1b8a798d94de95071a13165c3ba97b Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Tue, 13 Jul 2021 14:21:01 +0200 Subject: Convert QLocalSocket benchmark to use QTestEventLoop Now that this event loop pays attention to test failures, we can avoid the time-outs that used to happen on test failure. Also check for premature failures (but don't return early, so we can shut down the server gracefully) and give the event-loops sensible time-outs. Task-number: QTBUG-91713 Change-Id: Ib895a5fba0f22654c7fecf996f23649a4b5ce0de Reviewed-by: Alex Trotsenko --- .../socket/qlocalsocket/tst_qlocalsocket.cpp | 27 ++++++++++++++-------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/tests/benchmarks/network/socket/qlocalsocket/tst_qlocalsocket.cpp b/tests/benchmarks/network/socket/qlocalsocket/tst_qlocalsocket.cpp index d7b39ed566..7130895f51 100644 --- a/tests/benchmarks/network/socket/qlocalsocket/tst_qlocalsocket.cpp +++ b/tests/benchmarks/network/socket/qlocalsocket/tst_qlocalsocket.cpp @@ -28,11 +28,12 @@ ****************************************************************************/ #include +#include + #include #include #include #include -#include #include #include #include @@ -152,7 +153,7 @@ void tst_QLocalSocket::pingPong() QVERIFY(serverThread.running.tryAcquire(1, 3000)); SocketFactory factory(1, connections); - QEventLoop eventLoop; + QTestEventLoop eventLoop; QVector bytesToRead; QElapsedTimer timer; @@ -163,15 +164,20 @@ void tst_QLocalSocket::pingPong() if (--bytesToRead[channel] == 0 && --connections == 0) { factory.stopped = true; - eventLoop.quit(); + eventLoop.exitLoop(); } }); timer.start(); emit factory.start(); - eventLoop.exec(); - - qDebug("Elapsed time: %.1f s", timer.elapsed() / 1000.0); + // QtTestLib's Watchdog defaults to 300 seconds; we want to give up before + // it bites. + eventLoop.enterLoop(290); + + if (eventLoop.timeout()) + qDebug("Timed out after %.1f s", timer.elapsed() / 1000.0); + else if (!QTest::currentTestFailed()) + qDebug("Elapsed time: %.1f s", timer.elapsed() / 1000.0); serverThread.quit(); serverThread.wait(); } @@ -202,7 +208,7 @@ void tst_QLocalSocket::dataExchange() QVERIFY(serverThread.running.tryAcquire(1, 3000)); SocketFactory factory(chunkSize, connections); - QEventLoop eventLoop; + QTestEventLoop eventLoop; qint64 totalReceived = 0; QElapsedTimer timer; @@ -213,15 +219,16 @@ void tst_QLocalSocket::dataExchange() totalReceived += bytes; if (timer.elapsed() >= timeToTest) { factory.stopped = true; - eventLoop.quit(); + eventLoop.exitLoop(); } }); timer.start(); emit factory.start(); - eventLoop.exec(); + eventLoop.enterLoopMSecs(timeToTest * 2); - qDebug("Transfer rate: %.1f MB/s", totalReceived / 1048.576 / timer.elapsed()); + if (!QTest::currentTestFailed()) + qDebug("Transfer rate: %.1f MB/s", totalReceived / 1048.576 / timer.elapsed()); serverThread.quit(); serverThread.wait(); } -- cgit v1.2.3