Skip to content

Commit a8bcd0b

Browse files
committed
Pin every terminal state, not just the two being fixed
The seven states #4298 made terminal had no test. A future edit that drops one back to a bare log would only show up as a hung export in the field. The companion case covers the other direction: progress states must not decide the result on their own, or a response arriving after them would never be consulted.
1 parent 4dcfc60 commit a8bcd0b

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

‎exporters/elasticsearch/test/es_log_record_exporter_test.cc‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,48 @@ TEST(ElasticsearchLogsExporterSyncTests, ReadErrorEndsTheWait)
280280
EXPECT_EQ(result, opentelemetry::sdk::common::ExportResult::kFailure);
281281
}
282282

283+
// The whole contract in one place. Every state that ends a session has to leave a result behind,
284+
// otherwise a client that emits it last strands the wait. The seven states other than the two
285+
// this change adds have behaved this way since #4298 but had no test.
286+
//
287+
// A regression here surfaces as a CTest timeout rather than a failed assertion, because a state
288+
// that stops being terminal leaves Export() waiting with nothing left to wake it.
289+
TEST(ElasticsearchLogsExporterSyncTests, EveryTerminalStateEndsTheWaitInFailure)
290+
{
291+
SKIP_WITHOUT_SYNC_EXPORT();
292+
const http_client::SessionState terminal[] = {
293+
http_client::SessionState::CreateFailed, http_client::SessionState::ConnectFailed,
294+
http_client::SessionState::SendFailed, http_client::SessionState::SSLHandshakeFailed,
295+
http_client::SessionState::TimedOut, http_client::SessionState::NetworkError,
296+
http_client::SessionState::Cancelled, http_client::SessionState::ReadError,
297+
http_client::SessionState::WriteError, http_client::SessionState::Destroyed};
298+
299+
for (const auto state : terminal)
300+
{
301+
SCOPED_TRACE(static_cast<int>(state));
302+
const auto result =
303+
ExportWith([state](http_client::EventHandler &handler) { handler.OnEvent(state, ""); });
304+
EXPECT_EQ(result, opentelemetry::sdk::common::ExportResult::kFailure);
305+
}
306+
}
307+
308+
// The other side of the same contract: a state that only reports progress must not complete the
309+
// export on its own, or a response that arrives afterwards is never consulted.
310+
TEST(ElasticsearchLogsExporterSyncTests, ProgressStatesDoNotDecideTheResult)
311+
{
312+
SKIP_WITHOUT_SYNC_EXPORT();
313+
const auto result = ExportWith([](http_client::EventHandler &handler) {
314+
handler.OnEvent(http_client::SessionState::Created, "");
315+
handler.OnEvent(http_client::SessionState::Connecting, "");
316+
handler.OnEvent(http_client::SessionState::Connected, "");
317+
handler.OnEvent(http_client::SessionState::Sending, "");
318+
handler.OnEvent(http_client::SessionState::Response, "");
319+
FakeResponse response(200, kAcceptedBody);
320+
handler.OnResponse(response);
321+
});
322+
EXPECT_EQ(result, opentelemetry::sdk::common::ExportResult::kSuccess);
323+
}
324+
283325
TEST(ElasticsearchLogsExporterSyncTests, WriteErrorEndsTheWait)
284326
{
285327
SKIP_WITHOUT_SYNC_EXPORT();

0 commit comments

Comments
 (0)