Skip to content

Commit

Permalink
modified testRemoveContextValuesFromSpan to call span.end() instead o…
Browse files Browse the repository at this point in the history
…f explicitly calling removeContextValue
  • Loading branch information
vvydier committed Dec 21, 2023
1 parent d502090 commit 57249c7
Showing 1 changed file with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -318,32 +318,34 @@ class ActivityContextManagerTests: XCTestCase {
XCTAssert(ActivityContextManager.instance.getCurrentContextValue(forKey: .span) === span1)

//Add it to one parent in one thread
let parent1 = defaultTracer.spanBuilder(spanName: "parent1").startSpan()
ActivityContextManager.instance.setCurrentContextValue(forKey: .span, value: parent1)
XCTAssert(ActivityContextManager.instance.getCurrentContextValue(forKey: .span) === parent1)

DispatchQueue.global().async {
let parent1 = self.defaultTracer.spanBuilder(spanName: "parent1").startSpan()
ActivityContextManager.instance.setCurrentContextValue(forKey: .span, value: parent1)
XCTAssert(ActivityContextManager.instance.getCurrentContextValue(forKey: .span) === parent1)

let activeSpan = ActivityContextManager.instance.getCurrentContextValue(forKey: .span)
XCTAssert(activeSpan === parent1)
ActivityContextManager.instance.setCurrentContextValue(forKey: .span, value: span1)
parent1.end()
}

//Add it to another parent in another thread
let parent2 = defaultTracer.spanBuilder(spanName: "parent2").startSpan()
ActivityContextManager.instance.setCurrentContextValue(forKey: .span, value: parent2)
XCTAssert(ActivityContextManager.instance.getCurrentContextValue(forKey: .span) === parent2)

DispatchQueue.global().async {
let parent2 = self.defaultTracer.spanBuilder(spanName: "parent2").startSpan()
ActivityContextManager.instance.setCurrentContextValue(forKey: .span, value: parent2)
XCTAssert(ActivityContextManager.instance.getCurrentContextValue(forKey: .span) === parent2)

let activeSpan = ActivityContextManager.instance.getCurrentContextValue(forKey: .span)
XCTAssert(activeSpan === parent2)
ActivityContextManager.instance.setCurrentContextValue(forKey: .span, value: span1)
parent2.end()
}

//remove all the contexts from the span and check if the Context is nil
sleep(1)
ActivityContextManager.instance.removeContextValue(forKey: .span, value: span1)
// Remove all the contexts from the span and check if the Context is nil
// Ending the span will remove all the context associated with it, dont need to call removeContextValue explicitly
// ActivityContextManager.instance.removeContextValue(forKey: .span, value: span1)
span1.end()
XCTAssert(ActivityContextManager.instance.getCurrentContextValue(forKey: .span) === nil)
}

Expand Down

0 comments on commit 57249c7

Please sign in to comment.