Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
philipphofmann committed Oct 12, 2023
1 parent 49cc4ca commit 0aeff0a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions Tests/SentryTests/SentryTests-Bridging-Header.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 8 additions & 3 deletions Tests/SentryTests/Transaction/SentryTracerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 0aeff0a

Please sign in to comment.