From 2a495c25961d73353339e165d4a4edbce91d7d2c Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Wed, 15 Feb 2023 13:08:30 +0200 Subject: QTestEventLoop: add enterLoop(std::chrono::milliseconds) overload Task-number: QTBUG-110059 Change-Id: Ibf1d76afd313e390103be4a22e44af7fb41ace1b Reviewed-by: Edward Welbourne Reviewed-by: Thiago Macieira --- .../access/qnetworkreply/tst_qnetworkreply.cpp | 22 ++++++++++++---------- .../socket/qlocalsocket/tst_qlocalsocket.cpp | 8 +++++--- 2 files changed, 17 insertions(+), 13 deletions(-) (limited to 'tests/benchmarks') diff --git a/tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp index 651bd90b0f..bb11a97f40 100644 --- a/tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp @@ -21,6 +21,8 @@ #include #endif +using namespace std::chrono_literals; + Q_DECLARE_METATYPE(QSharedPointer) class TimedSender: public QThread @@ -456,7 +458,7 @@ void tst_qnetworkreply::httpLatency() QNetworkRequest request(QUrl("http://" + QtNetworkSettings::serverName() + "/qtest/")); QNetworkReply* reply = manager.get(request); connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()), Qt::QueuedConnection); - QTestEventLoop::instance().enterLoop(5); + QTestEventLoop::instance().enterLoop(5s); QVERIFY(!QTestEventLoop::instance().timeout()); delete reply; } @@ -470,7 +472,7 @@ QPair tst_qnetworkreply::runGetRequest( QNetworkReply *reply = manager->get(request); connect(reply, SIGNAL(sslErrors(QList)), reply, SLOT(ignoreSslErrors())); connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()), Qt::QueuedConnection); - QTestEventLoop::instance().enterLoop(20); + QTestEventLoop::instance().enterLoop(20s); qint64 elapsed = timer.elapsed(); return qMakePair(reply, elapsed); } @@ -501,7 +503,7 @@ void tst_qnetworkreply::echoPerformance() QNetworkReply* reply = manager.post(request, data); connect(reply, SIGNAL(sslErrors(QList)), reply, SLOT(ignoreSslErrors())); connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()), Qt::QueuedConnection); - QTestEventLoop::instance().enterLoop(5); + QTestEventLoop::instance().enterLoop(5s); QVERIFY(!QTestEventLoop::instance().timeout()); QVERIFY(reply->error() == QNetworkReply::NoError); delete reply; @@ -510,7 +512,7 @@ void tst_qnetworkreply::echoPerformance() void tst_qnetworkreply::preConnectEncrypted() { - QFETCH(int, sleepTime); + QFETCH(std::chrono::milliseconds, sleepTime); QString hostName = QLatin1String("www.google.com"); QNetworkAccessManager manager; @@ -541,7 +543,7 @@ void tst_qnetworkreply::preConnectEncrypted() // now try to make the connection beforehand manager.connectToHostEncrypted(hostName); - QTestEventLoop::instance().enterLoopMSecs(sleepTime); + QTestEventLoop::instance().enterLoop(sleepTime); // now make another request and hopefully use the existing connection QPair preConnectResult = runGetRequest(&manager, request); @@ -559,12 +561,12 @@ void tst_qnetworkreply::preConnectEncrypted() void tst_qnetworkreply::preConnectEncrypted_data() { #ifndef QT_NO_OPENSSL - QTest::addColumn("sleepTime"); + QTest::addColumn("sleepTime"); // start a new normal request after preconnecting is done - QTest::newRow("HTTPS-2secs") << 2000; + QTest::newRow("HTTPS-2secs") << 2000ms; // start a new normal request while preconnecting is in-flight - QTest::newRow("HTTPS-100ms") << 100; + QTest::newRow("HTTPS-100ms") << 100ms; #endif // QT_NO_OPENSSL } @@ -915,9 +917,9 @@ void tst_qnetworkreply::preConnect() manager.clearAccessCache(); // now try to make the connection beforehand - QFETCH(int, sleepTime); + QFETCH(std::chrono::milliseconds, sleepTime); manager.connectToHost(hostName); - QTestEventLoop::instance().enterLoopMSecs(sleepTime); + QTestEventLoop::instance().enterLoop(sleepTime); // now make another request and hopefully use the existing connection QPair preConnectResult = runGetRequest(&manager, request); diff --git a/tests/benchmarks/network/socket/qlocalsocket/tst_qlocalsocket.cpp b/tests/benchmarks/network/socket/qlocalsocket/tst_qlocalsocket.cpp index dc88adb975..6c779b6188 100644 --- a/tests/benchmarks/network/socket/qlocalsocket/tst_qlocalsocket.cpp +++ b/tests/benchmarks/network/socket/qlocalsocket/tst_qlocalsocket.cpp @@ -14,6 +14,8 @@ #include #include +using namespace std::chrono_literals; + class tst_QLocalSocket : public QObject { Q_OBJECT @@ -175,7 +177,7 @@ void tst_QLocalSocket::dataExchange() QFETCH(int, chunkSize); Q_ASSERT(chunkSize > 0 && connections > 0); - const qint64 timeToTest = 5000; + const auto timeToTest = 5000ms; ServerThread serverThread(chunkSize); serverThread.start(); @@ -191,7 +193,7 @@ void tst_QLocalSocket::dataExchange() Q_UNUSED(channel); totalReceived += bytes; - if (timer.elapsed() >= timeToTest) { + if (timer.elapsed() >= timeToTest.count()) { factory.stopped = true; eventLoop.exitLoop(); } @@ -199,7 +201,7 @@ void tst_QLocalSocket::dataExchange() timer.start(); emit factory.start(); - eventLoop.enterLoopMSecs(timeToTest * 2); + eventLoop.enterLoop(timeToTest * 2); if (!QTest::currentTestFailed()) qDebug("Transfer rate: %.1f MB/s", totalReceived / 1048.576 / timer.elapsed()); -- cgit v1.2.3