|
| 1 | +// SPDX-FileCopyrightText: 2026 Icinga GmbH <https://icinga.com> |
| 2 | +// SPDX-License-Identifier: GPL-3.0-or-later |
| 3 | + |
| 4 | +#include <BoostTestTargetConfig.h> |
| 5 | +#include "base/perfdatavalue.hpp" |
| 6 | +#include "perfdata/opentsdbwriter.hpp" |
| 7 | +#include "test/base-testloggerfixture.hpp" |
| 8 | +#include "test/perfdata-perfdatawriterfixture.hpp" |
| 9 | +#include "test/utils.hpp" |
| 10 | + |
| 11 | +using namespace icinga; |
| 12 | + |
| 13 | +BOOST_FIXTURE_TEST_SUITE(perfdata_opentsdbwriter, PerfdataWriterFixture<OpenTsdbWriter>, |
| 14 | + *boost::unit_test::label("perfdata") |
| 15 | + *boost::unit_test::label("network") |
| 16 | +) |
| 17 | + |
| 18 | +BOOST_AUTO_TEST_CASE(connect) |
| 19 | +{ |
| 20 | + ResumeWriter(); |
| 21 | + |
| 22 | + ReceiveCheckResults(1, ServiceState::ServiceCritical); |
| 23 | + |
| 24 | + Accept(); |
| 25 | + auto msg = GetDataUntil('\n'); |
| 26 | + std::vector<std::string> splitMsg; |
| 27 | + boost::split(splitMsg, msg, boost::is_any_of(" ")); |
| 28 | + |
| 29 | + // Just some basic sanity tests. It's not important to check if everything is entirely correct here. |
| 30 | + BOOST_REQUIRE_EQUAL(splitMsg.size(), 5); |
| 31 | + BOOST_REQUIRE_EQUAL(splitMsg[0], "put"); |
| 32 | + BOOST_REQUIRE_EQUAL(splitMsg[1], "icinga.host.state"); |
| 33 | + BOOST_REQUIRE_CLOSE(boost::lexical_cast<double>(splitMsg[2]), Utility::GetTime(), 1); |
| 34 | + BOOST_REQUIRE_EQUAL(splitMsg[3], "1"); |
| 35 | + BOOST_REQUIRE_EQUAL(splitMsg[4], "host=h1"); |
| 36 | + PauseWriter(); |
| 37 | +} |
| 38 | + |
| 39 | +BOOST_AUTO_TEST_CASE(pause_with_pending_work) |
| 40 | +{ |
| 41 | + ResumeWriter(); |
| 42 | + |
| 43 | + // Process check-results until the writer is stuck. |
| 44 | + BOOST_REQUIRE_MESSAGE(GetWriterStuck(10s), "Failed to get Writer stuck."); |
| 45 | + |
| 46 | + // Now stop reading and try to pause OpenTsdbWriter. |
| 47 | + PauseWriter(); |
| 48 | + |
| 49 | + REQUIRE_LOG_MESSAGE("Connection stopped\\.", 10s); |
| 50 | + REQUIRE_LOG_MESSAGE("'OpenTsdbWriter' paused\\.", 10s); |
| 51 | +} |
| 52 | + |
| 53 | +BOOST_AUTO_TEST_SUITE_END() |
0 commit comments