diff --git a/Tests/SentryTests/SentryTests-Bridging-Header.h b/Tests/SentryTests/SentryTests-Bridging-Header.h index bca2e15232c..1dc1af4ee23 100644 --- a/Tests/SentryTests/SentryTests-Bridging-Header.h +++ b/Tests/SentryTests/SentryTests-Bridging-Header.h @@ -181,6 +181,7 @@ #import "SentryThreadWrapper.h" #import "SentryTime.h" #import "SentryTraceContext.h" +#import "SentryTracer+Private.h" #import "SentryTracer+Test.h" #import "SentryTransaction.h" #import "SentryTransactionContext+Private.h" diff --git a/Tests/SentryTests/Transaction/SentryTracerTests.swift b/Tests/SentryTests/Transaction/SentryTracerTests.swift index bfbe11babbc..45ce7d2fde0 100644 --- a/Tests/SentryTests/Transaction/SentryTracerTests.swift +++ b/Tests/SentryTests/Transaction/SentryTracerTests.swift @@ -207,18 +207,23 @@ class SentryTracerTests: XCTestCase { } var timer: Timer? + weak var weakSut: SentryTracer? // Added internal function so the tracer gets deallocated after executing this function. func startTracer() { let sut = fixture.getSut() + timer = Dynamic(sut).deadlineTimer.asObject as! Timer? + weakSut = sut + + // The TestHub keeps a reference to the tracer in capturedEventsWithScopes. + // We set it to nil to avoid that. + sut.hub = nil sut.finish() } startTracer() - // The TestHub keeps a reference to the tracer in capturedEventsWithScopes. - // We have to clear the captured events so the tracer gets deallocated. - fixture.hub.capturedEventsWithScopes.removeAll() + XCTAssertNil(weakSut, "sut was not deallocated") fixture.timerFactory.fire()