From c7e0a1a966c143485eb32211aaabf62cd8dbf6ca Mon Sep 17 00:00:00 2001 From: Dimitrios Apostolou Date: Fri, 17 Sep 2021 12:32:14 +0200 Subject: [PATCH] Fix flaky test timing out sometimes while waiting for data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The test used to hang on waitForRead(), sometimes, which underneath involve a poll()+read() syscall pair. When this happened, the IMAP data came together with the proxy data on a previous poll()+read() call and the proxy code had already consumed it. We now wait for data only if data is not already available. Fixes: QTBUG-96345 Pick-to: 6.2 Change-Id: I084f5d1268a5091ea614fcec91c8d356dcb90d9f Reviewed-by: MÃ¥rten Nordheim --- .../qsocks5socketengine/tst_qsocks5socketengine.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/auto/network/socket/qsocks5socketengine/tst_qsocks5socketengine.cpp b/tests/auto/network/socket/qsocks5socketengine/tst_qsocks5socketengine.cpp index 7bf057cd5a..11e17cb319 100644 --- a/tests/auto/network/socket/qsocks5socketengine/tst_qsocks5socketengine.cpp +++ b/tests/auto/network/socket/qsocks5socketengine/tst_qsocks5socketengine.cpp @@ -312,12 +312,15 @@ void tst_QSocks5SocketEngine::simpleConnectToIMAP() QCOMPARE(socketDevice.state(), QAbstractSocket::ConnectedState); QCOMPARE(socketDevice.peerAddress(), QtNetworkSettings::imapServerIp()); - // Wait for the greeting - QVERIFY2(socketDevice.waitForRead(), qPrintable("Socket error:" + socketDevice.errorString())); + // Wait for the greeting, if it hasn't arrived yet + qint64 available = socketDevice.bytesAvailable(); + if (available == 0) { + QVERIFY2(socketDevice.waitForRead(), qPrintable("Socket error:" + socketDevice.errorString())); + available = socketDevice.bytesAvailable(); + } + QVERIFY(available > 0); // Read the greeting - qint64 available = socketDevice.bytesAvailable(); - QVERIFY(available > 0); QByteArray array; array.resize(available); QVERIFY(socketDevice.read(array.data(), array.size()) == available);