Skip to content

Commit f10af7a

Browse files
author
Gleb Tarasov
committed
Improve leak detection tests
1 parent 73e2a09 commit f10af7a

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

PerformanceSuite/Tests/ViewControllerLeaksObserverTests.swift

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import XCTest
1010

1111
@testable import PerformanceSuite
1212

13+
// swiftlint:disable force_unwrapping
1314
class ViewControllerLeaksObserverTests: XCTestCase {
1415

1516
override func setUp() {
@@ -38,16 +39,24 @@ class ViewControllerLeaksObserverTests: XCTestCase {
3839

3940
weak var weakViewController: UIViewController?
4041
autoreleasepool {
41-
var viewController: UIViewController? = viewControllerMaker()
42-
weakViewController = viewController
43-
if let viewController = viewController {
44-
rootViewController.present(viewController, animated: false)
45-
viewController.dismiss(animated: false)
42+
let exp = expectation(description: "view controller presentation")
43+
var strongViewController: UIViewController? = viewControllerMaker()
44+
weakViewController = strongViewController
45+
if let viewController = strongViewController {
46+
rootViewController.present(viewController, animated: false) {
47+
viewController.dismiss(animated: false) {
48+
strongViewController = nil
49+
exp.fulfill()
50+
}
51+
}
4652
}
47-
viewController = nil
53+
wait(for: [exp], timeout: 1)
4854
}
4955

50-
waitForExpectations(timeout: 1)
56+
PerformanceSuite.queue.sync { }
57+
PerformanceSuite.consumerQueue.sync { }
58+
59+
wait(for: [receiver.expectation!], timeout: 1)
5160
if expectLeak {
5261
let vc = weakViewController
5362
XCTAssertNotNil(vc)

0 commit comments

Comments
 (0)