From 66bf45eb9cd419b19f942ef6ba278e674a97e70f Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sat, 14 Apr 2018 06:43:01 +0200 Subject: [PATCH] Unit tests, skip if DB is not reachable --- src/blackcore/db/networkwatchdog.h | 12 +++++++----- tests/blackcore/testconnectivity.cpp | 8 ++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/blackcore/db/networkwatchdog.h b/src/blackcore/db/networkwatchdog.h index e07d4a03c..01a0a5e15 100644 --- a/src/blackcore/db/networkwatchdog.h +++ b/src/blackcore/db/networkwatchdog.h @@ -12,6 +12,7 @@ #ifndef BLACKCORE_DB_NETWORKWATCHDOG_H #define BLACKCORE_DB_NETWORKWATCHDOG_H +#include "blackcore/blackcoreexport.h" #include "blackmisc/worker.h" #include "blackmisc/network/url.h" #include @@ -23,7 +24,7 @@ namespace BlackCore namespace Db { //! Monitoring the swift DB, internet access, shared URLs - class CNetworkWatchdog : public BlackMisc::CContinuousWorker + class BLACKCORE_EXPORT CNetworkWatchdog : public BlackMisc::CContinuousWorker { Q_OBJECT @@ -114,6 +115,11 @@ namespace BlackCore //! \remark depends on BlackCore::Application::getGlobalSetup() static bool isDbUrl(const BlackMisc::Network::CUrl &url); + //! The URL being tested + //! \remark depends on BlackCore::Application::getGlobalSetup() + //! \private primarily accessible for unit tests + static BlackMisc::Network::CUrl dbTestUrl(); + signals: //! DB was available, but not longer is and vice versa void changedSwiftDbAccessibility(bool available, const BlackMisc::Network::CUrl &url); @@ -139,10 +145,6 @@ namespace BlackCore //! Received reply of client service ping void replyPingClientService(QNetworkReply *nwReply); - //! The URL being tested - //! \remark depends on BlackCore::Application::getGlobalSetup() - static BlackMisc::Network::CUrl dbTestUrl(); - //! The DB server //! \remark depends on BlackCore::Application::getGlobalSetup() static QString dbHost(); diff --git a/tests/blackcore/testconnectivity.cpp b/tests/blackcore/testconnectivity.cpp index d075c869b..85f7b0c06 100644 --- a/tests/blackcore/testconnectivity.cpp +++ b/tests/blackcore/testconnectivity.cpp @@ -13,6 +13,7 @@ #include "testconnectivity.h" #include "blackcore/application.h" +#include "blackcore/db/networkwatchdog.h" #include #include #include @@ -20,6 +21,7 @@ #include using namespace BlackCore; +using namespace BlackCore::Db; using namespace BlackMisc::Network; namespace BlackCoreTest @@ -85,6 +87,12 @@ namespace BlackCoreTest void CTestConnectivity::testNetworkWatchdog() { QVERIFY2(sApp->getNetworkWatchdog(), "No network watchdog"); + const CUrl dbUrl = CNetworkWatchdog::dbTestUrl(); + qDebug() << "Using DB test URL: " << dbUrl.toQString(); + const bool ok = CNetworkUtils::canPing(dbUrl); + if (!ok) { QSKIP(qPrintable("Cannot ping " + dbUrl.getFullUrl())); } + + // only if URL is reachable QTRY_VERIFY2_WITH_TIMEOUT(sApp->isSwiftDbAccessible(), "Watchdog cannot connect db", 20000); QTRY_VERIFY2_WITH_TIMEOUT(sApp->getNetworkWatchdog()->getCheckCount() >= m_networkCheckCount + 1, "Timeout of network check", 30000); qDebug() << "Current network check count:" << sApp->getNetworkWatchdog()->getCheckCount();