From dab847d270228d5f3b5393da3842f8458f7f9757 Mon Sep 17 00:00:00 2001 From: M Kelly Date: Mon, 23 Sep 2024 09:36:16 -0400 Subject: [PATCH] HPCC-32691 Add optional timestamp arg to createClientSpan() 3 Signed-off-by: M Kelly --- testing/unittests/jlibtests.cpp | 42 ++++++++++++--------------------- 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/testing/unittests/jlibtests.cpp b/testing/unittests/jlibtests.cpp index bc80645682d..a331936bcdb 100644 --- a/testing/unittests/jlibtests.cpp +++ b/testing/unittests/jlibtests.cpp @@ -59,7 +59,6 @@ class JlibTraceTest : public CppUnit::TestFixture CPPUNIT_TEST(testPropegatedServerSpan); CPPUNIT_TEST(testInvalidPropegatedServerSpan); CPPUNIT_TEST(testInternalSpan); - CPPUNIT_TEST(testClientSpan); CPPUNIT_TEST(testMultiNestedSpanTraceOutput); CPPUNIT_TEST(testNullSpan); CPPUNIT_TEST(testClientSpanGlobalID); @@ -232,6 +231,11 @@ class JlibTraceTest : public CppUnit::TestFixture OwnedSpanScope serverSpan = queryTraceManager().createServerSpan("declaredSpanStartTime", emptyMockHTTPHeaders, &declaredSpanStartTime); //{ "type": "span", "name": "declaredSpanStartTime", "trace_id": "0a2eff24e1996540056745aaeb2f5824", "span_id": "46d0faf8b4da893e", //"start": 1702672311203213259, "duration": 125311051 } + + SpanTimeStamp clientSpanTimeStamp; + clientSpanTimeStamp.now(); + MilliSleep(20); + OwnedSpanScope clientSpan = serverSpan->createClientSpan("clientSpanStartTime", &clientSpanTimeStamp); } auto reqStartMSTick = msTick(); @@ -248,6 +252,12 @@ class JlibTraceTest : public CppUnit::TestFixture nowTimeStamp.now(); { OwnedSpanScope serverSpan = queryTraceManager().createServerSpan("msTickOffsetStartTime", emptyMockHTTPHeaders, &msTickOffsetTimeStamp); + + unsigned clientStartMS = msTick(); + MilliSleep(20); + SpanTimeStamp clientSpanTimeStamp; + clientSpanTimeStamp.setMSTickTime(clientStartMS); + OwnedSpanScope clientSpan = serverSpan->createClientSpan("clientSpanOffsetTime", &clientSpanTimeStamp); } DBGLOG("MsTickOffset span actual start-time timestamp: %lld", (long long)(nowTimeStamp.systemClockTime).count()); @@ -483,33 +493,11 @@ class JlibTraceTest : public CppUnit::TestFixture CPPUNIT_ASSERT_MESSAGE("Mismatched localParentSpanID detected", strsame(serverSpanID, retrievedSpanCtxAttributes->queryProp("localParentSpanID"))); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Unexpected GlobalID detected", false, - retrievedSpanCtxAttributes->hasProp(kGlobalIdHttpHeaderName)); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Unexpected CallerID detected", false, - retrievedSpanCtxAttributes->hasProp(kCallerIdHttpHeaderName)); - - CPPUNIT_ASSERT_EQUAL_MESSAGE("Unexpected Declared Parent SpanID detected", false, - retrievedSpanCtxAttributes->hasProp("remoteParentSpanID")); - - CPPUNIT_ASSERT_EQUAL_MESSAGE("Unexpected empty TraceID detected", false, isEmptyString(retrievedSpanCtxAttributes->queryProp("traceID"))); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Unexpected empty SpanID detected", false, isEmptyString(retrievedSpanCtxAttributes->queryProp("spanID"))); - } - } - - { - unsigned startMs = msTick() - 1234; - SpanTimeStamp SpanTS; - SpanTS.setMSTickTime(startMs); - OwnedSpanScope clientSpan = serverSpan->createClientSpan("clientSpan", &SpanTS); - //retrieve clientSpan context with the intent to propogate otel and HPCC context - { - Owned retrievedSpanCtxAttributes = createProperties(); - clientSpan->getSpanContext(retrievedSpanCtxAttributes); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Unexpected missing localParentSpanID detected", true, - retrievedSpanCtxAttributes->hasProp("localParentSpanID")); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unexpected missing remoteParentID detected", true, + retrievedSpanCtxAttributes->hasProp("remoteParentID")); - CPPUNIT_ASSERT_MESSAGE("Mismatched localParentSpanID detected", - strsame(serverSpanID, retrievedSpanCtxAttributes->queryProp("localParentSpanID"))); + CPPUNIT_ASSERT_MESSAGE("Unexpected CallerID detected", + strsame(serverTraceID, retrievedSpanCtxAttributes->queryProp("remoteParentID"))); CPPUNIT_ASSERT_EQUAL_MESSAGE("Unexpected GlobalID detected", false, retrievedSpanCtxAttributes->hasProp(kGlobalIdHttpHeaderName));