diff options
author | Dimitrios Apostolou <jimis@qt.io> | 2021-09-17 12:32:14 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-09-17 16:16:36 +0000 |
commit | 03224fa6de9a606b828ae1c6698124f6cea4fe7d (patch) | |
tree | 4a8d08f880e0f85fc28b22512d47ee9379bc5351 /tests | |
parent | c492bda966ebb0b4966de2fd592e95001054ba42 (diff) |
Fix flaky test timing out sometimes while waiting for data
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
Change-Id: I084f5d1268a5091ea614fcec91c8d356dcb90d9f
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
(cherry picked from commit c7e0a1a966c143485eb32211aaabf62cd8dbf6ca)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/network/socket/qsocks5socketengine/tst_qsocks5socketengine.cpp | 11 |
1 files 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 f0cff5da3e..97213ae65f 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())); - - // Read the greeting + // 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 QByteArray array; array.resize(available); QVERIFY(socketDevice.read(array.data(), array.size()) == available); |