Skip to content

Commit 42c1c58

Browse files
authored
Merge pull request #88 from wwt/flakey-tests
Adds debugging to help diagnose flakey test
2 parents 036c970 + 955cba2 commit 42c1c58

File tree

4 files changed

+43
-12
lines changed

4 files changed

+43
-12
lines changed

ExampleApps/UIKitExample/SwiftCurrent_UIKitTests/ModalStyleTests.swift

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ import UIUTest
1414
import SwiftCurrent_UIKit
1515

1616
class ModalStyleTests: XCTestCase {
17+
override class func setUp() {
18+
print("!!!! \(Date().timeIntervalSince1970) - ModalStyleTests - class setup starting. Top view controller: \(String(describing: UIApplication.topViewController()))")
19+
waitUntil(UIApplication.topViewController() != nil)
20+
print("!!!! \(Date().timeIntervalSince1970) - ModalStyleTests - class setup ending. Top view controller: \(String(describing: UIApplication.topViewController()))")
21+
}
22+
1723
override func setUp() {
1824
UIView.setAnimationsEnabled(false)
1925
UIViewController.initializeTestable()
@@ -70,19 +76,14 @@ class ModalStyleTests: XCTestCase {
7076
}
7177

7278
func testShowModalAsCustom() {
73-
print("!!!! \(Date().timeIntervalSince1970) - testShowModalAsCustom - About to loadForTesting")
7479
RootViewController.standard.loadForTesting()
75-
print("!!!! \(Date().timeIntervalSince1970) - testShowModalAsCustom - Completed loadForTesting")
80+
XCTAssertNotNil(UIApplication.topViewController(), "loadForTesting() failed to update the top view controller")
7681

77-
print("!!!! \(Date().timeIntervalSince1970) - testShowModalAsCustom - about to launchInto from: \(String(describing: UIApplication.topViewController()))")
78-
UIApplication.topViewController()?
79-
.launchInto(Workflow(TestViewController.self,
80-
launchStyle: .modal(.custom)))
81-
print("!!!! \(Date().timeIntervalSince1970) - testShowModalAsCustom - Completed launchInto")
82+
UIApplication.topViewController()?.launchInto(Workflow(TestViewController.self,
83+
launchStyle: .modal(.custom)))
8284

8385
XCTAssertUIViewControllerDisplayed(ofType: TestViewController.self)
8486
XCTAssertEqual(UIApplication.topViewController()?.modalPresentationStyle.rawValue, UIModalPresentationStyle.custom.rawValue)
85-
print("!!!! \(Date().timeIntervalSince1970) - testShowModalAsCustom - RawValue: \(String(describing: UIApplication.topViewController()?.modalPresentationStyle.rawValue))")
8687
}
8788

8889
func testShowModalOverFullScreen() {

ExampleApps/UIKitExample/SwiftCurrent_UIKitTests/UIKitConsumerPersistenceTests.swift

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,27 +459,37 @@ class UIKitConsumerPersistenceTests: XCTestCase {
459459
}
460460

461461
func testDefaultWorkflow_LaunchedFromModal_CanDestroyAllItems_AndStillProceedThroughFlow_AndCallOnFinish() {
462-
class FR1: TestViewController { }
463-
class FR2: TestViewController { }
464-
class FR3: TestViewController { }
462+
print("!!!! \(Date().timeIntervalSince1970) - testDefaultWorkflow_LaunchedFromModal_CanDestroyAllItems_AndStillProceedThroughFlow_AndCallOnFinish - Starting top view controller: \(String(describing: UIApplication.topViewController()))")
463+
class FR1: TestViewController { override func viewDidLoad() { print("!!!! \(Date().timeIntervalSince1970) - FR1 - viewDidLoad()") } }
464+
class FR2: TestViewController { override func viewDidLoad() { print("!!!! \(Date().timeIntervalSince1970) - FR2 - viewDidLoad()") } }
465+
class FR3: TestViewController { override func viewDidLoad() { print("!!!! \(Date().timeIntervalSince1970) - FR3 - viewDidLoad()") } }
465466
let root = UIViewController()
466467
root.loadForTesting()
467468

468469
let expectOnFinish = self.expectation(description: "onFinish called")
470+
print("!!!! \(Date().timeIntervalSince1970) - testDefaultWorkflow_LaunchedFromModal_CanDestroyAllItems_AndStillProceedThroughFlow_AndCallOnFinish - Before launch top view controller: \(String(describing: UIApplication.topViewController()))")
469471
root.launchInto(Workflow(FR1.self, flowPersistence: .removedAfterProceeding)
470472
.thenProceed(with: FR2.self, flowPersistence: .removedAfterProceeding)
471473
.thenProceed(with: FR3.self, flowPersistence: .removedAfterProceeding)) { _ in
472474
XCTAssertUIViewControllerDisplayed(isInstance: root)
473475
XCTAssertNil(UIApplication.topViewController()?.presentingViewController)
474476
expectOnFinish.fulfill()
475477
}
478+
479+
print("!!!! \(Date().timeIntervalSince1970) - testDefaultWorkflow_LaunchedFromModal_CanDestroyAllItems_AndStillProceedThroughFlow_AndCallOnFinish - After launch top view controller: \(String(describing: UIApplication.topViewController()))")
476480
XCTAssertUIViewControllerDisplayed(ofType: FR1.self)
477481
XCTAssert(UIApplication.topViewController()?.presentingViewController === root)
482+
483+
print("!!!! \(Date().timeIntervalSince1970) - testDefaultWorkflow_LaunchedFromModal_CanDestroyAllItems_AndStillProceedThroughFlow_AndCallOnFinish - Proceeding from FR1: \(String(describing: UIApplication.topViewController()))")
478484
(UIApplication.topViewController() as? FR1)?.proceedInWorkflow(nil)
479485
XCTAssertUIViewControllerDisplayed(ofType: FR2.self)
480486
XCTAssert(UIApplication.topViewController()?.presentingViewController === root)
487+
488+
print("!!!! \(Date().timeIntervalSince1970) - testDefaultWorkflow_LaunchedFromModal_CanDestroyAllItems_AndStillProceedThroughFlow_AndCallOnFinish - Proceeding from FR2: \(String(describing: UIApplication.topViewController()))")
481489
(UIApplication.topViewController() as? FR2)?.proceedInWorkflow(nil)
482490
XCTAssertUIViewControllerDisplayed(ofType: FR3.self)
491+
492+
print("!!!! \(Date().timeIntervalSince1970) - testDefaultWorkflow_LaunchedFromModal_CanDestroyAllItems_AndStillProceedThroughFlow_AndCallOnFinish - Proceeding from FR3: \(String(describing: UIApplication.topViewController()))")
483493
(UIApplication.topViewController() as? FR3)?.proceedInWorkflow(nil)
484494

485495
wait(for: [expectOnFinish], timeout: 3)

SwiftCurrent.xcworkspace/xcshareddata/xcschemes/SwiftCurrent_UIKit.xcscheme

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,26 @@
4242
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
4343
shouldUseLaunchSchemeArgsEnv = "YES">
4444
<Testables>
45+
<TestableReference
46+
skipped = "NO">
47+
<BuildableReference
48+
BuildableIdentifier = "primary"
49+
BlueprintIdentifier = "CAF58634256CF0E50044C864"
50+
BuildableName = "SwiftCurrent_UIKitTests.xctest"
51+
BlueprintName = "SwiftCurrent_UIKitTests"
52+
ReferencedContainer = "container:ExampleApps/UIKitExample/UIKitExample.xcodeproj">
53+
</BuildableReference>
54+
</TestableReference>
55+
<TestableReference
56+
skipped = "NO">
57+
<BuildableReference
58+
BuildableIdentifier = "primary"
59+
BlueprintIdentifier = "CAF586AD256CF2B40044C864"
60+
BuildableName = "UIKitExampleTests.xctest"
61+
BlueprintName = "UIKitExampleTests"
62+
ReferencedContainer = "container:ExampleApps/UIKitExample/UIKitExample.xcodeproj">
63+
</BuildableReference>
64+
</TestableReference>
4565
</Testables>
4666
</TestAction>
4767
<LaunchAction

Tests/SwiftCurrent_SwiftUITests/SwiftCurrent_SwiftUITests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ final class SwiftCurrent_SwiftUIConsumerTests: XCTestCase {
303303
XCTAssertThrowsError(try viewUnderTest.find(ViewType.Text.self, skipFound: 1))
304304
}
305305

306-
wait(for: [expectViewLoaded], timeout: 0.3)
306+
wait(for: [expectViewLoaded], timeout: TestConstant.timeout)
307307
}
308308

309309
func testMovingBiDirectionallyInAWorkflow() throws {

0 commit comments

Comments
 (0)