From e67f40ca183665f317aab36fabec9a44b5926b6c Mon Sep 17 00:00:00 2001 From: Martchus Date: Mon, 30 Jan 2023 15:19:08 +0100 Subject: [PATCH] Enable verbose logging for tests and dump Syncthing config at the end This is not very verbose but hopefully it'll help debugging test failures more easily. --- connector/syncthingconnection.cpp | 6 ++++++ widgets/CMakeLists.txt | 1 + widgets/tests/wizard.cpp | 10 ++++++++++ 3 files changed, 17 insertions(+) diff --git a/connector/syncthingconnection.cpp b/connector/syncthingconnection.cpp index 0550b74..2858c1d 100644 --- a/connector/syncthingconnection.cpp +++ b/connector/syncthingconnection.cpp @@ -958,6 +958,9 @@ void SyncthingConnection::setStatus(SyncthingStatus status) */ void SyncthingConnection::emitError(const QString &message, const QJsonParseError &jsonError, QNetworkReply *reply, const QByteArray &response) { + if (loggingFlags() & SyncthingConnectionLoggingFlags::ApiReplies) { + cerr << Phrases::Error << "JSON parsing error: " << message.toLocal8Bit().data() << jsonError.errorString().toLocal8Bit().data() << " (at offset " << jsonError.offset << ')' << endl; + } emit error(message % jsonError.errorString() % QChar(' ') % QChar('(') % tr("at offset %1").arg(jsonError.offset) % QChar(')'), SyncthingErrorCategory::Parsing, QNetworkReply::NoError, reply->request(), response); } @@ -967,6 +970,9 @@ void SyncthingConnection::emitError(const QString &message, const QJsonParseErro */ void SyncthingConnection::emitError(const QString &message, SyncthingErrorCategory category, QNetworkReply *reply) { + if (loggingFlags() & SyncthingConnectionLoggingFlags::ApiReplies) { + cerr << Phrases::Error << "Syncthing connection error: " << message.toLocal8Bit().data() << reply->errorString().toLocal8Bit().data() << endl; + } emit error(message + reply->errorString(), category, reply->error(), reply->request(), reply->bytesAvailable() ? reply->readAll() : QByteArray()); } diff --git a/widgets/CMakeLists.txt b/widgets/CMakeLists.txt index 6908789..95d91a2 100644 --- a/widgets/CMakeLists.txt +++ b/widgets/CMakeLists.txt @@ -157,5 +157,6 @@ foreach (TEST ${QT_TESTS}) # avoid running wizard tests in parallel with other tests spawning a Syncthing test instance if ("${TEST}" STREQUAL "wizard") set_tests_properties("${FULL_TEST_NAME_${TEST}}" PROPERTIES RESOURCE_LOCK "syncthingtestinstance") + set_tests_properties("${FULL_TEST_NAME_${TEST}}" PROPERTIES ENVIRONMENT "LIB_SYNCTHING_CONNECTOR_LOG_ALL=1") endif () endforeach () diff --git a/widgets/tests/wizard.cpp b/widgets/tests/wizard.cpp index 69e487e..036cd23 100644 --- a/widgets/tests/wizard.cpp +++ b/widgets/tests/wizard.cpp @@ -95,6 +95,10 @@ void WizardTests::initTestCase() void WizardTests::cleanupTestCase() { + auto syncthingConfig = QFile(m_homeDir.path() + QStringLiteral("/config.xml")); + qDebug() << "Syncthing config: "; + !syncthingConfig.open(QFile::ReadOnly) ? (qDebug() << "unable to open") : (qDebug().noquote() << syncthingConfig.readAll()); + if (m_launcher.isRunning()) { qDebug() << "terminating Syncthing"; m_launcher.terminate(); @@ -348,6 +352,12 @@ void WizardTests::testConfiguringCurrentlyRunningSyncthing() m_eventLoop.exec(); // configure external launcher + const auto &url = setupDetection.connection.syncthingUrl(); + const auto &apiKey = setupDetection.connection.apiKey(); + qDebug() << "configured URL: " << url; + qDebug() << "configured API key: " << apiKey; + QVERIFY(!url.isEmpty()); + QVERIFY(!apiKey.isEmpty()); auto *const mainConfigPage = qobject_cast(wizardDlg.currentPage()); QVERIFY(mainConfigPage != nullptr); QVERIFY(setupDetection.hasConfig());