From 0f3c9782e6e2459f3fea361962492f52fa9c4fd9 Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Mon, 20 Nov 2017 16:50:12 +0100 Subject: tst_QNetworkReply::ioHttpRedirectErrors - fix a flaky test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This test became a real pain recently. A close look at the test shows several problems (strangely enough, the failure can never be reproduced on real machines, only on VM - Ubuntu and RHEL 6.6). There are several asserts that are firing from time to time here and there. They show that the logic in test is broken/incorrect. QNAM can open several connections to a host, our test then incorrectly resets its 'client' data-member and bad things can later happen after 'bytesWrittenSlot' executed (and deleted a socket). For example, I can reproduce this scenario in every second run: 1. incoming connection -> client = socket(descriptor), connect to client's readyRead (s1) 2. incoming connection -> client = socket(descriptor), connect to client's readyRead (s2) QNAM sends a request on s1. We reply on s2 (which is already wrong) and call client->deleteLater(), which resets client to nullptr. If QNAM sends something else on s1, we hit assert(!client.isNull()). To avoid this, whenever 'sender' in any slot is different from the 'client', we use the actual 'sender' to reply. Another problem is this weird and rather cryptic waitForFinish which is not needed in this particular test since we wait for reply error, not 'finished'. As it happened before - it's not clear if these two problems were the cause of guaranteed fails on CI - an integration failed ~10 times in a row in the same test (not happening anymore though). Task-number: QTBUG-64569 Change-Id: Id9aa091290350c61fadf1c3c001e7c2e1b5ac8f4 Reviewed-by: Edward Welbourne Reviewed-by: Mårten Nordheim --- .../access/qnetworkreply/tst_qnetworkreply.cpp | 38 +++++++++++++++------- 1 file changed, 27 insertions(+), 11 deletions(-) (limited to 'tests/auto/network') diff --git a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp index 3a752c0748..9fa54597f1 100644 --- a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp @@ -622,7 +622,7 @@ protected: Q_ASSERT(!client.isNull()); // we need to emulate the bytesWrittenSlot call if the data is empty. if (dataToTransmit.size() == 0) { - QMetaObject::invokeMethod(this, "bytesWrittenSlot", Qt::QueuedConnection); + emit client->bytesWritten(0); } else { client->write(dataToTransmit); // FIXME: For SSL connections, if we don't flush the socket, the @@ -659,22 +659,26 @@ private slots: #ifndef QT_NO_SSL void slotSslErrors(const QList& errors) { - Q_ASSERT(!client.isNull()); - qDebug() << "slotSslErrors" << client->errorString() << errors; + QTcpSocket *currentClient = qobject_cast(sender()); + Q_ASSERT(currentClient); + qDebug() << "slotSslErrors" << currentClient->errorString() << errors; } #endif void slotError(QAbstractSocket::SocketError err) { - if (client.isNull()) - qDebug() << "slotError" << err; - else - qDebug() << "slotError" << err << client->errorString(); + QTcpSocket *currentClient = qobject_cast(sender()); + Q_ASSERT(currentClient); + qDebug() << "slotError" << err << currentClient->errorString(); } public slots: void readyReadSlot() { - Q_ASSERT(!client.isNull()); + QTcpSocket *currentClient = qobject_cast(sender()); + Q_ASSERT(currentClient); + if (currentClient != client) + client = currentClient; + receivedData += client->readAll(); const int doubleEndlPos = receivedData.indexOf("\r\n\r\n"); @@ -8290,11 +8294,23 @@ void tst_QNetworkReply::ioHttpRedirectErrors() QNetworkReplyPtr reply(manager.get(request)); if (localhost.scheme() == "https") reply.data()->ignoreSslErrors(); - QSignalSpy spy(reply.data(), SIGNAL(error(QNetworkReply::NetworkError))); - QCOMPARE(waitForFinish(reply), int(Failure)); + QEventLoop eventLoop; + QTimer watchDog; + watchDog.setSingleShot(true); - QCOMPARE(spy.count(), 1); + reply->connect(reply.data(), QOverload().of(&QNetworkReply::error), + [&eventLoop](QNetworkReply::NetworkError){ + eventLoop.exit(Failure); + }); + + watchDog.connect(&watchDog, &QTimer::timeout, [&eventLoop](){ + eventLoop.exit(Timeout); + }); + + watchDog.start(5000); + + QCOMPARE(eventLoop.exec(), int(Failure)); QCOMPARE(reply->error(), error); } -- cgit v1.2.3 From c3a5c482efcac794033721e4e32b01b012704096 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Fri, 17 Nov 2017 14:44:36 +0100 Subject: Fix tst_QSslSocket::waitForConnectedEncryptedReadyRead ... and unblacklist it. It was blacklisted some years ago because it was failing too often. It was failing because the ssl socket had already received and decrypted all the data it was going to get, meaning the waitForReadyRead call was just going to block forever. Change-Id: Ia540735177d4e1be8696f2d752f1d7813faecfe5 Reviewed-by: Timur Pocheptsov Reviewed-by: Edward Welbourne --- tests/auto/network/ssl/qsslsocket/BLACKLIST | 2 -- tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp | 7 ++++++- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'tests/auto/network') diff --git a/tests/auto/network/ssl/qsslsocket/BLACKLIST b/tests/auto/network/ssl/qsslsocket/BLACKLIST index 52c023b78f..a9ecc69f50 100644 --- a/tests/auto/network/ssl/qsslsocket/BLACKLIST +++ b/tests/auto/network/ssl/qsslsocket/BLACKLIST @@ -1,6 +1,4 @@ windows -[waitForConnectedEncryptedReadyRead:WithSocks5ProxyAuth] -* [protocolServerSide:ssl3-any] rhel-7.2 [protocolServerSide:tls1.0-any] diff --git a/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp b/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp index c74d3b5375..f97627cb42 100644 --- a/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp +++ b/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp @@ -1587,7 +1587,12 @@ void tst_QSslSocket::waitForConnectedEncryptedReadyRead() QFETCH_GLOBAL(bool, setProxy); if (setProxy && !socket->waitForEncrypted(10000)) QSKIP("Skipping flaky test - See QTBUG-29941"); - QVERIFY(socket->waitForReadyRead(10000)); + + // We only do this if we have no bytes available to read already because readyRead will + // not be emitted again. + if (socket->bytesAvailable() == 0) + QVERIFY(socket->waitForReadyRead(10000)); + QVERIFY(!socket->peerCertificate().isNull()); QVERIFY(!socket->peerCertificateChain().isEmpty()); } -- cgit v1.2.3 From 5a235da270a4ea65b7ef1edf31a761c41dbfcc88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Wed, 22 Nov 2017 14:16:42 +0100 Subject: tst_QTcpSocket: fix disconnectWhileLookingUp ... and unblacklist it on Windows. From what I can tell there is no particular reason why this test fails other than that it is a little too slow sometimes (these things happen). So, to fix the test I bumped the timeout, but to avoid the test running for longer on every test-run it now also ends when the socket enters the "Unconnected" state. Previously it failed 171/500 times, and after this patch it failed 0/1000 times. Change-Id: I4266bff6b91aaaf502ee66265d01c3a177706402 Reviewed-by: Edward Welbourne Reviewed-by: Thiago Macieira Reviewed-by: Jesus Fernandez --- tests/auto/network/socket/qtcpsocket/BLACKLIST | 2 -- tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp | 9 ++++++++- 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'tests/auto/network') diff --git a/tests/auto/network/socket/qtcpsocket/BLACKLIST b/tests/auto/network/socket/qtcpsocket/BLACKLIST index 5fc2589323..96e59e5678 100644 --- a/tests/auto/network/socket/qtcpsocket/BLACKLIST +++ b/tests/auto/network/socket/qtcpsocket/BLACKLIST @@ -6,8 +6,6 @@ windows windows [invalidProxy:socks5-on-http] windows -[disconnectWhileLookingUp] -windows [timeoutConnect:ip] windows ] diff --git a/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp b/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp index 7340817ade..f64a88cc05 100644 --- a/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp +++ b/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp @@ -1447,8 +1447,15 @@ void tst_QTcpSocket::disconnectWhileLookingUp() } // let anything queued happen + QEventLoop loop; - QTimer::singleShot(50, &loop, SLOT(quit())); + // If 'doClose' is false then we called '::waitForDisconnected' earlier, meaning + // we are already 'Unconnected'. So we don't need to wait for any potentially slow host lookups. + QTimer::singleShot(doClose ? 4000 : 50, &loop, SLOT(quit())); + connect(socket, &QTcpSocket::stateChanged, [&loop](QAbstractSocket::SocketState state) { + if (state == QAbstractSocket::UnconnectedState) + loop.exit(); // we don't need to wait for the timer to expire; we're done. + }); loop.exec(); // recheck -- cgit v1.2.3 From 5f66f871816d083da9795d71f746413d6f6118f7 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Sun, 26 Nov 2017 23:01:57 -0800 Subject: Stop depending on test.macieira.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We have had test.qt-project.org for close to 3 years now. Change-Id: I71488efd29b645f7b228fffd14fadf4627288243 Reviewed-by: Jędrzej Nowacki --- .../auto/network/kernel/qdnslookup_appless/tst_qdnslookup_appless.cpp | 4 ++-- tests/auto/network/kernel/qhostinfo/tst_qhostinfo.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'tests/auto/network') diff --git a/tests/auto/network/kernel/qdnslookup_appless/tst_qdnslookup_appless.cpp b/tests/auto/network/kernel/qdnslookup_appless/tst_qdnslookup_appless.cpp index 7874221da9..e302fe8c74 100644 --- a/tests/auto/network/kernel/qdnslookup_appless/tst_qdnslookup_appless.cpp +++ b/tests/auto/network/kernel/qdnslookup_appless/tst_qdnslookup_appless.cpp @@ -43,7 +43,7 @@ private slots: void tst_QDnsLookup_Appless::noApplication() { QTest::ignoreMessage(QtWarningMsg, "QDnsLookup requires a QCoreApplication"); - QDnsLookup dns(QDnsLookup::A, "a-single.test.macieira.org"); + QDnsLookup dns(QDnsLookup::A, "a-single.test.qt-project.org"); dns.lookup(); } @@ -53,7 +53,7 @@ void tst_QDnsLookup_Appless::recreateApplication() char **argv = 0; for (int i = 0; i < 10; ++i) { QCoreApplication app(argc, argv); - QDnsLookup dns(QDnsLookup::A, "a-single.test.macieira.org"); + QDnsLookup dns(QDnsLookup::A, "a-single.test.qt-project.org"); dns.lookup(); if (!dns.isFinished()) { QObject::connect(&dns, SIGNAL(finished()), diff --git a/tests/auto/network/kernel/qhostinfo/tst_qhostinfo.cpp b/tests/auto/network/kernel/qhostinfo/tst_qhostinfo.cpp index 2671c253cb..14bffaf7ca 100644 --- a/tests/auto/network/kernel/qhostinfo/tst_qhostinfo.cpp +++ b/tests/auto/network/kernel/qhostinfo/tst_qhostinfo.cpp @@ -76,7 +76,7 @@ #include "../../../network-settings.h" -#define TEST_DOMAIN ".test.macieira.org" +#define TEST_DOMAIN ".test.qt-project.org" class tst_QHostInfo : public QObject -- cgit v1.2.3