From cd3a73ef14bf882cb9b93cf6c0e8c1fe7ea2a996 Mon Sep 17 00:00:00 2001 From: Rodrigo Pastrana Date: Wed, 8 Nov 2023 07:40:09 -0500 Subject: [PATCH] HPCC-30687 Expand JTrace unittest coverage - Defines clientSpan test - Adds clientSpan test to jtrace suite - Ensures propagate GlobalID is persisted Signed-off-by: Rodrigo Pastrana --- testing/unittests/jlibtests.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/testing/unittests/jlibtests.cpp b/testing/unittests/jlibtests.cpp index 83925b32c49..25ac9655e81 100644 --- a/testing/unittests/jlibtests.cpp +++ b/testing/unittests/jlibtests.cpp @@ -55,6 +55,7 @@ class JlibTraceTest : public CppUnit::TestFixture CPPUNIT_TEST(testInternalSpan); CPPUNIT_TEST(testMultiNestedSpanTraceOutput); CPPUNIT_TEST(testNullSpan); + CPPUNIT_TEST(testClientSpanGlobalID); CPPUNIT_TEST_SUITE_END(); const char * simulatedGlobalYaml = R"!!(global: @@ -416,6 +417,31 @@ class JlibTraceTest : public CppUnit::TestFixture } } + void testClientSpanGlobalID() + { + Owned mockHTTPHeaders = createProperties(); + createMockHTTPHeaders(mockHTTPHeaders, true); //includes global ID + + Owned serverSpan = queryTraceManager().createServerSpan("propegatedServerSpan", mockHTTPHeaders); + Owned clientSpan = serverSpan->createClientSpan("clientSpanWithGlobalID"); + + //retrieve serverSpan context with the intent to interrogate attributes + { + Owned retrievedClientSpanCtxAttributes = createProperties(); + bool getClientSpanCtxSuccess = clientSpan->getSpanContext(retrievedClientSpanCtxAttributes.get(), false); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unexpected getSpanContext failure detected on client span", true, getClientSpanCtxSuccess); + + CPPUNIT_ASSERT_MESSAGE("Unexpected GlobalID detected", + strsame("IncomingUGID", retrievedClientSpanCtxAttributes->queryProp(kGlobalIdHttpHeaderName))); + CPPUNIT_ASSERT_MESSAGE("Unexpected CallerID detected", + strsame("IncomingCID", retrievedClientSpanCtxAttributes->queryProp(kCallerIdHttpHeaderName))); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unexpected empty TraceID detected", false, isEmptyString(retrievedClientSpanCtxAttributes->queryProp("traceID"))); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unexpected empty SpanID detected", false, isEmptyString(retrievedClientSpanCtxAttributes->queryProp("spanID"))); + } + } + void testPropegatedServerSpan() { Owned mockHTTPHeaders = createProperties();