Skip to content

Commit

Permalink
Merge pull request #88 from wwt/flakey-tests
Browse files Browse the repository at this point in the history
Adds debugging to help diagnose flakey test
  • Loading branch information
wiemerm authored Jul 29, 2021
2 parents 036c970 + 955cba2 commit 42c1c58
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ import UIUTest
import SwiftCurrent_UIKit

class ModalStyleTests: XCTestCase {
override class func setUp() {
print("!!!! \(Date().timeIntervalSince1970) - ModalStyleTests - class setup starting. Top view controller: \(String(describing: UIApplication.topViewController()))")
waitUntil(UIApplication.topViewController() != nil)
print("!!!! \(Date().timeIntervalSince1970) - ModalStyleTests - class setup ending. Top view controller: \(String(describing: UIApplication.topViewController()))")
}

override func setUp() {
UIView.setAnimationsEnabled(false)
UIViewController.initializeTestable()
Expand Down Expand Up @@ -70,19 +76,14 @@ class ModalStyleTests: XCTestCase {
}

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

print("!!!! \(Date().timeIntervalSince1970) - testShowModalAsCustom - about to launchInto from: \(String(describing: UIApplication.topViewController()))")
UIApplication.topViewController()?
.launchInto(Workflow(TestViewController.self,
launchStyle: .modal(.custom)))
print("!!!! \(Date().timeIntervalSince1970) - testShowModalAsCustom - Completed launchInto")
UIApplication.topViewController()?.launchInto(Workflow(TestViewController.self,
launchStyle: .modal(.custom)))

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

func testShowModalOverFullScreen() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,27 +459,37 @@ class UIKitConsumerPersistenceTests: XCTestCase {
}

func testDefaultWorkflow_LaunchedFromModal_CanDestroyAllItems_AndStillProceedThroughFlow_AndCallOnFinish() {
class FR1: TestViewController { }
class FR2: TestViewController { }
class FR3: TestViewController { }
print("!!!! \(Date().timeIntervalSince1970) - testDefaultWorkflow_LaunchedFromModal_CanDestroyAllItems_AndStillProceedThroughFlow_AndCallOnFinish - Starting top view controller: \(String(describing: UIApplication.topViewController()))")
class FR1: TestViewController { override func viewDidLoad() { print("!!!! \(Date().timeIntervalSince1970) - FR1 - viewDidLoad()") } }
class FR2: TestViewController { override func viewDidLoad() { print("!!!! \(Date().timeIntervalSince1970) - FR2 - viewDidLoad()") } }
class FR3: TestViewController { override func viewDidLoad() { print("!!!! \(Date().timeIntervalSince1970) - FR3 - viewDidLoad()") } }
let root = UIViewController()
root.loadForTesting()

let expectOnFinish = self.expectation(description: "onFinish called")
print("!!!! \(Date().timeIntervalSince1970) - testDefaultWorkflow_LaunchedFromModal_CanDestroyAllItems_AndStillProceedThroughFlow_AndCallOnFinish - Before launch top view controller: \(String(describing: UIApplication.topViewController()))")
root.launchInto(Workflow(FR1.self, flowPersistence: .removedAfterProceeding)
.thenProceed(with: FR2.self, flowPersistence: .removedAfterProceeding)
.thenProceed(with: FR3.self, flowPersistence: .removedAfterProceeding)) { _ in
XCTAssertUIViewControllerDisplayed(isInstance: root)
XCTAssertNil(UIApplication.topViewController()?.presentingViewController)
expectOnFinish.fulfill()
}

print("!!!! \(Date().timeIntervalSince1970) - testDefaultWorkflow_LaunchedFromModal_CanDestroyAllItems_AndStillProceedThroughFlow_AndCallOnFinish - After launch top view controller: \(String(describing: UIApplication.topViewController()))")
XCTAssertUIViewControllerDisplayed(ofType: FR1.self)
XCTAssert(UIApplication.topViewController()?.presentingViewController === root)

print("!!!! \(Date().timeIntervalSince1970) - testDefaultWorkflow_LaunchedFromModal_CanDestroyAllItems_AndStillProceedThroughFlow_AndCallOnFinish - Proceeding from FR1: \(String(describing: UIApplication.topViewController()))")
(UIApplication.topViewController() as? FR1)?.proceedInWorkflow(nil)
XCTAssertUIViewControllerDisplayed(ofType: FR2.self)
XCTAssert(UIApplication.topViewController()?.presentingViewController === root)

print("!!!! \(Date().timeIntervalSince1970) - testDefaultWorkflow_LaunchedFromModal_CanDestroyAllItems_AndStillProceedThroughFlow_AndCallOnFinish - Proceeding from FR2: \(String(describing: UIApplication.topViewController()))")
(UIApplication.topViewController() as? FR2)?.proceedInWorkflow(nil)
XCTAssertUIViewControllerDisplayed(ofType: FR3.self)

print("!!!! \(Date().timeIntervalSince1970) - testDefaultWorkflow_LaunchedFromModal_CanDestroyAllItems_AndStillProceedThroughFlow_AndCallOnFinish - Proceeding from FR3: \(String(describing: UIApplication.topViewController()))")
(UIApplication.topViewController() as? FR3)?.proceedInWorkflow(nil)

wait(for: [expectOnFinish], timeout: 3)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,26 @@
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "CAF58634256CF0E50044C864"
BuildableName = "SwiftCurrent_UIKitTests.xctest"
BlueprintName = "SwiftCurrent_UIKitTests"
ReferencedContainer = "container:ExampleApps/UIKitExample/UIKitExample.xcodeproj">
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "CAF586AD256CF2B40044C864"
BuildableName = "UIKitExampleTests.xctest"
BlueprintName = "UIKitExampleTests"
ReferencedContainer = "container:ExampleApps/UIKitExample/UIKitExample.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ final class SwiftCurrent_SwiftUIConsumerTests: XCTestCase {
XCTAssertThrowsError(try viewUnderTest.find(ViewType.Text.self, skipFound: 1))
}

wait(for: [expectViewLoaded], timeout: 0.3)
wait(for: [expectViewLoaded], timeout: TestConstant.timeout)
}

func testMovingBiDirectionallyInAWorkflow() throws {
Expand Down

0 comments on commit 42c1c58

Please sign in to comment.