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 Pick-to: 6.2 Change-Id: I084f5d1268a5091ea614fcec91c8d356dcb90d9f Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
parent
c70bb357cc
commit
c7e0a1a966
@ -312,12 +312,15 @@ void tst_QSocks5SocketEngine::simpleConnectToIMAP()
|
|||||||
QCOMPARE(socketDevice.state(), QAbstractSocket::ConnectedState);
|
QCOMPARE(socketDevice.state(), QAbstractSocket::ConnectedState);
|
||||||
QCOMPARE(socketDevice.peerAddress(), QtNetworkSettings::imapServerIp());
|
QCOMPARE(socketDevice.peerAddress(), QtNetworkSettings::imapServerIp());
|
||||||
|
|
||||||
// Wait for the greeting
|
// Wait for the greeting, if it hasn't arrived yet
|
||||||
QVERIFY2(socketDevice.waitForRead(), qPrintable("Socket error:" + socketDevice.errorString()));
|
qint64 available = socketDevice.bytesAvailable();
|
||||||
|
if (available == 0) {
|
||||||
|
QVERIFY2(socketDevice.waitForRead(), qPrintable("Socket error:" + socketDevice.errorString()));
|
||||||
|
available = socketDevice.bytesAvailable();
|
||||||
|
}
|
||||||
|
QVERIFY(available > 0);
|
||||||
|
|
||||||
// Read the greeting
|
// Read the greeting
|
||||||
qint64 available = socketDevice.bytesAvailable();
|
|
||||||
QVERIFY(available > 0);
|
|
||||||
QByteArray array;
|
QByteArray array;
|
||||||
array.resize(available);
|
array.resize(available);
|
||||||
QVERIFY(socketDevice.read(array.data(), array.size()) == available);
|
QVERIFY(socketDevice.read(array.data(), array.size()) == available);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user