Skip to content

Commit

Permalink
Fix testAsyncStacktraces
Browse files Browse the repository at this point in the history
Fixed Xcode 14 problems
  • Loading branch information
kevinrenskers committed Sep 13, 2022
1 parent b54a8a0 commit fccfb49
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 20 deletions.
4 changes: 2 additions & 2 deletions Samples/iOS-Swift/iOS-Swift/Tools/SpanObserver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class SpanObserver: NSObject {
}
}

func performOnFinish(callback : @escaping (Span) -> Void) {
func performOnFinish(callback: @escaping (Span) -> Void) {
addSpanObserver(forKeyPath: "timestamp", callback: callback)
}

Expand All @@ -32,7 +32,7 @@ class SpanObserver: NSObject {
}
}

func addSpanObserver(forKeyPath keyPath: String, callback : @escaping (Span) -> Void) {
func addSpanObserver(forKeyPath keyPath: String, callback: @escaping (Span) -> Void) {
callbacks[keyPath] = callback
//The given span may be a SentryTracer that wont respond to KVO. We need to get the root Span
let spanToObserve = span.rootSpan() ?? span
Expand Down
2 changes: 1 addition & 1 deletion Samples/tvOS-Swift/tvOS-SBSwift/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class ViewController: UICollectionViewController {

struct Action {
var title: String
var callback : () -> Void
var callback: () -> Void
}

var actions: [Action]!
Expand Down
2 changes: 1 addition & 1 deletion Tests/SentryTests/Helper/UrlSessionDelegateSpy.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation

class UrlSessionDelegateSpy: NSObject, URLSessionDelegate {
var delegateCallback : () -> Void = {}
var delegateCallback: () -> Void = {}

func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
delegateCallback()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class SentryFramesTrackerTests: XCTestCase {
XCTAssertEqual(0, sut.currentFrames.frozen)
}

private func assertPreviousCountBiggerThanCurrent(_ group: DispatchGroup, count: @escaping () -> UInt) {
private func assertPreviousCountBiggerThanCurrent(_ group: DispatchGroup, count: @escaping () -> UInt) {
group.enter()
fixture.queue.async {
var previousCount: UInt = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ class SentryFileIOTrackingIntegrationTests: XCTestCase {
}
}

private func assertSpans( _ spansCount: Int, _ operation: String, _ description: String = "TestFile", _ block : () -> Void) {
private func assertSpans( _ spansCount: Int, _ operation: String, _ description: String = "TestFile", _ block: () -> Void) {
let parentTransaction = SentrySDK.startTransaction(name: "Transaction", operation: "Test", bindToScope: true)

block()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,21 @@ class SentryUIViewControllerSwizzlingTests: XCTestCase {
}

func testSwizzle_fromApplication_noWindowMethod() {
XCTAssertFalse(fixture.sut.swizzleRootViewController(from: MockApplication(MockApplication.MockApplicationDelegateNoWindow())))
let mockApplicationDelegate = MockApplication.MockApplicationDelegateNoWindow()
let mockApplication = MockApplication(mockApplicationDelegate)
XCTAssertFalse(fixture.sut.swizzleRootViewController(from: mockApplication))
}

func testSwizzle_fromApplication_noWindow() {
XCTAssertFalse(fixture.sut.swizzleRootViewController(from: MockApplication(MockApplication.MockApplicationDelegate(nil))))
let mockApplicationDelegate = MockApplication.MockApplicationDelegate(nil)
let mockApplication = MockApplication(mockApplicationDelegate)
XCTAssertFalse(fixture.sut.swizzleRootViewController(from: mockApplication))
}

func testSwizzle_fromApplication_noRootViewController_InWindow() {
XCTAssertFalse(fixture.sut.swizzleRootViewController(from: MockApplication(MockApplication.MockApplicationDelegate(UIWindow()))))
let mockApplicationDelegate = MockApplication.MockApplicationDelegate(UIWindow())
let mockApplication = MockApplication(mockApplicationDelegate)
XCTAssertFalse(fixture.sut.swizzleRootViewController(from: mockApplication))
}

func testSwizzle_fromApplication() {
Expand Down
2 changes: 1 addition & 1 deletion Tests/SentryTests/Networking/TestRequestManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Foundation
@available(OSX 10.12, *)
public class TestRequestManager: NSObject, RequestManager {

private var nextResponse : () -> HTTPURLResponse? = { return nil }
private var nextResponse: () -> HTTPURLResponse? = { return nil }
var nextError: NSError?
public var isReady: Bool

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class TestSentryDispatchQueueWrapper: SentryDispatchQueueWrapper {
}

var blockOnMainInvocations = Invocations<() -> Void>()
var blockBeforeMainBlock : () -> Bool = { true }
var blockBeforeMainBlock: () -> Bool = { true }

override func dispatch(onMainQueue block: @escaping () -> Void) {
blockOnMainInvocations.record(block)
Expand Down
10 changes: 3 additions & 7 deletions Tests/SentryTests/SentryCrash/SentryStacktraceBuilderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ class SentryStacktraceBuilderTests: XCTestCase {
XCTAssertTrue(filteredFrames.count == 1, "The frames must be ordered from caller to callee, or oldest to youngest.")
}

/**
* Disabled for now, because this test is flaky.
*/
func testAsyncStacktraces() throws {
SentrySDK.start { options in
options.dsn = TestConstants.dsnAsString(username: "SentryStacktraceBuilderTests")
Expand All @@ -96,21 +93,20 @@ class SentryStacktraceBuilderTests: XCTestCase {
self.asyncAssertion(expect: expect)
}
}

func asyncAssertion(expect: XCTestExpectation) {
let actual = fixture.sut.buildStacktraceForCurrentThread()

let filteredFrames = actual.frames.filter { frame in
return frame.function?.contains("testAsyncStacktraces") ?? false ||
frame.function?.contains("asyncFrame1") ?? false ||
frame.function?.contains("asyncFrame2") ?? false ||
frame.function?.contains("asyncAssertion") ?? false
frame.function?.contains("asyncFrame2") ?? false
}
let startFrames = actual.frames.filter { frame in
return frame.stackStart?.boolValue ?? false
}

XCTAssertTrue(filteredFrames.count >= 4, "The Stacktrace must include the async callers.")
XCTAssertTrue(filteredFrames.count >= 3, "The Stacktrace must include the async callers.")
XCTAssertTrue(startFrames.count >= 3, "The Stacktrace must have async continuation markers.")

expect.fulfill()
Expand Down
2 changes: 1 addition & 1 deletion Tests/SentryTests/SentryScreenShotTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class SentryScreenShotTests: XCTestCase {
}

class TestWindow: UIWindow {
var onDrawHierarchy : (() -> Void)?
var onDrawHierarchy: (() -> Void)?

override func drawHierarchy(in rect: CGRect, afterScreenUpdates afterUpdates: Bool) -> Bool {
onDrawHierarchy?()
Expand Down
2 changes: 1 addition & 1 deletion Tests/SentryTests/Transaction/SentrySpanTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ class SentrySpanTests: XCTestCase {
func testSpanWithoutTracer_StartChild_ReturnsNoOpSpan() {
// Span has a weak reference to tracer. If we don't keep a reference
// to the tracer ARC will deallocate the tracer.
let sutGenerator : () -> Span = {
let sutGenerator: () -> Span = {
let tracer = SentryTracer()
return SentrySpan(tracer: tracer, context: SpanContext(operation: ""))
}
Expand Down

0 comments on commit fccfb49

Please sign in to comment.