From e9ae7cf31ff304150692d470ef914ec4d08c818e Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Tue, 10 Mar 2020 15:34:19 +0100 Subject: TCP socket auto-test: reduce flakyness MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit increaseReadBufferSize has several cases, surprisingly, subsequent runs can be affected by close notification from the previous tests, and then they ... break the expected logic test (by resetting read buffer size and trying to read as much as possible). Ah, and as it often happens with our auto-test - a client socket leaked if some of COMPARE/VERIFY failed. unique_ptr to rescue. Fixes: QTBUG-82776 Change-Id: I9dc79072fdefc08417274dc341b88fca70c54dae Reviewed-by: Timur Pocheptsov Reviewed-by: MÃ¥rten Nordheim --- tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp b/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp index 10b09629bc..d477c2f112 100644 --- a/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp +++ b/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp @@ -72,6 +72,8 @@ // RVCT compiles also unused inline methods # include +#include + #include #ifdef Q_OS_LINUX #include @@ -2587,12 +2589,21 @@ void tst_QTcpSocket::moveToThread0() void tst_QTcpSocket::increaseReadBufferSize() { +#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) + // Let's make sure we don't have close notify events + // unprocessed from the previous run of the same test, + // may happen that the server socket's descriptor gets + // reused by a client here and ... surprise! The buffer + // limit set to 256, but we read 512 (since closeNotify + // tries to read whatever we got, unsetting read limit). + QCoreApplication::processEvents(); +#endif // Q_OS_WIN QFETCH_GLOBAL(bool, setProxy); if (setProxy) return; //proxy not useful for localhost test case QTcpServer server; - QTcpSocket *active = newSocket(); - connect(active, SIGNAL(readyRead()), SLOT(exitLoopSlot())); + std::unique_ptr active(newSocket()); + connect(active.get(), SIGNAL(readyRead()), SLOT(exitLoopSlot())); // connect two sockets to each other: QVERIFY(server.listen(QHostAddress::LocalHost)); @@ -2641,8 +2652,6 @@ void tst_QTcpSocket::increaseReadBufferSize() QVERIFY2(!timeout(), "Network timeout"); QCOMPARE(active->bytesAvailable(), qint64(data.size())); QCOMPARE(active->readAll(), data); - - delete active; } void tst_QTcpSocket::increaseReadBufferSizeFromSlot() // like KIO's socketconnectionbackend -- cgit v1.2.3