mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 14:55:36 +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
|
||||
#define BLACKCORE_DB_NETWORKWATCHDOG_H
|
||||
|
||||
#include "blackcore/blackcoreexport.h"
|
||||
#include "blackmisc/worker.h"
|
||||
#include "blackmisc/network/url.h"
|
||||
#include <atomic>
|
||||
@@ -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();
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
#include "testconnectivity.h"
|
||||
#include "blackcore/application.h"
|
||||
#include "blackcore/db/networkwatchdog.h"
|
||||
#include <QDateTime>
|
||||
#include <QDebug>
|
||||
#include <QTest>
|
||||
@@ -20,6 +21,7 @@
|
||||
#include <QtDebug>
|
||||
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user