mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-20 20:40:29 +08:00
Unit tests, skip if DB is not reachable
This commit is contained in:
committed by
Roland Winklmeier
parent
efac4f1f27
commit
66bf45eb9c
@@ -12,6 +12,7 @@
|
|||||||
#ifndef BLACKCORE_DB_NETWORKWATCHDOG_H
|
#ifndef BLACKCORE_DB_NETWORKWATCHDOG_H
|
||||||
#define BLACKCORE_DB_NETWORKWATCHDOG_H
|
#define BLACKCORE_DB_NETWORKWATCHDOG_H
|
||||||
|
|
||||||
|
#include "blackcore/blackcoreexport.h"
|
||||||
#include "blackmisc/worker.h"
|
#include "blackmisc/worker.h"
|
||||||
#include "blackmisc/network/url.h"
|
#include "blackmisc/network/url.h"
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
@@ -23,7 +24,7 @@ namespace BlackCore
|
|||||||
namespace Db
|
namespace Db
|
||||||
{
|
{
|
||||||
//! Monitoring the swift DB, internet access, shared URLs
|
//! Monitoring the swift DB, internet access, shared URLs
|
||||||
class CNetworkWatchdog : public BlackMisc::CContinuousWorker
|
class BLACKCORE_EXPORT CNetworkWatchdog : public BlackMisc::CContinuousWorker
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
@@ -114,6 +115,11 @@ namespace BlackCore
|
|||||||
//! \remark depends on BlackCore::Application::getGlobalSetup()
|
//! \remark depends on BlackCore::Application::getGlobalSetup()
|
||||||
static bool isDbUrl(const BlackMisc::Network::CUrl &url);
|
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:
|
signals:
|
||||||
//! DB was available, but not longer is and vice versa
|
//! DB was available, but not longer is and vice versa
|
||||||
void changedSwiftDbAccessibility(bool available, const BlackMisc::Network::CUrl &url);
|
void changedSwiftDbAccessibility(bool available, const BlackMisc::Network::CUrl &url);
|
||||||
@@ -139,10 +145,6 @@ namespace BlackCore
|
|||||||
//! Received reply of client service ping
|
//! Received reply of client service ping
|
||||||
void replyPingClientService(QNetworkReply *nwReply);
|
void replyPingClientService(QNetworkReply *nwReply);
|
||||||
|
|
||||||
//! The URL being tested
|
|
||||||
//! \remark depends on BlackCore::Application::getGlobalSetup()
|
|
||||||
static BlackMisc::Network::CUrl dbTestUrl();
|
|
||||||
|
|
||||||
//! The DB server
|
//! The DB server
|
||||||
//! \remark depends on BlackCore::Application::getGlobalSetup()
|
//! \remark depends on BlackCore::Application::getGlobalSetup()
|
||||||
static QString dbHost();
|
static QString dbHost();
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
#include "testconnectivity.h"
|
#include "testconnectivity.h"
|
||||||
#include "blackcore/application.h"
|
#include "blackcore/application.h"
|
||||||
|
#include "blackcore/db/networkwatchdog.h"
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QTest>
|
#include <QTest>
|
||||||
@@ -20,6 +21,7 @@
|
|||||||
#include <QtDebug>
|
#include <QtDebug>
|
||||||
|
|
||||||
using namespace BlackCore;
|
using namespace BlackCore;
|
||||||
|
using namespace BlackCore::Db;
|
||||||
using namespace BlackMisc::Network;
|
using namespace BlackMisc::Network;
|
||||||
|
|
||||||
namespace BlackCoreTest
|
namespace BlackCoreTest
|
||||||
@@ -85,6 +87,12 @@ namespace BlackCoreTest
|
|||||||
void CTestConnectivity::testNetworkWatchdog()
|
void CTestConnectivity::testNetworkWatchdog()
|
||||||
{
|
{
|
||||||
QVERIFY2(sApp->getNetworkWatchdog(), "No network watchdog");
|
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->isSwiftDbAccessible(), "Watchdog cannot connect db", 20000);
|
||||||
QTRY_VERIFY2_WITH_TIMEOUT(sApp->getNetworkWatchdog()->getCheckCount() >= m_networkCheckCount + 1, "Timeout of network check", 30000);
|
QTRY_VERIFY2_WITH_TIMEOUT(sApp->getNetworkWatchdog()->getCheckCount() >= m_networkCheckCount + 1, "Timeout of network check", 30000);
|
||||||
qDebug() << "Current network check count:" << sApp->getNetworkWatchdog()->getCheckCount();
|
qDebug() << "Current network check count:" << sApp->getNetworkWatchdog()->getCheckCount();
|
||||||
|
|||||||
Reference in New Issue
Block a user