summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorTimur Pocheptsov <timur.pocheptsov@qt.io>2020-11-16 19:23:53 +0100
committerMÃ¥rten Nordheim <marten.nordheim@qt.io>2020-12-07 15:33:59 +0100
commit9f03c9304f85ff48620062c191d71e7700b49a2f (patch)
tree192a2f2a68f05481108318079a491f0bc96bc7af /tests
parent953d70c2a368aa5c48558fc9dddd4d7e24da0e45 (diff)
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)
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/network/socket/qtcpsocket/BLACKLIST1
-rw-r--r--tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp35
2 files changed, 27 insertions, 9 deletions
diff --git a/tests/auto/network/socket/qtcpsocket/BLACKLIST b/tests/auto/network/socket/qtcpsocket/BLACKLIST
index 95e3e63977..ac243c0203 100644
--- a/tests/auto/network/socket/qtcpsocket/BLACKLIST
+++ b/tests/auto/network/socket/qtcpsocket/BLACKLIST
@@ -2,7 +2,6 @@
windows
[connectToHostError]
windows-10 gcc developer-build
-ubuntu-20.04
# QTBUG-66247
[delayedClose:WithSocks5Proxy]
windows-10 gcc developer-build
diff --git a/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp b/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp
index 0608fa8e63..a141d08338 100644
--- a/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp
+++ b/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp
@@ -2090,31 +2090,50 @@ void tst_QTcpSocket::nestedEventLoopInErrorSlot()
void tst_QTcpSocket::connectToHostError_data()
{
QTest::addColumn<QString>("host");
- QTest::addColumn<int>("port");
+ QTest::addColumn<quint16>("port");
QTest::addColumn<QAbstractSocket::SocketError>("expectedError");
- QTest::newRow("localhost no service") << QStringLiteral("localhost") << 31415 << QAbstractSocket::ConnectionRefusedError;
- QTest::newRow("unreachable") << QStringLiteral("0.0.0.1") << 65000 << QAbstractSocket::NetworkError;
+ QTest::newRow("localhost no service") << QStringLiteral("localhost") << quint16(31415) << QAbstractSocket::ConnectionRefusedError;
+ QTest::newRow("unreachable") << QStringLiteral("0.0.0.1") << quint16(65000) << QAbstractSocket::NetworkError;
}
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());
QAbstractSocket::SocketError error = QAbstractSocket::UnknownSocketError;
- QFETCH(QString, host);
- QFETCH(int, port);
+ QFETCH(const QString, host);
+ QFETCH(const quint16, port);
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;
+ 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)
QEXPECT_FAIL("unreachable", "CI firewall interfers with this test", Continue);
+
QCOMPARE(error, expectedError);
}