Changes
diff --git a/src/scheduler.cpp b/src/scheduler.cpp
index aa97957..d73e68a 100644
--- a/src/scheduler.cpp
+++ b/src/scheduler.cpp
@@ -263,8 +263,8 @@ void Scheduler::execute(Task& task)
reportError(service_id, std::move(result.error()));
return;
}
- spdlog::info("Probe for service {} returned {}", service_id,
- probeStatusName(result->status));
+ spdlog::debug("Probe for service {} returned {}", service_id,
+ probeStatusName(result->status));
auto saved = data_source.save({service_id, result->timestamp,
result->duration_microsecond, result->status});
if(!saved)
diff --git a/src/service.cpp b/src/service.cpp
index 9673047..de05742 100644
--- a/src/service.cpp
+++ b/src/service.cpp
@@ -13,7 +13,8 @@ struct ProbeFactory
{
if(endpoint.url.empty() && url)
{
- return ::createProbe(HttpEndpoint{*url}, timeout);
+ return ::createProbe(
+ HttpEndpoint{*url, endpoint.expected_code}, timeout);
}
return ::createProbe(endpoint, timeout);
}
diff --git a/tests/probe_test.cpp b/tests/probe_test.cpp
index ff914b0..fdc8d4b 100644
--- a/tests/probe_test.cpp
+++ b/tests/probe_test.cpp
@@ -1,4 +1,5 @@
#include "probe.h"
+#include "service.h"
#include <array>
#include <cerrno>
@@ -324,6 +325,21 @@ TEST_F(ProbeTest, HttpExpectedStatusCode)
worker.join();
}
+TEST_F(ProbeTest, ServiceHttpFallbackPreservesExpectedStatusCode)
+{
+ ASSERT_TRUE(bindServer(SOCK_STREAM, AF_INET, true));
+ worker = std::jthread(&ProbeTest::serveHttp, this, 401, false);
+ Service service{{
+ "forum", "Forum", "", HttpEndpoint{"", 401}, 1s, 1min,
+ "http://127.0.0.1:" + std::to_string(port)}};
+ auto result_probe = service.createProbe();
+ ASSERT_TRUE(result_probe) << result_probe.error().msg();
+ auto result = (*result_probe)->probe();
+ ASSERT_TRUE(result) << result.error().msg();
+ EXPECT_EQ(result->status, ProbeStatus::GOOD);
+ worker.join();
+}
+
TEST_F(ProbeTest, HttpTimeout)
{
ASSERT_TRUE(bindServer(SOCK_STREAM, AF_INET, true));