Skip instead of fail tests when test server is not available

We were being inconsistent in how we handled this, some tests skipping
while others using QVERIFY. It makes more sense to skip the tests, since
the problem is a missing pre-condition of the test, not the test itself
being bad or exposing real failures in the implementation.

Change-Id: I20eacfe12dbce0b0d926e48cbe2d2772819fa4a5
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
This commit is contained in:
Tor Arne Vestbø 2020-01-13 16:47:15 +01:00
parent 9dcbf2cf5c
commit eb2a7738a4
18 changed files with 92 additions and 15 deletions

View File

@ -215,7 +215,8 @@ void tst_QFtp::initTestCase()
QVERIFY(QtNetworkSettings::verifyConnection(QtNetworkSettings::socksProxyServerName(), 1080));
QVERIFY(QtNetworkSettings::verifyConnection(QtNetworkSettings::httpProxyServerName(), 3128));
#else
QVERIFY(QtNetworkSettings::verifyTestNetworkSettings());
if (!QtNetworkSettings::verifyTestNetworkSettings())
QSKIP("No network test server available");
#endif
#ifndef QT_NO_BEARERMANAGEMENT
QNetworkConfigurationManager manager;

View File

@ -105,7 +105,8 @@ void tst_QHttpNetworkConnection::initTestCase()
#if defined(QT_TEST_SERVER)
QVERIFY(QtNetworkSettings::verifyConnection(httpServerName(), 80));
#else
QVERIFY(QtNetworkSettings::verifyTestNetworkSettings());
if (!QtNetworkSettings::verifyTestNetworkSettings())
QSKIP("No network test server available");
#endif
}

View File

@ -100,7 +100,8 @@ tst_Spdy::~tst_Spdy()
void tst_Spdy::initTestCase()
{
QVERIFY(!m_rfc3252FilePath.isEmpty());
QVERIFY(QtNetworkSettings::verifyTestNetworkSettings());
if (!QtNetworkSettings::verifyTestNetworkSettings())
QSKIP("No network test server available");
}
void tst_Spdy::settingsAndNegotiation_data()

View File

@ -1,5 +1,6 @@
TEMPLATE=subdirs
SUBDIRS=\
selftest \
access \
bearer \
kernel \

View File

@ -0,0 +1,6 @@
CONFIG += testcase
TARGET = tst_networkselftest
SOURCES += tst_networkselftest.cpp
requires(qtConfig(private_tests))
QT = core network network-private testlib

View File

@ -0,0 +1,55 @@
/****************************************************************************
**
** Copyright (C) 2020 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include <QtTest/QtTest>
#include "../../network-settings.h"
class tst_NetworkSelftest : public QObject
{
Q_OBJECT
private slots:
void testServerIsAvailableInCI();
};
void tst_NetworkSelftest::testServerIsAvailableInCI()
{
if (!qEnvironmentVariable("QTEST_ENVIRONMENT").split(' ').contains("ci"))
QSKIP("Not running in the CI");
#if !defined(QT_TEST_SERVER)
QVERIFY2(QtNetworkSettings::verifyTestNetworkSettings(),
"Test server must be available when running in the CI");
#endif
}
QTEST_MAIN(tst_NetworkSelftest)
#include "tst_networkselftest.moc"

View File

@ -87,7 +87,8 @@ private slots:
void tst_PlatformSocketEngine::initTestCase()
{
QVERIFY(QtNetworkSettings::verifyTestNetworkSettings());
if (!QtNetworkSettings::verifyTestNetworkSettings())
QSKIP("No network test server available");
}
//---------------------------------------------------------------------------

View File

@ -129,7 +129,8 @@ void tst_QHttpSocketEngine::initTestCase()
QVERIFY(QtNetworkSettings::verifyConnection(QtNetworkSettings::httpServerName(), 80));
QVERIFY(QtNetworkSettings::verifyConnection(QtNetworkSettings::imapServerName(), 143));
#else
QVERIFY(QtNetworkSettings::verifyTestNetworkSettings());
if (!QtNetworkSettings::verifyTestNetworkSettings())
QSKIP("No network test server available");
#endif
}

View File

@ -142,7 +142,8 @@ void tst_QSocks5SocketEngine::initTestCase()
QVERIFY(QtNetworkSettings::verifyConnection(QtNetworkSettings::httpServerName(), 80));
QVERIFY(QtNetworkSettings::verifyConnection(QtNetworkSettings::imapServerName(), 143));
#else
QVERIFY(QtNetworkSettings::verifyTestNetworkSettings());
if (!QtNetworkSettings::verifyTestNetworkSettings())
QSKIP("No network test server available");
#endif
}

View File

@ -358,7 +358,8 @@ void tst_QTcpSocket::initTestCase()
QVERIFY(QtNetworkSettings::verifyConnection(QtNetworkSettings::ftpServerName(), 21));
QVERIFY(QtNetworkSettings::verifyConnection(QtNetworkSettings::ftpProxyServerName(), 2121));
#else
QVERIFY(QtNetworkSettings::verifyTestNetworkSettings());
if (!QtNetworkSettings::verifyTestNetworkSettings())
QSKIP("No network test server available");
#endif
}

View File

@ -391,7 +391,8 @@ void tst_QSslSocket::initTestCase()
QVERIFY(QtNetworkSettings::verifyConnection(QtNetworkSettings::imapServerName(), 993));
QVERIFY(QtNetworkSettings::verifyConnection(QtNetworkSettings::echoServerName(), 13));
#else
QVERIFY(QtNetworkSettings::verifyTestNetworkSettings());
if (!QtNetworkSettings::verifyTestNetworkSettings())
QSKIP("No network test server available");
#endif // QT_TEST_SERVER
#endif // QT_NO_SSL
}

View File

@ -109,7 +109,8 @@ void tst_QSslSocket_onDemandCertificates_member::initTestCase()
QVERIFY(QtNetworkSettings::verifyConnection(QtNetworkSettings::httpProxyServerName(), 3129));
QVERIFY(QtNetworkSettings::verifyConnection(QtNetworkSettings::httpProxyServerName(), 3130));
#else
QVERIFY(QtNetworkSettings::verifyTestNetworkSettings());
if (!QtNetworkSettings::verifyTestNetworkSettings())
QSKIP("No network test server available");
#endif // QT_TEST_SERVER
}

View File

@ -105,7 +105,8 @@ void tst_QSslSocket_onDemandCertificates_static::initTestCase()
QVERIFY(QtNetworkSettings::verifyConnection(QtNetworkSettings::httpProxyServerName(), 3129));
QVERIFY(QtNetworkSettings::verifyConnection(QtNetworkSettings::httpProxyServerName(), 3130));
#else
QVERIFY(QtNetworkSettings::verifyTestNetworkSettings());
if (!QtNetworkSettings::verifyTestNetworkSettings())
QSKIP("No network test server available");
#endif // QT_TEST_SERVER
}

View File

@ -479,7 +479,8 @@ private:
void tst_qnetworkreply::initTestCase()
{
QVERIFY(QtNetworkSettings::verifyTestNetworkSettings());
if (!QtNetworkSettings::verifyTestNetworkSettings())
QSKIP("No network test server available");
}
void tst_qnetworkreply::httpLatency()

View File

@ -81,7 +81,8 @@ void tst_QTcpServer::initTestCase_data()
void tst_QTcpServer::initTestCase()
{
QVERIFY(QtNetworkSettings::verifyTestNetworkSettings());
if (!QtNetworkSettings::verifyTestNetworkSettings())
QSKIP("No network test server available");
}
void tst_QTcpServer::init()

View File

@ -63,7 +63,8 @@ tst_QSslSocket::~tst_QSslSocket()
void tst_QSslSocket::initTestCase()
{
QVERIFY(QtNetworkSettings::verifyTestNetworkSettings());
if (!QtNetworkSettings::verifyTestNetworkSettings())
QSKIP("No network test server available");
}
void tst_QSslSocket::init()

View File

@ -123,7 +123,8 @@ void tst_NetworkStressTest::initTestCase_data()
void tst_NetworkStressTest::initTestCase()
{
QVERIFY(QtNetworkSettings::verifyTestNetworkSettings());
if (!QtNetworkSettings::verifyTestNetworkSettings())
QSKIP("No network test server available");
}
void tst_NetworkStressTest::init()

View File

@ -108,7 +108,8 @@ protected:
void tst_qnetworkreply::initTestCase()
{
qRegisterMetaType<QNetworkReply *>(); // for QSignalSpy
QVERIFY(QtNetworkSettings::verifyTestNetworkSettings());
if (!QtNetworkSettings::verifyTestNetworkSettings())
QSKIP("No network test server available");
}
void tst_qnetworkreply::limiting_data()