mirror of
https://github.com/Icinga/icinga2.git
synced 2026-02-03 20:40:17 -05:00
There's a set of two tests for each perfdatawriter, just to make sure they can connect and send data that looks reasonably correct, and to make sure pausing actually works while the connection is stuck. Then there's a more in-depth suite of tests for PerfdataWriterConnection itself, to verify that connection handling works well in all types of scenarios.
53 lines
1.4 KiB
C++
53 lines
1.4 KiB
C++
/* Icinga 2 | (c) 2025 Icinga GmbH | GPLv2+ */
|
|
|
|
#include <BoostTestTargetConfig.h>
|
|
#include "perfdata/elasticsearchwriter.hpp"
|
|
#include "test/base-testloggerfixture.hpp"
|
|
#include "test/perfdata-perfdatawriterfixture.hpp"
|
|
#include "test/utils.hpp"
|
|
|
|
using namespace icinga;
|
|
|
|
BOOST_FIXTURE_TEST_SUITE(perfdata_elasticsearchwriter, PerfdataWriterFixture<ElasticsearchWriter>,
|
|
*boost::unit_test::label("perfdata"))
|
|
|
|
BOOST_AUTO_TEST_CASE(connect)
|
|
{
|
|
ResumeWriter();
|
|
|
|
ReceiveCheckResults(1, ServiceState::ServiceCritical);
|
|
|
|
Accept();
|
|
auto resp = GetSplitDecodedRequestBody();
|
|
SendResponse();
|
|
|
|
// Just some basic sanity tests. It's not important to check if everything is entirely
|
|
// correct here.
|
|
BOOST_REQUIRE_GT(resp->GetLength(), 1);
|
|
Dictionary::Ptr cr = resp->Get(1);
|
|
BOOST_CHECK(cr->Contains("@timestamp"));
|
|
BOOST_CHECK_EQUAL(cr->Get("check_command"), "dummy");
|
|
BOOST_CHECK_EQUAL(cr->Get("host"), "h1");
|
|
PauseWriter();
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(pause_with_pending_work)
|
|
{
|
|
ResumeWriter();
|
|
|
|
ReceiveCheckResults(1, ServiceState::ServiceCritical, [](const CheckResult::Ptr& cr) {
|
|
cr->SetOutput(GetRandomString("####", 1024UL * 1024));
|
|
});
|
|
|
|
// Accept the connection, but don't read from it to leave the client hanging.
|
|
Accept();
|
|
GetDataUntil("####");
|
|
|
|
// Now try to pause.
|
|
PauseWriter();
|
|
|
|
REQUIRE_LOG_MESSAGE("Operation cancelled\\.", 10s);
|
|
REQUIRE_LOG_MESSAGE("'ElasticsearchWriter' paused\\.", 10s);
|
|
}
|
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|