Skip to content

Commit 36f4dcf

Browse files
authored
Merge branch 'main' into spec-change
2 parents ac43818 + e1c6468 commit 36f4dcf

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

Tests/OpenTelemetryApiTests/Context/ActivityContextManagerTests.swift

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -318,32 +318,34 @@ class ActivityContextManagerTests: XCTestCase {
318318
XCTAssert(ActivityContextManager.instance.getCurrentContextValue(forKey: .span) === span1)
319319

320320
//Add it to one parent in one thread
321-
let parent1 = defaultTracer.spanBuilder(spanName: "parent1").startSpan()
322-
ActivityContextManager.instance.setCurrentContextValue(forKey: .span, value: parent1)
323-
XCTAssert(ActivityContextManager.instance.getCurrentContextValue(forKey: .span) === parent1)
324-
325321
DispatchQueue.global().async {
322+
let parent1 = self.defaultTracer.spanBuilder(spanName: "parent1").startSpan()
323+
ActivityContextManager.instance.setCurrentContextValue(forKey: .span, value: parent1)
324+
XCTAssert(ActivityContextManager.instance.getCurrentContextValue(forKey: .span) === parent1)
325+
326326
let activeSpan = ActivityContextManager.instance.getCurrentContextValue(forKey: .span)
327327
XCTAssert(activeSpan === parent1)
328328
ActivityContextManager.instance.setCurrentContextValue(forKey: .span, value: span1)
329329
parent1.end()
330330
}
331331

332332
//Add it to another parent in another thread
333-
let parent2 = defaultTracer.spanBuilder(spanName: "parent2").startSpan()
334-
ActivityContextManager.instance.setCurrentContextValue(forKey: .span, value: parent2)
335-
XCTAssert(ActivityContextManager.instance.getCurrentContextValue(forKey: .span) === parent2)
336-
337333
DispatchQueue.global().async {
334+
let parent2 = self.defaultTracer.spanBuilder(spanName: "parent2").startSpan()
335+
ActivityContextManager.instance.setCurrentContextValue(forKey: .span, value: parent2)
336+
XCTAssert(ActivityContextManager.instance.getCurrentContextValue(forKey: .span) === parent2)
337+
338338
let activeSpan = ActivityContextManager.instance.getCurrentContextValue(forKey: .span)
339339
XCTAssert(activeSpan === parent2)
340340
ActivityContextManager.instance.setCurrentContextValue(forKey: .span, value: span1)
341341
parent2.end()
342342
}
343343

344-
//remove all the contexts from the span and check if the Context is nil
345344
sleep(1)
346-
ActivityContextManager.instance.removeContextValue(forKey: .span, value: span1)
345+
// Remove all the contexts from the span and check if the Context is nil
346+
// Ending the span will remove all the context associated with it, dont need to call removeContextValue explicitly
347+
// ActivityContextManager.instance.removeContextValue(forKey: .span, value: span1)
348+
span1.end()
347349
XCTAssert(ActivityContextManager.instance.getCurrentContextValue(forKey: .span) === nil)
348350
}
349351

0 commit comments

Comments
 (0)