tst_QTcpSocket: stabilize connectToHostError
It's not _wrong_ to time out when connecting to something unreachable (it's just a different way of handling it) so we shouldn't fail when this happens either. In local testing (windows) it times out after 8 seconds, so bump the timer to 10 seconds. On systems where it's faster there'll be no difference as long as things don't go wrong. Fixes: QTBUG-88042 Fixes: QTBUG-89089 Change-Id: I8437cf8e4fbecedea2391ed87fdce1213085b964 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io> (cherry picked from commit 27f52942b422b47a1283d918e0a0bc8761382921) (cherry picked from commit 4111d8e8e789c815ae37eb9903b042124e169078)
This commit is contained in:
parent
953d70c2a3
commit
9f03c9304f
@ -2,7 +2,6 @@
|
|||||||
windows
|
windows
|
||||||
[connectToHostError]
|
[connectToHostError]
|
||||||
windows-10 gcc developer-build
|
windows-10 gcc developer-build
|
||||||
ubuntu-20.04
|
|
||||||
# QTBUG-66247
|
# QTBUG-66247
|
||||||
[delayedClose:WithSocks5Proxy]
|
[delayedClose:WithSocks5Proxy]
|
||||||
windows-10 gcc developer-build
|
windows-10 gcc developer-build
|
||||||
|
@ -2090,31 +2090,50 @@ void tst_QTcpSocket::nestedEventLoopInErrorSlot()
|
|||||||
void tst_QTcpSocket::connectToHostError_data()
|
void tst_QTcpSocket::connectToHostError_data()
|
||||||
{
|
{
|
||||||
QTest::addColumn<QString>("host");
|
QTest::addColumn<QString>("host");
|
||||||
QTest::addColumn<int>("port");
|
QTest::addColumn<quint16>("port");
|
||||||
QTest::addColumn<QAbstractSocket::SocketError>("expectedError");
|
QTest::addColumn<QAbstractSocket::SocketError>("expectedError");
|
||||||
|
|
||||||
QTest::newRow("localhost no service") << QStringLiteral("localhost") << 31415 << QAbstractSocket::ConnectionRefusedError;
|
QTest::newRow("localhost no service") << QStringLiteral("localhost") << quint16(31415) << QAbstractSocket::ConnectionRefusedError;
|
||||||
QTest::newRow("unreachable") << QStringLiteral("0.0.0.1") << 65000 << QAbstractSocket::NetworkError;
|
QTest::newRow("unreachable") << QStringLiteral("0.0.0.1") << quint16(65000) << QAbstractSocket::NetworkError;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void tst_QTcpSocket::connectToHostError()
|
void tst_QTcpSocket::connectToHostError()
|
||||||
{
|
{
|
||||||
|
// We are aware of at least one OS in our CI, that would fail
|
||||||
|
// the test due to timeout - it's Ubuntu 20.04 and 'connect'
|
||||||
|
// to 0.0.0.1 there return EINPROGRESS, with no other error
|
||||||
|
// ever received, so only our own internal 30 s. timer can
|
||||||
|
// detect a connection timeout.
|
||||||
|
|
||||||
std::unique_ptr<QTcpSocket> socket(newSocket());
|
std::unique_ptr<QTcpSocket> socket(newSocket());
|
||||||
|
|
||||||
QAbstractSocket::SocketError error = QAbstractSocket::UnknownSocketError;
|
QAbstractSocket::SocketError error = QAbstractSocket::UnknownSocketError;
|
||||||
|
|
||||||
QFETCH(QString, host);
|
QFETCH(const QString, host);
|
||||||
QFETCH(int, port);
|
QFETCH(const quint16, port);
|
||||||
QFETCH(QAbstractSocket::SocketError, expectedError);
|
QFETCH(QAbstractSocket::SocketError, expectedError);
|
||||||
|
|
||||||
connect(socket.get(), &QAbstractSocket::errorOccurred, [&](QAbstractSocket::SocketError socketError){
|
QTestEventLoop eventLoop;
|
||||||
|
connect(socket.get(), &QAbstractSocket::errorOccurred, socket.get(),
|
||||||
|
[&](QAbstractSocket::SocketError socketError) {
|
||||||
error = socketError;
|
error = socketError;
|
||||||
|
QTimer::singleShot(0, &eventLoop, [&]{eventLoop.exitLoop();});
|
||||||
});
|
});
|
||||||
socket->connectToHost(host, port); // no service running here, one suspects
|
|
||||||
QTRY_COMPARE_WITH_TIMEOUT(socket->state(), QTcpSocket::UnconnectedState, 7000);
|
socket->connectToHost(host, port);
|
||||||
|
eventLoop.enterLoopMSecs(10'000);
|
||||||
|
if (eventLoop.timeout()) {
|
||||||
|
// Let's at least verify it's not in connected state:
|
||||||
|
QVERIFY(socket->state() != QAbstractSocket::ConnectedState);
|
||||||
|
QSKIP("Connection to unreachable host timed out, skipping the rest of the test");
|
||||||
|
}
|
||||||
|
|
||||||
|
QCOMPARE(socket->state(), QTcpSocket::UnconnectedState);
|
||||||
|
|
||||||
if (error != expectedError && error == QAbstractSocket::ConnectionRefusedError)
|
if (error != expectedError && error == QAbstractSocket::ConnectionRefusedError)
|
||||||
QEXPECT_FAIL("unreachable", "CI firewall interfers with this test", Continue);
|
QEXPECT_FAIL("unreachable", "CI firewall interfers with this test", Continue);
|
||||||
|
|
||||||
QCOMPARE(error, expectedError);
|
QCOMPARE(error, expectedError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user