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:
parent
855a6cb676
commit
2a495c2596
@ -99,7 +99,7 @@ public:
|
|||||||
Q_ASSERT(!m_waiting);
|
Q_ASSERT(!m_waiting);
|
||||||
const qsizetype origCount = size();
|
const qsizetype origCount = size();
|
||||||
m_waiting = true;
|
m_waiting = true;
|
||||||
m_loop.enterLoopMSecs(timeout);
|
m_loop.enterLoop(std::chrono::milliseconds{timeout});
|
||||||
m_waiting = false;
|
m_waiting = false;
|
||||||
return size() > origCount;
|
return size() > origCount;
|
||||||
}
|
}
|
||||||
|
@ -25,8 +25,9 @@ public:
|
|||||||
: QObject(parent), _timeout(false)
|
: QObject(parent), _timeout(false)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
inline void enterLoopMSecs(int ms);
|
void enterLoopMSecs(int ms) { enterLoop(std::chrono::milliseconds{ms}); };
|
||||||
inline void enterLoop(int secs) { enterLoopMSecs(secs * 1000); }
|
void enterLoop(int secs) { enterLoop(std::chrono::seconds{secs}); }
|
||||||
|
inline void enterLoop(std::chrono::milliseconds msecs);
|
||||||
|
|
||||||
inline void changeInterval(int secs)
|
inline void changeInterval(int secs)
|
||||||
{ killTimer(timerId); timerId = startTimer(secs * 1000); }
|
{ killTimer(timerId); timerId = startTimer(secs * 1000); }
|
||||||
@ -55,7 +56,7 @@ private:
|
|||||||
Q_DECL_UNUSED_MEMBER uint reserved :31;
|
Q_DECL_UNUSED_MEMBER uint reserved :31;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline void QTestEventLoop::enterLoopMSecs(int ms)
|
inline void QTestEventLoop::enterLoop(std::chrono::milliseconds msecs)
|
||||||
{
|
{
|
||||||
Q_ASSERT(!loop);
|
Q_ASSERT(!loop);
|
||||||
_timeout = false;
|
_timeout = false;
|
||||||
@ -63,9 +64,10 @@ inline void QTestEventLoop::enterLoopMSecs(int ms)
|
|||||||
if (QTest::runningTest() && QTest::currentTestResolved())
|
if (QTest::runningTest() && QTest::currentTestResolved())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
using namespace std::chrono_literals;
|
||||||
QEventLoop l;
|
QEventLoop l;
|
||||||
// if tests want to measure sub-second precision, use a precise timer
|
// 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;
|
loop = &l;
|
||||||
l.exec();
|
l.exec();
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
# undef min
|
# undef min
|
||||||
#endif // Q_CC_MSVC
|
#endif // Q_CC_MSVC
|
||||||
|
|
||||||
|
using namespace std::chrono_literals;
|
||||||
|
|
||||||
class tst_QSocketNotifier : public QObject
|
class tst_QSocketNotifier : public QObject
|
||||||
{
|
{
|
||||||
@ -374,7 +375,7 @@ void tst_QSocketNotifier::asyncMultipleDatagram()
|
|||||||
&tst_QSocketNotifier::async_readDatagramSlot);
|
&tst_QSocketNotifier::async_readDatagramSlot);
|
||||||
|
|
||||||
// activate socket notifiers
|
// activate socket notifiers
|
||||||
QTestEventLoop::instance().enterLoopMSecs(100);
|
QTestEventLoop::instance().enterLoop(100ms);
|
||||||
|
|
||||||
m_asyncSender->writeDatagram("1", makeNonAny(m_asyncReceiver->localAddress()), port);
|
m_asyncSender->writeDatagram("1", makeNonAny(m_asyncReceiver->localAddress()), port);
|
||||||
m_asyncSender->writeDatagram("2", makeNonAny(m_asyncReceiver->localAddress()), port);
|
m_asyncSender->writeDatagram("2", makeNonAny(m_asyncReceiver->localAddress()), port);
|
||||||
|
@ -30,6 +30,9 @@
|
|||||||
# undef interface
|
# undef interface
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
using namespace std::chrono_literals;
|
||||||
|
static constexpr auto DefaultWaitTime = 2s;
|
||||||
|
|
||||||
using namespace Qt::StringLiterals;
|
using namespace Qt::StringLiterals;
|
||||||
|
|
||||||
class SenderObject : public QObject
|
class SenderObject : public QObject
|
||||||
@ -3487,7 +3490,7 @@ void tst_QFuture::runAndTake()
|
|||||||
auto gotcha = QtConcurrent::run(rabbit);
|
auto gotcha = QtConcurrent::run(rabbit);
|
||||||
watcha.setFuture(gotcha);
|
watcha.setFuture(gotcha);
|
||||||
|
|
||||||
loop.enterLoopMSecs(500);
|
loop.enterLoop(500ms);
|
||||||
if (loop.timeout())
|
if (loop.timeout())
|
||||||
QSKIP("Failed to run the task, nothing to test");
|
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
|
// Run event loop, QCoreApplication::postEvent is in use
|
||||||
// in QFutureInterface:
|
// in QFutureInterface:
|
||||||
eventProcessor.enterLoopMSecs(2000);
|
eventProcessor.enterLoop(DefaultWaitTime);
|
||||||
QVERIFY(!eventProcessor.timeout());
|
QVERIFY(!eventProcessor.timeout());
|
||||||
if (QTest::currentTestFailed()) // Failed in our lambda observing 'ready at'
|
if (QTest::currentTestFailed()) // Failed in our lambda observing 'ready at'
|
||||||
return;
|
return;
|
||||||
@ -3933,7 +3936,7 @@ void tst_QFuture::rejectResultOverwrite()
|
|||||||
});
|
});
|
||||||
// Run event loop, QCoreApplication::postEvent is in use
|
// Run event loop, QCoreApplication::postEvent is in use
|
||||||
// in QFutureInterface:
|
// in QFutureInterface:
|
||||||
eventProcessor.enterLoopMSecs(2000);
|
eventProcessor.enterLoop(DefaultWaitTime);
|
||||||
QVERIFY(!eventProcessor.timeout());
|
QVERIFY(!eventProcessor.timeout());
|
||||||
QCOMPARE(resultCounter.size(), 1);
|
QCOMPARE(resultCounter.size(), 1);
|
||||||
f.resume();
|
f.resume();
|
||||||
@ -3972,7 +3975,7 @@ void tst_QFuture::rejectResultOverwrite()
|
|||||||
QTimer::singleShot(50, [&f]() {
|
QTimer::singleShot(50, [&f]() {
|
||||||
f.suspend(); // should exit the loop
|
f.suspend(); // should exit the loop
|
||||||
});
|
});
|
||||||
eventProcessor.enterLoopMSecs(2000);
|
eventProcessor.enterLoop(DefaultWaitTime);
|
||||||
QVERIFY(!eventProcessor.timeout());
|
QVERIFY(!eventProcessor.timeout());
|
||||||
QCOMPARE(resultCounter.size(), 1);
|
QCOMPARE(resultCounter.size(), 1);
|
||||||
f.resume();
|
f.resume();
|
||||||
@ -4011,7 +4014,7 @@ void tst_QFuture::rejectPendingResultOverwrite()
|
|||||||
});
|
});
|
||||||
// Run event loop, QCoreApplication::postEvent is in use
|
// Run event loop, QCoreApplication::postEvent is in use
|
||||||
// in QFutureInterface:
|
// in QFutureInterface:
|
||||||
eventProcessor.enterLoopMSecs(2000);
|
eventProcessor.enterLoop(DefaultWaitTime);
|
||||||
QVERIFY(!eventProcessor.timeout());
|
QVERIFY(!eventProcessor.timeout());
|
||||||
QCOMPARE(resultCounter.size(), 1);
|
QCOMPARE(resultCounter.size(), 1);
|
||||||
f.resume();
|
f.resume();
|
||||||
@ -4055,7 +4058,7 @@ void tst_QFuture::rejectPendingResultOverwrite()
|
|||||||
QTimer::singleShot(50, [&f]() {
|
QTimer::singleShot(50, [&f]() {
|
||||||
f.suspend(); // should exit the loop
|
f.suspend(); // should exit the loop
|
||||||
});
|
});
|
||||||
eventProcessor.enterLoopMSecs(2000);
|
eventProcessor.enterLoop(DefaultWaitTime);
|
||||||
QVERIFY(!eventProcessor.timeout());
|
QVERIFY(!eventProcessor.timeout());
|
||||||
QCOMPARE(resultCounter.size(), 1);
|
QCOMPARE(resultCounter.size(), 1);
|
||||||
f.resume();
|
f.resume();
|
||||||
|
@ -26,6 +26,8 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
using namespace std::chrono_literals;
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
@ -127,8 +129,8 @@ private:
|
|||||||
DtlsPtr clientCrypto;
|
DtlsPtr clientCrypto;
|
||||||
|
|
||||||
QTestEventLoop testLoop;
|
QTestEventLoop testLoop;
|
||||||
const int handshakeTimeoutMS = 5000;
|
static constexpr auto HandshakeTimeout = 5s;
|
||||||
const int dataExchangeTimeoutMS = 1000;
|
static constexpr auto DataExchangeTimeout = 1s;
|
||||||
|
|
||||||
const QByteArray presharedKey = "DEADBEEFDEADBEEF";
|
const QByteArray presharedKey = "DEADBEEFDEADBEEF";
|
||||||
QString certDirPath;
|
QString certDirPath;
|
||||||
@ -413,7 +415,7 @@ void tst_QDtls::handshake()
|
|||||||
QDTLS_VERIFY_NO_ERROR(clientCrypto);
|
QDTLS_VERIFY_NO_ERROR(clientCrypto);
|
||||||
QCOMPARE(clientCrypto->handshakeState(), QDtls::HandshakeInProgress);
|
QCOMPARE(clientCrypto->handshakeState(), QDtls::HandshakeInProgress);
|
||||||
|
|
||||||
testLoop.enterLoopMSecs(handshakeTimeoutMS);
|
testLoop.enterLoop(HandshakeTimeout);
|
||||||
|
|
||||||
QVERIFY(!testLoop.timeout());
|
QVERIFY(!testLoop.timeout());
|
||||||
|
|
||||||
@ -473,7 +475,7 @@ void tst_QDtls::handshakeWithRetransmission()
|
|||||||
// client will re-transmit in 1s., the first part of 'ServerHello' to be
|
// 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.
|
// 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.
|
// We err on safe side and double our (already quite generous) 5s.
|
||||||
testLoop.enterLoopMSecs(handshakeTimeoutMS * 2);
|
testLoop.enterLoop(HandshakeTimeout * 2);
|
||||||
|
|
||||||
QVERIFY(!testLoop.timeout());
|
QVERIFY(!testLoop.timeout());
|
||||||
QDTLS_VERIFY_HANDSHAKE_SUCCESS(serverCrypto);
|
QDTLS_VERIFY_HANDSHAKE_SUCCESS(serverCrypto);
|
||||||
@ -496,7 +498,7 @@ void tst_QDtls::sessionCipher()
|
|||||||
QVERIFY(clientCrypto->setPeer(serverAddress, serverPort, hostName));
|
QVERIFY(clientCrypto->setPeer(serverAddress, serverPort, hostName));
|
||||||
QVERIFY(clientCrypto->doHandshake(&clientSocket));
|
QVERIFY(clientCrypto->doHandshake(&clientSocket));
|
||||||
|
|
||||||
testLoop.enterLoopMSecs(handshakeTimeoutMS);
|
testLoop.enterLoop(HandshakeTimeout);
|
||||||
|
|
||||||
QVERIFY(!testLoop.timeout());
|
QVERIFY(!testLoop.timeout());
|
||||||
QDTLS_VERIFY_HANDSHAKE_SUCCESS(clientCrypto);
|
QDTLS_VERIFY_HANDSHAKE_SUCCESS(clientCrypto);
|
||||||
@ -559,7 +561,7 @@ void tst_QDtls::cipherPreferences()
|
|||||||
QVERIFY(clientCrypto->doHandshake(&clientSocket));
|
QVERIFY(clientCrypto->doHandshake(&clientSocket));
|
||||||
QDTLS_VERIFY_NO_ERROR(clientCrypto);
|
QDTLS_VERIFY_NO_ERROR(clientCrypto);
|
||||||
|
|
||||||
testLoop.enterLoopMSecs(handshakeTimeoutMS);
|
testLoop.enterLoop(HandshakeTimeout);
|
||||||
QVERIFY(!testLoop.timeout());
|
QVERIFY(!testLoop.timeout());
|
||||||
QDTLS_VERIFY_HANDSHAKE_SUCCESS(clientCrypto);
|
QDTLS_VERIFY_HANDSHAKE_SUCCESS(clientCrypto);
|
||||||
QDTLS_VERIFY_HANDSHAKE_SUCCESS(serverCrypto);
|
QDTLS_VERIFY_HANDSHAKE_SUCCESS(serverCrypto);
|
||||||
@ -626,7 +628,7 @@ void tst_QDtls::protocolVersionMatching()
|
|||||||
QVERIFY(clientCrypto->setPeer(serverAddress, serverPort));
|
QVERIFY(clientCrypto->setPeer(serverAddress, serverPort));
|
||||||
QVERIFY(clientCrypto->doHandshake(&clientSocket));
|
QVERIFY(clientCrypto->doHandshake(&clientSocket));
|
||||||
|
|
||||||
testLoop.enterLoopMSecs(handshakeTimeoutMS);
|
testLoop.enterLoop(HandshakeTimeout);
|
||||||
|
|
||||||
if (works) {
|
if (works) {
|
||||||
QDTLS_VERIFY_HANDSHAKE_SUCCESS(serverCrypto);
|
QDTLS_VERIFY_HANDSHAKE_SUCCESS(serverCrypto);
|
||||||
@ -661,7 +663,7 @@ void tst_QDtls::verificationErrors()
|
|||||||
// Now we are ready for handshake:
|
// Now we are ready for handshake:
|
||||||
QVERIFY(clientCrypto->doHandshake(&clientSocket));
|
QVERIFY(clientCrypto->doHandshake(&clientSocket));
|
||||||
|
|
||||||
testLoop.enterLoopMSecs(handshakeTimeoutMS);
|
testLoop.enterLoop(HandshakeTimeout);
|
||||||
|
|
||||||
QVERIFY(!testLoop.timeout());
|
QVERIFY(!testLoop.timeout());
|
||||||
QDTLS_VERIFY_NO_ERROR(serverCrypto);
|
QDTLS_VERIFY_NO_ERROR(serverCrypto);
|
||||||
@ -731,7 +733,7 @@ void tst_QDtls::presetExpectedErrors()
|
|||||||
QVERIFY(clientCrypto->setPeer(serverAddress, serverPort));
|
QVERIFY(clientCrypto->setPeer(serverAddress, serverPort));
|
||||||
QVERIFY(clientCrypto->doHandshake(&clientSocket));
|
QVERIFY(clientCrypto->doHandshake(&clientSocket));
|
||||||
|
|
||||||
testLoop.enterLoopMSecs(handshakeTimeoutMS);
|
testLoop.enterLoop(HandshakeTimeout);
|
||||||
|
|
||||||
QVERIFY(!testLoop.timeout());
|
QVERIFY(!testLoop.timeout());
|
||||||
|
|
||||||
@ -818,7 +820,7 @@ void tst_QDtls::verifyServerCertificate()
|
|||||||
|
|
||||||
QVERIFY(clientCrypto->doHandshake(&clientSocket));
|
QVERIFY(clientCrypto->doHandshake(&clientSocket));
|
||||||
|
|
||||||
testLoop.enterLoopMSecs(handshakeTimeoutMS);
|
testLoop.enterLoop(HandshakeTimeout);
|
||||||
QVERIFY(!testLoop.timeout());
|
QVERIFY(!testLoop.timeout());
|
||||||
|
|
||||||
if (serverKey.isNull() && !serverCerts.isEmpty()) {
|
if (serverKey.isNull() && !serverCerts.isEmpty()) {
|
||||||
@ -948,7 +950,7 @@ void tst_QDtls::verifyClientCertificate()
|
|||||||
QVERIFY(clientCrypto->doHandshake(&clientSocket));
|
QVERIFY(clientCrypto->doHandshake(&clientSocket));
|
||||||
QDTLS_VERIFY_NO_ERROR(clientCrypto);
|
QDTLS_VERIFY_NO_ERROR(clientCrypto);
|
||||||
|
|
||||||
testLoop.enterLoopMSecs(handshakeTimeoutMS);
|
testLoop.enterLoop(HandshakeTimeout);
|
||||||
|
|
||||||
serverConfig = serverCrypto->dtlsConfiguration();
|
serverConfig = serverCrypto->dtlsConfiguration();
|
||||||
|
|
||||||
@ -995,7 +997,7 @@ void tst_QDtls::blacklistedCerificate()
|
|||||||
QVERIFY(clientCrypto->setPeer(serverAddress, serverPort, name));
|
QVERIFY(clientCrypto->setPeer(serverAddress, serverPort, name));
|
||||||
QVERIFY(clientCrypto->doHandshake(&clientSocket));
|
QVERIFY(clientCrypto->doHandshake(&clientSocket));
|
||||||
|
|
||||||
testLoop.enterLoopMSecs(handshakeTimeoutMS);
|
testLoop.enterLoop(HandshakeTimeout);
|
||||||
QVERIFY(!testLoop.timeout());
|
QVERIFY(!testLoop.timeout());
|
||||||
QCOMPARE(clientCrypto->handshakeState(), QDtls::PeerVerificationFailed);
|
QCOMPARE(clientCrypto->handshakeState(), QDtls::PeerVerificationFailed);
|
||||||
QCOMPARE(clientCrypto->dtlsError(), QDtlsError::PeerVerificationError);
|
QCOMPARE(clientCrypto->dtlsError(), QDtlsError::PeerVerificationError);
|
||||||
@ -1047,7 +1049,7 @@ void tst_QDtls::readWriteEncrypted()
|
|||||||
QCOMPARE(clientCrypto->dtlsError(), QDtlsError::InvalidOperation);
|
QCOMPARE(clientCrypto->dtlsError(), QDtlsError::InvalidOperation);
|
||||||
|
|
||||||
// 1.2 Finish the handshake:
|
// 1.2 Finish the handshake:
|
||||||
testLoop.enterLoopMSecs(handshakeTimeoutMS);
|
testLoop.enterLoop(HandshakeTimeout);
|
||||||
QVERIFY(!testLoop.timeout());
|
QVERIFY(!testLoop.timeout());
|
||||||
|
|
||||||
QDTLS_VERIFY_HANDSHAKE_SUCCESS(clientCrypto);
|
QDTLS_VERIFY_HANDSHAKE_SUCCESS(clientCrypto);
|
||||||
@ -1065,7 +1067,7 @@ void tst_QDtls::readWriteEncrypted()
|
|||||||
QVERIFY(clientBytesWritten > 0);
|
QVERIFY(clientBytesWritten > 0);
|
||||||
|
|
||||||
// 5. Exchange client/server messages:
|
// 5. Exchange client/server messages:
|
||||||
testLoop.enterLoopMSecs(dataExchangeTimeoutMS);
|
testLoop.enterLoop(DataExchangeTimeout);
|
||||||
QVERIFY(!testLoop.timeout());
|
QVERIFY(!testLoop.timeout());
|
||||||
|
|
||||||
QCOMPARE(serverExpectedPlainText, serverReceivedPlainText);
|
QCOMPARE(serverExpectedPlainText, serverReceivedPlainText);
|
||||||
@ -1083,7 +1085,7 @@ void tst_QDtls::readWriteEncrypted()
|
|||||||
QCOMPARE(crypto->handshakeState(), QDtls::HandshakeNotStarted);
|
QCOMPARE(crypto->handshakeState(), QDtls::HandshakeNotStarted);
|
||||||
QVERIFY(!crypto->isConnectionEncrypted());
|
QVERIFY(!crypto->isConnectionEncrypted());
|
||||||
// 8. Receive this read notification and handle it:
|
// 8. Receive this read notification and handle it:
|
||||||
testLoop.enterLoopMSecs(dataExchangeTimeoutMS);
|
testLoop.enterLoop(DataExchangeTimeout);
|
||||||
QVERIFY(!testLoop.timeout());
|
QVERIFY(!testLoop.timeout());
|
||||||
|
|
||||||
DtlsPtr &peerCrypto = serverSideShutdown ? clientCrypto : serverCrypto;
|
DtlsPtr &peerCrypto = serverSideShutdown ? clientCrypto : serverCrypto;
|
||||||
@ -1108,7 +1110,7 @@ void tst_QDtls::datagramFragmentation()
|
|||||||
|
|
||||||
QVERIFY(clientCrypto->doHandshake(&clientSocket));
|
QVERIFY(clientCrypto->doHandshake(&clientSocket));
|
||||||
|
|
||||||
testLoop.enterLoopMSecs(handshakeTimeoutMS);
|
testLoop.enterLoop(HandshakeTimeout);
|
||||||
QVERIFY(!testLoop.timeout());
|
QVERIFY(!testLoop.timeout());
|
||||||
|
|
||||||
QDTLS_VERIFY_HANDSHAKE_SUCCESS(clientCrypto);
|
QDTLS_VERIFY_HANDSHAKE_SUCCESS(clientCrypto);
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
using namespace std::chrono_literals;
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
#define STOP_ON_FAILURE \
|
#define STOP_ON_FAILURE \
|
||||||
@ -76,7 +78,7 @@ private:
|
|||||||
quint16 serverPort = 0;
|
quint16 serverPort = 0;
|
||||||
|
|
||||||
QTestEventLoop testLoop;
|
QTestEventLoop testLoop;
|
||||||
int handshakeTimeoutMS = 500;
|
static constexpr auto HandshakeTimeout = 500ms;
|
||||||
|
|
||||||
QDtlsClientVerifier listener;
|
QDtlsClientVerifier listener;
|
||||||
using HandshakePtr = QSharedPointer<QDtls>;
|
using HandshakePtr = QSharedPointer<QDtls>;
|
||||||
@ -327,7 +329,7 @@ void tst_QDtlsCookie::verifyMultipleClients()
|
|||||||
|
|
||||||
clientsToAdd = clientsToWait = 100;
|
clientsToAdd = clientsToWait = 100;
|
||||||
|
|
||||||
testLoop.enterLoopMSecs(handshakeTimeoutMS * clientsToWait);
|
testLoop.enterLoop(HandshakeTimeout * clientsToWait);
|
||||||
QVERIFY(!testLoop.timeout());
|
QVERIFY(!testLoop.timeout());
|
||||||
QVERIFY(clientsToWait == 0);
|
QVERIFY(clientsToWait == 0);
|
||||||
}
|
}
|
||||||
@ -351,7 +353,7 @@ void tst_QDtlsCookie::receiveMessage(QUdpSocket *socket, QByteArray *message,
|
|||||||
Q_ASSERT(socket && message);
|
Q_ASSERT(socket && message);
|
||||||
|
|
||||||
if (socket->pendingDatagramSize() <= 0)
|
if (socket->pendingDatagramSize() <= 0)
|
||||||
testLoop.enterLoopMSecs(handshakeTimeoutMS);
|
testLoop.enterLoop(HandshakeTimeout);
|
||||||
|
|
||||||
QVERIFY(!testLoop.timeout());
|
QVERIFY(!testLoop.timeout());
|
||||||
QVERIFY(socket->pendingDatagramSize());
|
QVERIFY(socket->pendingDatagramSize());
|
||||||
|
@ -28,6 +28,8 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
using namespace std::chrono_literals;
|
||||||
|
|
||||||
// NOTE: the word 'subject' in the code below means the subject of a status request,
|
// 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.
|
// 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 (QSslSocket::*tlsErrorsSignal)(const QList<QSslError> &) = &QSslSocket::sslErrors;
|
||||||
void (QTestEventLoop::*exitLoopSlot)() = &QTestEventLoop::exitLoop;
|
void (QTestEventLoop::*exitLoopSlot)() = &QTestEventLoop::exitLoop;
|
||||||
|
|
||||||
const int handshakeTimeoutMS = 500;
|
static constexpr auto HandshakeTimeout = 500ms;
|
||||||
QTestEventLoop loop;
|
QTestEventLoop loop;
|
||||||
|
|
||||||
std::vector<QSslError::SslError> ocspErrorCodes = {QSslError::OcspNoResponseFound,
|
std::vector<QSslError::SslError> ocspErrorCodes = {QSslError::OcspNoResponseFound,
|
||||||
@ -462,7 +464,7 @@ void tst_QOcsp::connectSelfSigned()
|
|||||||
auto roots = clientConfig.caCertificates();
|
auto roots = clientConfig.caCertificates();
|
||||||
setupOcspClient(clientSocket, issuerToChain(subjectChain), server.peerVerifyName());
|
setupOcspClient(clientSocket, issuerToChain(subjectChain), server.peerVerifyName());
|
||||||
clientSocket.connectToHostEncrypted(server.hostName(), server.serverPort());
|
clientSocket.connectToHostEncrypted(server.hostName(), server.serverPort());
|
||||||
loop.enterLoopMSecs(handshakeTimeoutMS);
|
loop.enterLoop(HandshakeTimeout);
|
||||||
|
|
||||||
QVERIFY(!clientSocket.isEncrypted());
|
QVERIFY(!clientSocket.isEncrypted());
|
||||||
QCOMPARE_SINGLE_ERROR(clientSocket, expectedError);
|
QCOMPARE_SINGLE_ERROR(clientSocket, expectedError);
|
||||||
@ -478,7 +480,7 @@ void tst_QOcsp::connectSelfSigned()
|
|||||||
QSslSocket clientSocket;
|
QSslSocket clientSocket;
|
||||||
setupOcspClient(clientSocket, issuerToChain(subjectChain), server.peerVerifyName());
|
setupOcspClient(clientSocket, issuerToChain(subjectChain), server.peerVerifyName());
|
||||||
clientSocket.connectToHostEncrypted(server.hostName(), server.serverPort());
|
clientSocket.connectToHostEncrypted(server.hostName(), server.serverPort());
|
||||||
loop.enterLoopMSecs(handshakeTimeoutMS);
|
loop.enterLoop(HandshakeTimeout);
|
||||||
|
|
||||||
QVERIFY_HANDSHAKE_WITHOUT_ERRORS(clientSocket);
|
QVERIFY_HANDSHAKE_WITHOUT_ERRORS(clientSocket);
|
||||||
|
|
||||||
@ -543,7 +545,7 @@ void tst_QOcsp::badStatus()
|
|||||||
QSslSocket clientSocket;
|
QSslSocket clientSocket;
|
||||||
setupOcspClient(clientSocket, issuerToChain(subjectChain), server.peerVerifyName());
|
setupOcspClient(clientSocket, issuerToChain(subjectChain), server.peerVerifyName());
|
||||||
clientSocket.connectToHostEncrypted(server.hostName(), server.serverPort());
|
clientSocket.connectToHostEncrypted(server.hostName(), server.serverPort());
|
||||||
loop.enterLoopMSecs(handshakeTimeoutMS);
|
loop.enterLoop(HandshakeTimeout);
|
||||||
|
|
||||||
QVERIFY(!clientSocket.isEncrypted());
|
QVERIFY(!clientSocket.isEncrypted());
|
||||||
QCOMPARE_SINGLE_ERROR(clientSocket, expectedError.error());
|
QCOMPARE_SINGLE_ERROR(clientSocket, expectedError.error());
|
||||||
@ -574,7 +576,7 @@ void tst_QOcsp::multipleSingleResponses()
|
|||||||
QSslSocket clientSocket;
|
QSslSocket clientSocket;
|
||||||
setupOcspClient(clientSocket, issuerToChain(responderChain), server.peerVerifyName());
|
setupOcspClient(clientSocket, issuerToChain(responderChain), server.peerVerifyName());
|
||||||
clientSocket.connectToHostEncrypted(server.hostName(), server.serverPort());
|
clientSocket.connectToHostEncrypted(server.hostName(), server.serverPort());
|
||||||
loop.enterLoopMSecs(handshakeTimeoutMS);
|
loop.enterLoop(HandshakeTimeout);
|
||||||
|
|
||||||
QVERIFY(!clientSocket.isEncrypted());
|
QVERIFY(!clientSocket.isEncrypted());
|
||||||
QCOMPARE_SINGLE_ERROR(clientSocket, expectedError);
|
QCOMPARE_SINGLE_ERROR(clientSocket, expectedError);
|
||||||
@ -594,7 +596,7 @@ void tst_QOcsp::malformedResponse()
|
|||||||
QSslSocket clientSocket;
|
QSslSocket clientSocket;
|
||||||
setupOcspClient(clientSocket, issuerToChain(serverChain), server.peerVerifyName());
|
setupOcspClient(clientSocket, issuerToChain(serverChain), server.peerVerifyName());
|
||||||
clientSocket.connectToHostEncrypted(server.hostName(), server.serverPort());
|
clientSocket.connectToHostEncrypted(server.hostName(), server.serverPort());
|
||||||
loop.enterLoopMSecs(handshakeTimeoutMS);
|
loop.enterLoop(HandshakeTimeout);
|
||||||
|
|
||||||
QVERIFY(!clientSocket.isEncrypted());
|
QVERIFY(!clientSocket.isEncrypted());
|
||||||
QCOMPARE(clientSocket.error(), QAbstractSocket::SslHandshakeFailedError);
|
QCOMPARE(clientSocket.error(), QAbstractSocket::SslHandshakeFailedError);
|
||||||
@ -633,7 +635,7 @@ void tst_QOcsp::expiredResponse()
|
|||||||
QSslSocket clientSocket;
|
QSslSocket clientSocket;
|
||||||
setupOcspClient(clientSocket, issuerToChain(subjectChain), server.peerVerifyName());
|
setupOcspClient(clientSocket, issuerToChain(subjectChain), server.peerVerifyName());
|
||||||
clientSocket.connectToHostEncrypted(server.hostName(), server.serverPort());
|
clientSocket.connectToHostEncrypted(server.hostName(), server.serverPort());
|
||||||
loop.enterLoopMSecs(handshakeTimeoutMS);
|
loop.enterLoop(HandshakeTimeout);
|
||||||
|
|
||||||
QVERIFY(!clientSocket.isEncrypted());
|
QVERIFY(!clientSocket.isEncrypted());
|
||||||
QCOMPARE_SINGLE_ERROR(clientSocket, expectedError);
|
QCOMPARE_SINGLE_ERROR(clientSocket, expectedError);
|
||||||
@ -664,7 +666,7 @@ void tst_QOcsp::noNextUpdate()
|
|||||||
QSslSocket clientSocket;
|
QSslSocket clientSocket;
|
||||||
setupOcspClient(clientSocket, issuerToChain(subjectChain), server.peerVerifyName());
|
setupOcspClient(clientSocket, issuerToChain(subjectChain), server.peerVerifyName());
|
||||||
clientSocket.connectToHostEncrypted(server.hostName(), server.serverPort());
|
clientSocket.connectToHostEncrypted(server.hostName(), server.serverPort());
|
||||||
loop.enterLoopMSecs(handshakeTimeoutMS);
|
loop.enterLoop(HandshakeTimeout);
|
||||||
|
|
||||||
QVERIFY_HANDSHAKE_WITHOUT_ERRORS(clientSocket);
|
QVERIFY_HANDSHAKE_WITHOUT_ERRORS(clientSocket);
|
||||||
}
|
}
|
||||||
@ -710,7 +712,7 @@ void tst_QOcsp::wrongCertificateInResponse()
|
|||||||
QSslSocket clientSocket;
|
QSslSocket clientSocket;
|
||||||
setupOcspClient(clientSocket, issuerToChain(subjectChain), server.peerVerifyName());
|
setupOcspClient(clientSocket, issuerToChain(subjectChain), server.peerVerifyName());
|
||||||
clientSocket.connectToHostEncrypted(server.hostName(), server.serverPort());
|
clientSocket.connectToHostEncrypted(server.hostName(), server.serverPort());
|
||||||
loop.enterLoopMSecs(handshakeTimeoutMS);
|
loop.enterLoop(HandshakeTimeout);
|
||||||
|
|
||||||
QVERIFY(!clientSocket.isEncrypted());
|
QVERIFY(!clientSocket.isEncrypted());
|
||||||
QVERIFY(containsError(clientSocket.sslHandshakeErrors(), expectedError));
|
QVERIFY(containsError(clientSocket.sslHandshakeErrors(), expectedError));
|
||||||
@ -735,7 +737,7 @@ void tst_QOcsp::untrustedResponder()
|
|||||||
QSslSocket clientSocket;
|
QSslSocket clientSocket;
|
||||||
setupOcspClient(clientSocket, {}, server.peerVerifyName());
|
setupOcspClient(clientSocket, {}, server.peerVerifyName());
|
||||||
clientSocket.connectToHostEncrypted(server.hostName(), server.serverPort());
|
clientSocket.connectToHostEncrypted(server.hostName(), server.serverPort());
|
||||||
loop.enterLoopMSecs(handshakeTimeoutMS);
|
loop.enterLoop(HandshakeTimeout);
|
||||||
|
|
||||||
QVERIFY(!clientSocket.isEncrypted());
|
QVERIFY(!clientSocket.isEncrypted());
|
||||||
QVERIFY(containsError(clientSocket.sslHandshakeErrors(), expectedError));
|
QVERIFY(containsError(clientSocket.sslHandshakeErrors(), expectedError));
|
||||||
|
@ -44,6 +44,8 @@
|
|||||||
#include "private/qsslsocket_p.h"
|
#include "private/qsslsocket_p.h"
|
||||||
#include "private/qsslconfiguration_p.h"
|
#include "private/qsslconfiguration_p.h"
|
||||||
|
|
||||||
|
using namespace std::chrono_literals;
|
||||||
|
|
||||||
QT_WARNING_PUSH
|
QT_WARNING_PUSH
|
||||||
QT_WARNING_DISABLE_DEPRECATED
|
QT_WARNING_DISABLE_DEPRECATED
|
||||||
// make these enum values available without causing deprecation warnings:
|
// 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:
|
// Make sure we have some data buffered so that close will try to flush:
|
||||||
clientSocket.write(QByteArray(1000000, Qt::Uninitialized));
|
clientSocket.write(QByteArray(1000000, Qt::Uninitialized));
|
||||||
|
|
||||||
QTestEventLoop::instance().enterLoopMSecs(1000);
|
QTestEventLoop::instance().enterLoop(1s);
|
||||||
QVERIFY(!QTestEventLoop::instance().timeout());
|
QVERIFY(!QTestEventLoop::instance().timeout());
|
||||||
|
|
||||||
QCOMPARE(socketErrorSpy.size(), 1);
|
QCOMPARE(socketErrorSpy.size(), 1);
|
||||||
@ -4555,7 +4557,7 @@ void tst_QSslSocket::unsupportedProtocols()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
QFETCH(const QSsl::SslProtocol, unsupportedProtocol);
|
QFETCH(const QSsl::SslProtocol, unsupportedProtocol);
|
||||||
const int timeoutMS = 500;
|
constexpr auto timeout = 500ms;
|
||||||
// Test a client socket.
|
// Test a client socket.
|
||||||
{
|
{
|
||||||
// 0. connectToHostEncrypted: client-side, non-blocking API, error is discovered
|
// 0. connectToHostEncrypted: client-side, non-blocking API, error is discovered
|
||||||
@ -4577,7 +4579,7 @@ void tst_QSslSocket::unsupportedProtocols()
|
|||||||
QCOMPARE(socket.error(), QAbstractSocket::UnknownSocketError);
|
QCOMPARE(socket.error(), QAbstractSocket::UnknownSocketError);
|
||||||
|
|
||||||
socket.connectToHost(QHostAddress::LocalHost, server.serverPort());
|
socket.connectToHost(QHostAddress::LocalHost, server.serverPort());
|
||||||
QVERIFY(socket.waitForConnected(timeoutMS));
|
QVERIFY(socket.waitForConnected(int(timeout.count())));
|
||||||
|
|
||||||
socket.setProtocol(unsupportedProtocol);
|
socket.setProtocol(unsupportedProtocol);
|
||||||
socket.startClientEncryption();
|
socket.startClientEncryption();
|
||||||
@ -4602,7 +4604,7 @@ void tst_QSslSocket::unsupportedProtocols()
|
|||||||
|
|
||||||
QTcpSocket client;
|
QTcpSocket client;
|
||||||
client.connectToHost(QHostAddress::LocalHost, server.serverPort());
|
client.connectToHost(QHostAddress::LocalHost, server.serverPort());
|
||||||
loop.enterLoopMSecs(timeoutMS);
|
loop.enterLoop(timeout);
|
||||||
QVERIFY(!loop.timeout());
|
QVERIFY(!loop.timeout());
|
||||||
QVERIFY(server.socket);
|
QVERIFY(server.socket);
|
||||||
QCOMPARE(server.socket->error(), QAbstractSocket::SslInvalidUserDataError);
|
QCOMPARE(server.socket->error(), QAbstractSocket::SslInvalidUserDataError);
|
||||||
@ -4709,7 +4711,7 @@ void tst_QSslSocket::alertMissingCertificate()
|
|||||||
connect(&clientSocket, &QAbstractSocket::errorOccurred, earlyQuitter);
|
connect(&clientSocket, &QAbstractSocket::errorOccurred, earlyQuitter);
|
||||||
connect(&server, &SslServer::socketError, earlyQuitter);
|
connect(&server, &SslServer::socketError, earlyQuitter);
|
||||||
|
|
||||||
runner.enterLoopMSecs(1000);
|
runner.enterLoop(1s);
|
||||||
|
|
||||||
if (clientSocket.isEncrypted()) {
|
if (clientSocket.isEncrypted()) {
|
||||||
// When using TLS 1.3 the client side thinks it is connected very
|
// When using TLS 1.3 the client side thinks it is connected very
|
||||||
@ -4717,7 +4719,7 @@ void tst_QSslSocket::alertMissingCertificate()
|
|||||||
// inevitable disconnect.
|
// inevitable disconnect.
|
||||||
QCOMPARE(clientSocket.sessionProtocol(), QSsl::TlsV1_3);
|
QCOMPARE(clientSocket.sessionProtocol(), QSsl::TlsV1_3);
|
||||||
connect(&clientSocket, &QSslSocket::disconnected, &runner, &QTestEventLoop::exitLoop);
|
connect(&clientSocket, &QSslSocket::disconnected, &runner, &QTestEventLoop::exitLoop);
|
||||||
runner.enterLoopMSecs(10000);
|
runner.enterLoop(10s);
|
||||||
}
|
}
|
||||||
|
|
||||||
QVERIFY(serverSpy.size() > 0);
|
QVERIFY(serverSpy.size() > 0);
|
||||||
@ -4772,7 +4774,7 @@ void tst_QSslSocket::alertInvalidCertificate()
|
|||||||
connect(&clientSocket, &QAbstractSocket::errorOccurred, earlyQuitter);
|
connect(&clientSocket, &QAbstractSocket::errorOccurred, earlyQuitter);
|
||||||
connect(&server, &SslServer::socketError, earlyQuitter);
|
connect(&server, &SslServer::socketError, earlyQuitter);
|
||||||
|
|
||||||
runner.enterLoopMSecs(1000);
|
runner.enterLoop(1s);
|
||||||
|
|
||||||
QVERIFY(serverSpy.size() > 0);
|
QVERIFY(serverSpy.size() > 0);
|
||||||
QVERIFY(clientSpy.size() > 0);
|
QVERIFY(clientSpy.size() > 0);
|
||||||
@ -4900,7 +4902,7 @@ void tst_QSslSocket::selfSignedCertificates()
|
|||||||
connect(&clientSocket, &QAbstractSocket::errorOccurred, earlyQuitter);
|
connect(&clientSocket, &QAbstractSocket::errorOccurred, earlyQuitter);
|
||||||
connect(&server, &SslServer::socketError, earlyQuitter);
|
connect(&server, &SslServer::socketError, earlyQuitter);
|
||||||
|
|
||||||
runner.enterLoopMSecs(1000);
|
runner.enterLoop(1s);
|
||||||
|
|
||||||
if (clientKnown) {
|
if (clientKnown) {
|
||||||
QCOMPARE(serverSpy.size(), 0);
|
QCOMPARE(serverSpy.size(), 0);
|
||||||
@ -5038,7 +5040,7 @@ void tst_QSslSocket::pskHandshake()
|
|||||||
connect(&clientSocket, &QAbstractSocket::errorOccurred, earlyQuitter);
|
connect(&clientSocket, &QAbstractSocket::errorOccurred, earlyQuitter);
|
||||||
connect(&server, &SslServer::socketError, earlyQuitter);
|
connect(&server, &SslServer::socketError, earlyQuitter);
|
||||||
|
|
||||||
runner.enterLoopMSecs(1000);
|
runner.enterLoop(1s);
|
||||||
|
|
||||||
if (pskRight) {
|
if (pskRight) {
|
||||||
QCOMPARE(serverSpy.size(), 0);
|
QCOMPARE(serverSpy.size(), 0);
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
#include <QTestEventLoop>
|
#include <QTestEventLoop>
|
||||||
#include <QtCore/QTimer>
|
#include <QtCore/QTimer>
|
||||||
|
|
||||||
|
using namespace std::chrono_literals;
|
||||||
|
|
||||||
// Tests for QTestEventLoop (and some QTRY_* details)
|
// Tests for QTestEventLoop (and some QTRY_* details)
|
||||||
class tst_EventLoop: public QObject
|
class tst_EventLoop: public QObject
|
||||||
{
|
{
|
||||||
@ -51,7 +53,7 @@ void tst_EventLoop::cleanup()
|
|||||||
{
|
{
|
||||||
DeferredFlag flag;
|
DeferredFlag flag;
|
||||||
auto &loop = QTestEventLoop::instance();
|
auto &loop = QTestEventLoop::instance();
|
||||||
loop.enterLoopMSecs(100);
|
loop.enterLoop(100ms);
|
||||||
QVERIFY2(loop.timeout(), "QTestEventLoop exited prematurely in cleanup()");
|
QVERIFY2(loop.timeout(), "QTestEventLoop exited prematurely in cleanup()");
|
||||||
QVERIFY(flag);
|
QVERIFY(flag);
|
||||||
}
|
}
|
||||||
@ -81,7 +83,7 @@ void tst_EventLoop::pass()
|
|||||||
{
|
{
|
||||||
DeferredFlag flag;
|
DeferredFlag flag;
|
||||||
auto &loop = QTestEventLoop::instance();
|
auto &loop = QTestEventLoop::instance();
|
||||||
loop.enterLoopMSecs(100);
|
loop.enterLoop(100ms);
|
||||||
QVERIFY(loop.timeout());
|
QVERIFY(loop.timeout());
|
||||||
QVERIFY(flag);
|
QVERIFY(flag);
|
||||||
}
|
}
|
||||||
@ -92,10 +94,10 @@ void tst_EventLoop::pass()
|
|||||||
DeferredFlag flag;
|
DeferredFlag flag;
|
||||||
QTestEventLoop loop(this);
|
QTestEventLoop loop(this);
|
||||||
QVERIFY(!flag);
|
QVERIFY(!flag);
|
||||||
loop.enterLoopMSecs(1);
|
loop.enterLoop(1ms);
|
||||||
QVERIFY(loop.timeout());
|
QVERIFY(loop.timeout());
|
||||||
QVERIFY(!flag);
|
QVERIFY(!flag);
|
||||||
loop.enterLoopMSecs(100);
|
loop.enterLoop(100ms);
|
||||||
QVERIFY(loop.timeout());
|
QVERIFY(loop.timeout());
|
||||||
QVERIFY(flag);
|
QVERIFY(flag);
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,8 @@
|
|||||||
#include <QtNetwork/private/qhostinfo_p.h>
|
#include <QtNetwork/private/qhostinfo_p.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
using namespace std::chrono_literals;
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(QSharedPointer<char>)
|
Q_DECLARE_METATYPE(QSharedPointer<char>)
|
||||||
|
|
||||||
class TimedSender: public QThread
|
class TimedSender: public QThread
|
||||||
@ -456,7 +458,7 @@ void tst_qnetworkreply::httpLatency()
|
|||||||
QNetworkRequest request(QUrl("http://" + QtNetworkSettings::serverName() + "/qtest/"));
|
QNetworkRequest request(QUrl("http://" + QtNetworkSettings::serverName() + "/qtest/"));
|
||||||
QNetworkReply* reply = manager.get(request);
|
QNetworkReply* reply = manager.get(request);
|
||||||
connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()), Qt::QueuedConnection);
|
connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()), Qt::QueuedConnection);
|
||||||
QTestEventLoop::instance().enterLoop(5);
|
QTestEventLoop::instance().enterLoop(5s);
|
||||||
QVERIFY(!QTestEventLoop::instance().timeout());
|
QVERIFY(!QTestEventLoop::instance().timeout());
|
||||||
delete reply;
|
delete reply;
|
||||||
}
|
}
|
||||||
@ -470,7 +472,7 @@ QPair<QNetworkReply *, qint64> tst_qnetworkreply::runGetRequest(
|
|||||||
QNetworkReply *reply = manager->get(request);
|
QNetworkReply *reply = manager->get(request);
|
||||||
connect(reply, SIGNAL(sslErrors(QList<QSslError>)), reply, SLOT(ignoreSslErrors()));
|
connect(reply, SIGNAL(sslErrors(QList<QSslError>)), reply, SLOT(ignoreSslErrors()));
|
||||||
connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()), Qt::QueuedConnection);
|
connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()), Qt::QueuedConnection);
|
||||||
QTestEventLoop::instance().enterLoop(20);
|
QTestEventLoop::instance().enterLoop(20s);
|
||||||
qint64 elapsed = timer.elapsed();
|
qint64 elapsed = timer.elapsed();
|
||||||
return qMakePair(reply, elapsed);
|
return qMakePair(reply, elapsed);
|
||||||
}
|
}
|
||||||
@ -501,7 +503,7 @@ void tst_qnetworkreply::echoPerformance()
|
|||||||
QNetworkReply* reply = manager.post(request, data);
|
QNetworkReply* reply = manager.post(request, data);
|
||||||
connect(reply, SIGNAL(sslErrors(QList<QSslError>)), reply, SLOT(ignoreSslErrors()));
|
connect(reply, SIGNAL(sslErrors(QList<QSslError>)), reply, SLOT(ignoreSslErrors()));
|
||||||
connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()), Qt::QueuedConnection);
|
connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()), Qt::QueuedConnection);
|
||||||
QTestEventLoop::instance().enterLoop(5);
|
QTestEventLoop::instance().enterLoop(5s);
|
||||||
QVERIFY(!QTestEventLoop::instance().timeout());
|
QVERIFY(!QTestEventLoop::instance().timeout());
|
||||||
QVERIFY(reply->error() == QNetworkReply::NoError);
|
QVERIFY(reply->error() == QNetworkReply::NoError);
|
||||||
delete reply;
|
delete reply;
|
||||||
@ -510,7 +512,7 @@ void tst_qnetworkreply::echoPerformance()
|
|||||||
|
|
||||||
void tst_qnetworkreply::preConnectEncrypted()
|
void tst_qnetworkreply::preConnectEncrypted()
|
||||||
{
|
{
|
||||||
QFETCH(int, sleepTime);
|
QFETCH(std::chrono::milliseconds, sleepTime);
|
||||||
QString hostName = QLatin1String("www.google.com");
|
QString hostName = QLatin1String("www.google.com");
|
||||||
|
|
||||||
QNetworkAccessManager manager;
|
QNetworkAccessManager manager;
|
||||||
@ -541,7 +543,7 @@ void tst_qnetworkreply::preConnectEncrypted()
|
|||||||
|
|
||||||
// now try to make the connection beforehand
|
// now try to make the connection beforehand
|
||||||
manager.connectToHostEncrypted(hostName);
|
manager.connectToHostEncrypted(hostName);
|
||||||
QTestEventLoop::instance().enterLoopMSecs(sleepTime);
|
QTestEventLoop::instance().enterLoop(sleepTime);
|
||||||
|
|
||||||
// now make another request and hopefully use the existing connection
|
// now make another request and hopefully use the existing connection
|
||||||
QPair<QNetworkReply *, qint64> preConnectResult = runGetRequest(&manager, request);
|
QPair<QNetworkReply *, qint64> preConnectResult = runGetRequest(&manager, request);
|
||||||
@ -559,12 +561,12 @@ void tst_qnetworkreply::preConnectEncrypted()
|
|||||||
void tst_qnetworkreply::preConnectEncrypted_data()
|
void tst_qnetworkreply::preConnectEncrypted_data()
|
||||||
{
|
{
|
||||||
#ifndef QT_NO_OPENSSL
|
#ifndef QT_NO_OPENSSL
|
||||||
QTest::addColumn<int>("sleepTime");
|
QTest::addColumn<std::chrono::milliseconds>("sleepTime");
|
||||||
// start a new normal request after preconnecting is done
|
// 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
|
// start a new normal request while preconnecting is in-flight
|
||||||
QTest::newRow("HTTPS-100ms") << 100;
|
QTest::newRow("HTTPS-100ms") << 100ms;
|
||||||
#endif // QT_NO_OPENSSL
|
#endif // QT_NO_OPENSSL
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -915,9 +917,9 @@ void tst_qnetworkreply::preConnect()
|
|||||||
manager.clearAccessCache();
|
manager.clearAccessCache();
|
||||||
|
|
||||||
// now try to make the connection beforehand
|
// now try to make the connection beforehand
|
||||||
QFETCH(int, sleepTime);
|
QFETCH(std::chrono::milliseconds, sleepTime);
|
||||||
manager.connectToHost(hostName);
|
manager.connectToHost(hostName);
|
||||||
QTestEventLoop::instance().enterLoopMSecs(sleepTime);
|
QTestEventLoop::instance().enterLoop(sleepTime);
|
||||||
|
|
||||||
// now make another request and hopefully use the existing connection
|
// now make another request and hopefully use the existing connection
|
||||||
QPair<QNetworkReply *, qint64> preConnectResult = runGetRequest(&manager, request);
|
QPair<QNetworkReply *, qint64> preConnectResult = runGetRequest(&manager, request);
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
#include <QtNetwork/qlocalsocket.h>
|
#include <QtNetwork/qlocalsocket.h>
|
||||||
#include <QtNetwork/qlocalserver.h>
|
#include <QtNetwork/qlocalserver.h>
|
||||||
|
|
||||||
|
using namespace std::chrono_literals;
|
||||||
|
|
||||||
class tst_QLocalSocket : public QObject
|
class tst_QLocalSocket : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -175,7 +177,7 @@ void tst_QLocalSocket::dataExchange()
|
|||||||
QFETCH(int, chunkSize);
|
QFETCH(int, chunkSize);
|
||||||
|
|
||||||
Q_ASSERT(chunkSize > 0 && connections > 0);
|
Q_ASSERT(chunkSize > 0 && connections > 0);
|
||||||
const qint64 timeToTest = 5000;
|
const auto timeToTest = 5000ms;
|
||||||
|
|
||||||
ServerThread serverThread(chunkSize);
|
ServerThread serverThread(chunkSize);
|
||||||
serverThread.start();
|
serverThread.start();
|
||||||
@ -191,7 +193,7 @@ void tst_QLocalSocket::dataExchange()
|
|||||||
Q_UNUSED(channel);
|
Q_UNUSED(channel);
|
||||||
|
|
||||||
totalReceived += bytes;
|
totalReceived += bytes;
|
||||||
if (timer.elapsed() >= timeToTest) {
|
if (timer.elapsed() >= timeToTest.count()) {
|
||||||
factory.stopped = true;
|
factory.stopped = true;
|
||||||
eventLoop.exitLoop();
|
eventLoop.exitLoop();
|
||||||
}
|
}
|
||||||
@ -199,7 +201,7 @@ void tst_QLocalSocket::dataExchange()
|
|||||||
|
|
||||||
timer.start();
|
timer.start();
|
||||||
emit factory.start();
|
emit factory.start();
|
||||||
eventLoop.enterLoopMSecs(timeToTest * 2);
|
eventLoop.enterLoop(timeToTest * 2);
|
||||||
|
|
||||||
if (!QTest::currentTestFailed())
|
if (!QTest::currentTestFailed())
|
||||||
qDebug("Transfer rate: %.1f MB/s", totalReceived / 1048.576 / timer.elapsed());
|
qDebug("Transfer rate: %.1f MB/s", totalReceived / 1048.576 / timer.elapsed());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user