QTestEventLoop: add enterLoop(std::chrono::milliseconds) overload

Task-number: QTBUG-110059
Change-Id: Ibf1d76afd313e390103be4a22e44af7fb41ace1b
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Ahmad Samir 2023-02-15 13:08:30 +02:00
parent 855a6cb676
commit 2a495c2596
11 changed files with 87 additions and 67 deletions

View File

@ -99,7 +99,7 @@ public:
Q_ASSERT(!m_waiting);
const qsizetype origCount = size();
m_waiting = true;
m_loop.enterLoopMSecs(timeout);
m_loop.enterLoop(std::chrono::milliseconds{timeout});
m_waiting = false;
return size() > origCount;
}

View File

@ -25,8 +25,9 @@ public:
: QObject(parent), _timeout(false)
{}
inline void enterLoopMSecs(int ms);
inline void enterLoop(int secs) { enterLoopMSecs(secs * 1000); }
void enterLoopMSecs(int ms) { enterLoop(std::chrono::milliseconds{ms}); };
void enterLoop(int secs) { enterLoop(std::chrono::seconds{secs}); }
inline void enterLoop(std::chrono::milliseconds msecs);
inline void changeInterval(int secs)
{ killTimer(timerId); timerId = startTimer(secs * 1000); }
@ -55,7 +56,7 @@ private:
Q_DECL_UNUSED_MEMBER uint reserved :31;
};
inline void QTestEventLoop::enterLoopMSecs(int ms)
inline void QTestEventLoop::enterLoop(std::chrono::milliseconds msecs)
{
Q_ASSERT(!loop);
_timeout = false;
@ -63,9 +64,10 @@ inline void QTestEventLoop::enterLoopMSecs(int ms)
if (QTest::runningTest() && QTest::currentTestResolved())
return;
using namespace std::chrono_literals;
QEventLoop l;
// if tests want to measure sub-second precision, use a precise timer
timerId = startTimer(ms, ms < 1000 ? Qt::PreciseTimer : Qt::CoarseTimer);
timerId = startTimer(msecs, msecs < 1s ? Qt::PreciseTimer : Qt::CoarseTimer);
loop = &l;
l.exec();

View File

@ -24,6 +24,7 @@
# undef min
#endif // Q_CC_MSVC
using namespace std::chrono_literals;
class tst_QSocketNotifier : public QObject
{
@ -374,7 +375,7 @@ void tst_QSocketNotifier::asyncMultipleDatagram()
&tst_QSocketNotifier::async_readDatagramSlot);
// activate socket notifiers
QTestEventLoop::instance().enterLoopMSecs(100);
QTestEventLoop::instance().enterLoop(100ms);
m_asyncSender->writeDatagram("1", makeNonAny(m_asyncReceiver->localAddress()), port);
m_asyncSender->writeDatagram("2", makeNonAny(m_asyncReceiver->localAddress()), port);

View File

@ -30,6 +30,9 @@
# undef interface
#endif
using namespace std::chrono_literals;
static constexpr auto DefaultWaitTime = 2s;
using namespace Qt::StringLiterals;
class SenderObject : public QObject
@ -3487,7 +3490,7 @@ void tst_QFuture::runAndTake()
auto gotcha = QtConcurrent::run(rabbit);
watcha.setFuture(gotcha);
loop.enterLoopMSecs(500);
loop.enterLoop(500ms);
if (loop.timeout())
QSKIP("Failed to run the task, nothing to test");
@ -3558,7 +3561,7 @@ void tst_QFuture::resultsReadyAt()
// Run event loop, QCoreApplication::postEvent is in use
// in QFutureInterface:
eventProcessor.enterLoopMSecs(2000);
eventProcessor.enterLoop(DefaultWaitTime);
QVERIFY(!eventProcessor.timeout());
if (QTest::currentTestFailed()) // Failed in our lambda observing 'ready at'
return;
@ -3933,7 +3936,7 @@ void tst_QFuture::rejectResultOverwrite()
});
// Run event loop, QCoreApplication::postEvent is in use
// in QFutureInterface:
eventProcessor.enterLoopMSecs(2000);
eventProcessor.enterLoop(DefaultWaitTime);
QVERIFY(!eventProcessor.timeout());
QCOMPARE(resultCounter.size(), 1);
f.resume();
@ -3972,7 +3975,7 @@ void tst_QFuture::rejectResultOverwrite()
QTimer::singleShot(50, [&f]() {
f.suspend(); // should exit the loop
});
eventProcessor.enterLoopMSecs(2000);
eventProcessor.enterLoop(DefaultWaitTime);
QVERIFY(!eventProcessor.timeout());
QCOMPARE(resultCounter.size(), 1);
f.resume();
@ -4011,7 +4014,7 @@ void tst_QFuture::rejectPendingResultOverwrite()
});
// Run event loop, QCoreApplication::postEvent is in use
// in QFutureInterface:
eventProcessor.enterLoopMSecs(2000);
eventProcessor.enterLoop(DefaultWaitTime);
QVERIFY(!eventProcessor.timeout());
QCOMPARE(resultCounter.size(), 1);
f.resume();
@ -4055,7 +4058,7 @@ void tst_QFuture::rejectPendingResultOverwrite()
QTimer::singleShot(50, [&f]() {
f.suspend(); // should exit the loop
});
eventProcessor.enterLoopMSecs(2000);
eventProcessor.enterLoop(DefaultWaitTime);
QVERIFY(!eventProcessor.timeout());
QCOMPARE(resultCounter.size(), 1);
f.resume();

View File

@ -26,6 +26,8 @@
#include <algorithm>
using namespace std::chrono_literals;
QT_BEGIN_NAMESPACE
namespace
@ -127,8 +129,8 @@ private:
DtlsPtr clientCrypto;
QTestEventLoop testLoop;
const int handshakeTimeoutMS = 5000;
const int dataExchangeTimeoutMS = 1000;
static constexpr auto HandshakeTimeout = 5s;
static constexpr auto DataExchangeTimeout = 1s;
const QByteArray presharedKey = "DEADBEEFDEADBEEF";
QString certDirPath;
@ -413,7 +415,7 @@ void tst_QDtls::handshake()
QDTLS_VERIFY_NO_ERROR(clientCrypto);
QCOMPARE(clientCrypto->handshakeState(), QDtls::HandshakeInProgress);
testLoop.enterLoopMSecs(handshakeTimeoutMS);
testLoop.enterLoop(HandshakeTimeout);
QVERIFY(!testLoop.timeout());
@ -473,7 +475,7 @@ void tst_QDtls::handshakeWithRetransmission()
// client will re-transmit in 1s., the first part of 'ServerHello' to be
// dropped, the client then will re-transmit after another 2 s. Thus it's ~3.
// We err on safe side and double our (already quite generous) 5s.
testLoop.enterLoopMSecs(handshakeTimeoutMS * 2);
testLoop.enterLoop(HandshakeTimeout * 2);
QVERIFY(!testLoop.timeout());
QDTLS_VERIFY_HANDSHAKE_SUCCESS(serverCrypto);
@ -496,7 +498,7 @@ void tst_QDtls::sessionCipher()
QVERIFY(clientCrypto->setPeer(serverAddress, serverPort, hostName));
QVERIFY(clientCrypto->doHandshake(&clientSocket));
testLoop.enterLoopMSecs(handshakeTimeoutMS);
testLoop.enterLoop(HandshakeTimeout);
QVERIFY(!testLoop.timeout());
QDTLS_VERIFY_HANDSHAKE_SUCCESS(clientCrypto);
@ -559,7 +561,7 @@ void tst_QDtls::cipherPreferences()
QVERIFY(clientCrypto->doHandshake(&clientSocket));
QDTLS_VERIFY_NO_ERROR(clientCrypto);
testLoop.enterLoopMSecs(handshakeTimeoutMS);
testLoop.enterLoop(HandshakeTimeout);
QVERIFY(!testLoop.timeout());
QDTLS_VERIFY_HANDSHAKE_SUCCESS(clientCrypto);
QDTLS_VERIFY_HANDSHAKE_SUCCESS(serverCrypto);
@ -626,7 +628,7 @@ void tst_QDtls::protocolVersionMatching()
QVERIFY(clientCrypto->setPeer(serverAddress, serverPort));
QVERIFY(clientCrypto->doHandshake(&clientSocket));
testLoop.enterLoopMSecs(handshakeTimeoutMS);
testLoop.enterLoop(HandshakeTimeout);
if (works) {
QDTLS_VERIFY_HANDSHAKE_SUCCESS(serverCrypto);
@ -661,7 +663,7 @@ void tst_QDtls::verificationErrors()
// Now we are ready for handshake:
QVERIFY(clientCrypto->doHandshake(&clientSocket));
testLoop.enterLoopMSecs(handshakeTimeoutMS);
testLoop.enterLoop(HandshakeTimeout);
QVERIFY(!testLoop.timeout());
QDTLS_VERIFY_NO_ERROR(serverCrypto);
@ -731,7 +733,7 @@ void tst_QDtls::presetExpectedErrors()
QVERIFY(clientCrypto->setPeer(serverAddress, serverPort));
QVERIFY(clientCrypto->doHandshake(&clientSocket));
testLoop.enterLoopMSecs(handshakeTimeoutMS);
testLoop.enterLoop(HandshakeTimeout);
QVERIFY(!testLoop.timeout());
@ -818,7 +820,7 @@ void tst_QDtls::verifyServerCertificate()
QVERIFY(clientCrypto->doHandshake(&clientSocket));
testLoop.enterLoopMSecs(handshakeTimeoutMS);
testLoop.enterLoop(HandshakeTimeout);
QVERIFY(!testLoop.timeout());
if (serverKey.isNull() && !serverCerts.isEmpty()) {
@ -948,7 +950,7 @@ void tst_QDtls::verifyClientCertificate()
QVERIFY(clientCrypto->doHandshake(&clientSocket));
QDTLS_VERIFY_NO_ERROR(clientCrypto);
testLoop.enterLoopMSecs(handshakeTimeoutMS);
testLoop.enterLoop(HandshakeTimeout);
serverConfig = serverCrypto->dtlsConfiguration();
@ -995,7 +997,7 @@ void tst_QDtls::blacklistedCerificate()
QVERIFY(clientCrypto->setPeer(serverAddress, serverPort, name));
QVERIFY(clientCrypto->doHandshake(&clientSocket));
testLoop.enterLoopMSecs(handshakeTimeoutMS);
testLoop.enterLoop(HandshakeTimeout);
QVERIFY(!testLoop.timeout());
QCOMPARE(clientCrypto->handshakeState(), QDtls::PeerVerificationFailed);
QCOMPARE(clientCrypto->dtlsError(), QDtlsError::PeerVerificationError);
@ -1047,7 +1049,7 @@ void tst_QDtls::readWriteEncrypted()
QCOMPARE(clientCrypto->dtlsError(), QDtlsError::InvalidOperation);
// 1.2 Finish the handshake:
testLoop.enterLoopMSecs(handshakeTimeoutMS);
testLoop.enterLoop(HandshakeTimeout);
QVERIFY(!testLoop.timeout());
QDTLS_VERIFY_HANDSHAKE_SUCCESS(clientCrypto);
@ -1065,7 +1067,7 @@ void tst_QDtls::readWriteEncrypted()
QVERIFY(clientBytesWritten > 0);
// 5. Exchange client/server messages:
testLoop.enterLoopMSecs(dataExchangeTimeoutMS);
testLoop.enterLoop(DataExchangeTimeout);
QVERIFY(!testLoop.timeout());
QCOMPARE(serverExpectedPlainText, serverReceivedPlainText);
@ -1083,7 +1085,7 @@ void tst_QDtls::readWriteEncrypted()
QCOMPARE(crypto->handshakeState(), QDtls::HandshakeNotStarted);
QVERIFY(!crypto->isConnectionEncrypted());
// 8. Receive this read notification and handle it:
testLoop.enterLoopMSecs(dataExchangeTimeoutMS);
testLoop.enterLoop(DataExchangeTimeout);
QVERIFY(!testLoop.timeout());
DtlsPtr &peerCrypto = serverSideShutdown ? clientCrypto : serverCrypto;
@ -1108,7 +1110,7 @@ void tst_QDtls::datagramFragmentation()
QVERIFY(clientCrypto->doHandshake(&clientSocket));
testLoop.enterLoopMSecs(handshakeTimeoutMS);
testLoop.enterLoop(HandshakeTimeout);
QVERIFY(!testLoop.timeout());
QDTLS_VERIFY_HANDSHAKE_SUCCESS(clientCrypto);

View File

@ -22,6 +22,8 @@
#include <utility>
#include <vector>
using namespace std::chrono_literals;
QT_BEGIN_NAMESPACE
#define STOP_ON_FAILURE \
@ -76,7 +78,7 @@ private:
quint16 serverPort = 0;
QTestEventLoop testLoop;
int handshakeTimeoutMS = 500;
static constexpr auto HandshakeTimeout = 500ms;
QDtlsClientVerifier listener;
using HandshakePtr = QSharedPointer<QDtls>;
@ -327,7 +329,7 @@ void tst_QDtlsCookie::verifyMultipleClients()
clientsToAdd = clientsToWait = 100;
testLoop.enterLoopMSecs(handshakeTimeoutMS * clientsToWait);
testLoop.enterLoop(HandshakeTimeout * clientsToWait);
QVERIFY(!testLoop.timeout());
QVERIFY(clientsToWait == 0);
}
@ -351,7 +353,7 @@ void tst_QDtlsCookie::receiveMessage(QUdpSocket *socket, QByteArray *message,
Q_ASSERT(socket && message);
if (socket->pendingDatagramSize() <= 0)
testLoop.enterLoopMSecs(handshakeTimeoutMS);
testLoop.enterLoop(HandshakeTimeout);
QVERIFY(!testLoop.timeout());
QVERIFY(socket->pendingDatagramSize());

View File

@ -28,6 +28,8 @@
#include <algorithm>
#include <utility>
using namespace std::chrono_literals;
// NOTE: the word 'subject' in the code below means the subject of a status request,
// so in general it's our peer's certificate we are asking about.
@ -386,7 +388,7 @@ private:
void (QSslSocket::*tlsErrorsSignal)(const QList<QSslError> &) = &QSslSocket::sslErrors;
void (QTestEventLoop::*exitLoopSlot)() = &QTestEventLoop::exitLoop;
const int handshakeTimeoutMS = 500;
static constexpr auto HandshakeTimeout = 500ms;
QTestEventLoop loop;
std::vector<QSslError::SslError> ocspErrorCodes = {QSslError::OcspNoResponseFound,
@ -462,7 +464,7 @@ void tst_QOcsp::connectSelfSigned()
auto roots = clientConfig.caCertificates();
setupOcspClient(clientSocket, issuerToChain(subjectChain), server.peerVerifyName());
clientSocket.connectToHostEncrypted(server.hostName(), server.serverPort());
loop.enterLoopMSecs(handshakeTimeoutMS);
loop.enterLoop(HandshakeTimeout);
QVERIFY(!clientSocket.isEncrypted());
QCOMPARE_SINGLE_ERROR(clientSocket, expectedError);
@ -478,7 +480,7 @@ void tst_QOcsp::connectSelfSigned()
QSslSocket clientSocket;
setupOcspClient(clientSocket, issuerToChain(subjectChain), server.peerVerifyName());
clientSocket.connectToHostEncrypted(server.hostName(), server.serverPort());
loop.enterLoopMSecs(handshakeTimeoutMS);
loop.enterLoop(HandshakeTimeout);
QVERIFY_HANDSHAKE_WITHOUT_ERRORS(clientSocket);
@ -543,7 +545,7 @@ void tst_QOcsp::badStatus()
QSslSocket clientSocket;
setupOcspClient(clientSocket, issuerToChain(subjectChain), server.peerVerifyName());
clientSocket.connectToHostEncrypted(server.hostName(), server.serverPort());
loop.enterLoopMSecs(handshakeTimeoutMS);
loop.enterLoop(HandshakeTimeout);
QVERIFY(!clientSocket.isEncrypted());
QCOMPARE_SINGLE_ERROR(clientSocket, expectedError.error());
@ -574,7 +576,7 @@ void tst_QOcsp::multipleSingleResponses()
QSslSocket clientSocket;
setupOcspClient(clientSocket, issuerToChain(responderChain), server.peerVerifyName());
clientSocket.connectToHostEncrypted(server.hostName(), server.serverPort());
loop.enterLoopMSecs(handshakeTimeoutMS);
loop.enterLoop(HandshakeTimeout);
QVERIFY(!clientSocket.isEncrypted());
QCOMPARE_SINGLE_ERROR(clientSocket, expectedError);
@ -594,7 +596,7 @@ void tst_QOcsp::malformedResponse()
QSslSocket clientSocket;
setupOcspClient(clientSocket, issuerToChain(serverChain), server.peerVerifyName());
clientSocket.connectToHostEncrypted(server.hostName(), server.serverPort());
loop.enterLoopMSecs(handshakeTimeoutMS);
loop.enterLoop(HandshakeTimeout);
QVERIFY(!clientSocket.isEncrypted());
QCOMPARE(clientSocket.error(), QAbstractSocket::SslHandshakeFailedError);
@ -633,7 +635,7 @@ void tst_QOcsp::expiredResponse()
QSslSocket clientSocket;
setupOcspClient(clientSocket, issuerToChain(subjectChain), server.peerVerifyName());
clientSocket.connectToHostEncrypted(server.hostName(), server.serverPort());
loop.enterLoopMSecs(handshakeTimeoutMS);
loop.enterLoop(HandshakeTimeout);
QVERIFY(!clientSocket.isEncrypted());
QCOMPARE_SINGLE_ERROR(clientSocket, expectedError);
@ -664,7 +666,7 @@ void tst_QOcsp::noNextUpdate()
QSslSocket clientSocket;
setupOcspClient(clientSocket, issuerToChain(subjectChain), server.peerVerifyName());
clientSocket.connectToHostEncrypted(server.hostName(), server.serverPort());
loop.enterLoopMSecs(handshakeTimeoutMS);
loop.enterLoop(HandshakeTimeout);
QVERIFY_HANDSHAKE_WITHOUT_ERRORS(clientSocket);
}
@ -710,7 +712,7 @@ void tst_QOcsp::wrongCertificateInResponse()
QSslSocket clientSocket;
setupOcspClient(clientSocket, issuerToChain(subjectChain), server.peerVerifyName());
clientSocket.connectToHostEncrypted(server.hostName(), server.serverPort());
loop.enterLoopMSecs(handshakeTimeoutMS);
loop.enterLoop(HandshakeTimeout);
QVERIFY(!clientSocket.isEncrypted());
QVERIFY(containsError(clientSocket.sslHandshakeErrors(), expectedError));
@ -735,7 +737,7 @@ void tst_QOcsp::untrustedResponder()
QSslSocket clientSocket;
setupOcspClient(clientSocket, {}, server.peerVerifyName());
clientSocket.connectToHostEncrypted(server.hostName(), server.serverPort());
loop.enterLoopMSecs(handshakeTimeoutMS);
loop.enterLoop(HandshakeTimeout);
QVERIFY(!clientSocket.isEncrypted());
QVERIFY(containsError(clientSocket.sslHandshakeErrors(), expectedError));

View File

@ -44,6 +44,8 @@
#include "private/qsslsocket_p.h"
#include "private/qsslconfiguration_p.h"
using namespace std::chrono_literals;
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
// make these enum values available without causing deprecation warnings:
@ -2824,7 +2826,7 @@ void tst_QSslSocket::closeWhileEmittingSocketError()
// Make sure we have some data buffered so that close will try to flush:
clientSocket.write(QByteArray(1000000, Qt::Uninitialized));
QTestEventLoop::instance().enterLoopMSecs(1000);
QTestEventLoop::instance().enterLoop(1s);
QVERIFY(!QTestEventLoop::instance().timeout());
QCOMPARE(socketErrorSpy.size(), 1);
@ -4555,7 +4557,7 @@ void tst_QSslSocket::unsupportedProtocols()
return;
QFETCH(const QSsl::SslProtocol, unsupportedProtocol);
const int timeoutMS = 500;
constexpr auto timeout = 500ms;
// Test a client socket.
{
// 0. connectToHostEncrypted: client-side, non-blocking API, error is discovered
@ -4577,7 +4579,7 @@ void tst_QSslSocket::unsupportedProtocols()
QCOMPARE(socket.error(), QAbstractSocket::UnknownSocketError);
socket.connectToHost(QHostAddress::LocalHost, server.serverPort());
QVERIFY(socket.waitForConnected(timeoutMS));
QVERIFY(socket.waitForConnected(int(timeout.count())));
socket.setProtocol(unsupportedProtocol);
socket.startClientEncryption();
@ -4602,7 +4604,7 @@ void tst_QSslSocket::unsupportedProtocols()
QTcpSocket client;
client.connectToHost(QHostAddress::LocalHost, server.serverPort());
loop.enterLoopMSecs(timeoutMS);
loop.enterLoop(timeout);
QVERIFY(!loop.timeout());
QVERIFY(server.socket);
QCOMPARE(server.socket->error(), QAbstractSocket::SslInvalidUserDataError);
@ -4709,7 +4711,7 @@ void tst_QSslSocket::alertMissingCertificate()
connect(&clientSocket, &QAbstractSocket::errorOccurred, earlyQuitter);
connect(&server, &SslServer::socketError, earlyQuitter);
runner.enterLoopMSecs(1000);
runner.enterLoop(1s);
if (clientSocket.isEncrypted()) {
// When using TLS 1.3 the client side thinks it is connected very
@ -4717,7 +4719,7 @@ void tst_QSslSocket::alertMissingCertificate()
// inevitable disconnect.
QCOMPARE(clientSocket.sessionProtocol(), QSsl::TlsV1_3);
connect(&clientSocket, &QSslSocket::disconnected, &runner, &QTestEventLoop::exitLoop);
runner.enterLoopMSecs(10000);
runner.enterLoop(10s);
}
QVERIFY(serverSpy.size() > 0);
@ -4772,7 +4774,7 @@ void tst_QSslSocket::alertInvalidCertificate()
connect(&clientSocket, &QAbstractSocket::errorOccurred, earlyQuitter);
connect(&server, &SslServer::socketError, earlyQuitter);
runner.enterLoopMSecs(1000);
runner.enterLoop(1s);
QVERIFY(serverSpy.size() > 0);
QVERIFY(clientSpy.size() > 0);
@ -4900,7 +4902,7 @@ void tst_QSslSocket::selfSignedCertificates()
connect(&clientSocket, &QAbstractSocket::errorOccurred, earlyQuitter);
connect(&server, &SslServer::socketError, earlyQuitter);
runner.enterLoopMSecs(1000);
runner.enterLoop(1s);
if (clientKnown) {
QCOMPARE(serverSpy.size(), 0);
@ -5038,7 +5040,7 @@ void tst_QSslSocket::pskHandshake()
connect(&clientSocket, &QAbstractSocket::errorOccurred, earlyQuitter);
connect(&server, &SslServer::socketError, earlyQuitter);
runner.enterLoopMSecs(1000);
runner.enterLoop(1s);
if (pskRight) {
QCOMPARE(serverSpy.size(), 0);

View File

@ -5,6 +5,8 @@
#include <QTestEventLoop>
#include <QtCore/QTimer>
using namespace std::chrono_literals;
// Tests for QTestEventLoop (and some QTRY_* details)
class tst_EventLoop: public QObject
{
@ -51,7 +53,7 @@ void tst_EventLoop::cleanup()
{
DeferredFlag flag;
auto &loop = QTestEventLoop::instance();
loop.enterLoopMSecs(100);
loop.enterLoop(100ms);
QVERIFY2(loop.timeout(), "QTestEventLoop exited prematurely in cleanup()");
QVERIFY(flag);
}
@ -81,7 +83,7 @@ void tst_EventLoop::pass()
{
DeferredFlag flag;
auto &loop = QTestEventLoop::instance();
loop.enterLoopMSecs(100);
loop.enterLoop(100ms);
QVERIFY(loop.timeout());
QVERIFY(flag);
}
@ -92,10 +94,10 @@ void tst_EventLoop::pass()
DeferredFlag flag;
QTestEventLoop loop(this);
QVERIFY(!flag);
loop.enterLoopMSecs(1);
loop.enterLoop(1ms);
QVERIFY(loop.timeout());
QVERIFY(!flag);
loop.enterLoopMSecs(100);
loop.enterLoop(100ms);
QVERIFY(loop.timeout());
QVERIFY(flag);
}

View File

@ -21,6 +21,8 @@
#include <QtNetwork/private/qhostinfo_p.h>
#endif
using namespace std::chrono_literals;
Q_DECLARE_METATYPE(QSharedPointer<char>)
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<QNetworkReply *, qint64> tst_qnetworkreply::runGetRequest(
QNetworkReply *reply = manager->get(request);
connect(reply, SIGNAL(sslErrors(QList<QSslError>)), 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<QSslError>)), 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<QNetworkReply *, qint64> preConnectResult = runGetRequest(&manager, request);
@ -559,12 +561,12 @@ void tst_qnetworkreply::preConnectEncrypted()
void tst_qnetworkreply::preConnectEncrypted_data()
{
#ifndef QT_NO_OPENSSL
QTest::addColumn<int>("sleepTime");
QTest::addColumn<std::chrono::milliseconds>("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<QNetworkReply *, qint64> preConnectResult = runGetRequest(&manager, request);

View File

@ -14,6 +14,8 @@
#include <QtNetwork/qlocalsocket.h>
#include <QtNetwork/qlocalserver.h>
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());