diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2021-07-13 14:21:01 +0200 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2021-07-23 19:48:59 +0200 |
commit | 328f22561d1b8a798d94de95071a13165c3ba97b (patch) | |
tree | f5750d29d657e20fef549637ee7f51cdf2584475 | |
parent | ebae6e2041bcbe5b86fa13f779c952896e9c68d6 (diff) |
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 <alex1973tr@gmail.com>
-rw-r--r-- | tests/benchmarks/network/socket/qlocalsocket/tst_qlocalsocket.cpp | 27 |
1 files 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 <QTest> +#include <QtTest/qtesteventloop.h> + #include <QtCore/qglobal.h> #include <QtCore/qthread.h> #include <QtCore/qsemaphore.h> #include <QtCore/qbytearray.h> -#include <QtCore/qeventloop.h> #include <QtCore/qvector.h> #include <QtCore/qelapsedtimer.h> #include <QtNetwork/qlocalsocket.h> @@ -152,7 +153,7 @@ void tst_QLocalSocket::pingPong() QVERIFY(serverThread.running.tryAcquire(1, 3000)); SocketFactory factory(1, connections); - QEventLoop eventLoop; + QTestEventLoop eventLoop; QVector<qint64> 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(); } |