diff options
author | Timur Pocheptsov <timur.pocheptsov@qt.io> | 2020-03-10 15:34:19 +0100 |
---|---|---|
committer | Timur Pocheptsov <timur.pocheptsov@qt.io> | 2020-03-12 02:27:04 +0100 |
commit | e9ae7cf31ff304150692d470ef914ec4d08c818e (patch) | |
tree | 3c9c69421e162e847289967307a5c2f5effa7e6d /tests | |
parent | cf925913486f83d2556308d2f9e545a36abb6fa4 (diff) |
TCP socket auto-test: reduce flakyness
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 <timur.pocheptsov@qt.io>
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp | 17 |
1 files changed, 13 insertions, 4 deletions
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 <QNetworkProxy> +#include <memory> + #include <time.h> #ifdef Q_OS_LINUX #include <stdio.h> @@ -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<QTcpSocket> 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 |