From 7b01729710d530699980495a187d7bd78b576966 Mon Sep 17 00:00:00 2001 From: James McMullan Date: Thu, 14 Nov 2024 23:22:15 -0500 Subject: [PATCH] HPCC-32961 OwnedSpanScope assignment causes early span end - Added OwnedSpanScope assignment operator for ISpan* - Deleted OwnedSpanScope copy constructor and assignment operator Signed-off-by: James McMullan James.McMullan@lexisnexis.com --- system/jlib/jtrace.hpp | 12 ++++++++++++ testing/unittests/jlibtests.cpp | 11 +++++++++++ 2 files changed, 23 insertions(+) diff --git a/system/jlib/jtrace.hpp b/system/jlib/jtrace.hpp index 7f1e7d9431b..22a4603c05f 100644 --- a/system/jlib/jtrace.hpp +++ b/system/jlib/jtrace.hpp @@ -164,11 +164,23 @@ class jlib_decl OwnedSpanScope public: OwnedSpanScope() = default; OwnedSpanScope(ISpan * _ptr); + OwnedSpanScope(const OwnedSpanScope& rhs) = delete; + OwnedSpanScope(OwnedSpanScope&& rhs) = default; ~OwnedSpanScope(); inline ISpan * operator -> () const { return span; } inline operator ISpan *() const { return span; } + inline OwnedSpanScope& operator=(ISpan * ptr) = delete; + inline OwnedSpanScope& operator=(const OwnedSpanScope& rhs) = delete; + inline OwnedSpanScope& operator=(OwnedSpanScope&& rhs) + { + setown(rhs.span.getClear()); + prevSpan = rhs.prevSpan; + + return *this; + } + void clear(); ISpan * query() const { return span; } void set(ISpan * _span); diff --git a/testing/unittests/jlibtests.cpp b/testing/unittests/jlibtests.cpp index 195a34c3705..f744788cc59 100644 --- a/testing/unittests/jlibtests.cpp +++ b/testing/unittests/jlibtests.cpp @@ -285,6 +285,17 @@ class JlibTraceTest : public CppUnit::TestFixture //"start": 1702668157790080022, //"duration": 75316248 } } + + { + OwnedSpanScope serverSpan; + serverSpan = std::move(OwnedSpanScope(queryTraceManager().createServerSpan("movedSpanAssignment", emptyMockHTTPHeaders, &uninitializedTS))); + //sleep for 75 milliseconds after span creation, expect at least 75 milliseconds duration output + MilliSleep(75); + + //14:22:37.865509 30396 { "type": "span", "name": "uninitializeddeclaredSpanStartTime", "trace_id": "f7844c5c09b413e008f912ded0e12dec", "span_id": "7fcf9042a090c663", + //"start": 1702668157790080022, + //"duration": 75316248 } + } } //not able to programmatically test yet, but can visually inspect trace output