From adde8182ca8233cf2934bd181d35f2781995c92c Mon Sep 17 00:00:00 2001 From: Richard Gist Date: Tue, 27 Jul 2021 15:55:38 -0600 Subject: [PATCH 1/7] [flakey-tests] - Found another timeout that should have been updated - RAG --- Tests/SwiftCurrent_SwiftUITests/SwiftCurrent_SwiftUITests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/SwiftCurrent_SwiftUITests/SwiftCurrent_SwiftUITests.swift b/Tests/SwiftCurrent_SwiftUITests/SwiftCurrent_SwiftUITests.swift index 56449b594..dbdd582ad 100644 --- a/Tests/SwiftCurrent_SwiftUITests/SwiftCurrent_SwiftUITests.swift +++ b/Tests/SwiftCurrent_SwiftUITests/SwiftCurrent_SwiftUITests.swift @@ -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 { From bee9e50b7b64ba20e917216bd567f3db9d9af26e Mon Sep 17 00:00:00 2001 From: Richard Gist Date: Wed, 28 Jul 2021 10:56:32 -0600 Subject: [PATCH 2/7] [flakey-tests] - Changing topViewController to get the top window instead of the bottom window - BL RAG Co-authored-by: Brian Lombardo --- .../TestUtilities/TopViewController.swift | 2 +- .../xcschemes/SwiftCurrent_UIKit.xcscheme | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/ExampleApps/UIKitExample/SwiftCurrent_UIKitTests/TestUtilities/TopViewController.swift b/ExampleApps/UIKitExample/SwiftCurrent_UIKitTests/TestUtilities/TopViewController.swift index 945e2e46d..8c632a1ab 100644 --- a/ExampleApps/UIKitExample/SwiftCurrent_UIKitTests/TestUtilities/TopViewController.swift +++ b/ExampleApps/UIKitExample/SwiftCurrent_UIKitTests/TestUtilities/TopViewController.swift @@ -10,7 +10,7 @@ import Foundation import UIKit extension UIApplication { - static func topViewController(of controller: UIViewController? = UIApplication.shared.windows.first?.rootViewController) -> UIViewController? { + static func topViewController(of controller: UIViewController? = UIApplication.shared.windows.last?.rootViewController) -> UIViewController? { if let navigationController = controller as? UINavigationController, let visible = navigationController.visibleViewController { return topViewController(of: visible) diff --git a/SwiftCurrent.xcworkspace/xcshareddata/xcschemes/SwiftCurrent_UIKit.xcscheme b/SwiftCurrent.xcworkspace/xcshareddata/xcschemes/SwiftCurrent_UIKit.xcscheme index ced738c2b..fe1f7bc7e 100644 --- a/SwiftCurrent.xcworkspace/xcshareddata/xcschemes/SwiftCurrent_UIKit.xcscheme +++ b/SwiftCurrent.xcworkspace/xcshareddata/xcschemes/SwiftCurrent_UIKit.xcscheme @@ -42,6 +42,26 @@ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" shouldUseLaunchSchemeArgsEnv = "YES"> + + + + + + + + Date: Wed, 28 Jul 2021 11:19:45 -0600 Subject: [PATCH 3/7] [flakey-tests] - New debugging information and additional assert for testShowModalAsCustom - RAG BL Co-authored-by: Brian Lombardo --- .../ModalStyleTests.swift | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/ExampleApps/UIKitExample/SwiftCurrent_UIKitTests/ModalStyleTests.swift b/ExampleApps/UIKitExample/SwiftCurrent_UIKitTests/ModalStyleTests.swift index 3ee4f59ed..b8e109c68 100644 --- a/ExampleApps/UIKitExample/SwiftCurrent_UIKitTests/ModalStyleTests.swift +++ b/ExampleApps/UIKitExample/SwiftCurrent_UIKitTests/ModalStyleTests.swift @@ -69,20 +69,24 @@ class ModalStyleTests: XCTestCase { XCTAssertEqual(UIApplication.topViewController()?.modalPresentationStyle, .currentContext) } + // This test has been flakey in the pipeline. Print statements to help diagnose and debug. func testShowModalAsCustom() { - print("!!!! \(Date().timeIntervalSince1970) - testShowModalAsCustom - About to loadForTesting") - RootViewController.standard.loadForTesting() - print("!!!! \(Date().timeIntervalSince1970) - testShowModalAsCustom - Completed loadForTesting") + print("!!!! \(Date().timeIntervalSince1970) - testShowModalAsCustom - Starting top view controller: \(String(describing: UIApplication.topViewController()))") + let standardRoot = RootViewController.standard + print("!!!! \(Date().timeIntervalSince1970) - testShowModalAsCustom - About to load \(standardRoot) for testing") + let topViewController = standardRoot.loadForTesting() + print("!!!! \(Date().timeIntervalSince1970) - testShowModalAsCustom - \(String(describing: topViewController)) was loaded for testing") + + XCTAssertIdentical(topViewController, 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))) + print("!!!! \(Date().timeIntervalSince1970) - testShowModalAsCustom - Completed launchInto. TopViewController is now: \(String(describing: UIApplication.topViewController()))") XCTAssertUIViewControllerDisplayed(ofType: TestViewController.self) XCTAssertEqual(UIApplication.topViewController()?.modalPresentationStyle.rawValue, UIModalPresentationStyle.custom.rawValue) - print("!!!! \(Date().timeIntervalSince1970) - testShowModalAsCustom - RawValue: \(String(describing: UIApplication.topViewController()?.modalPresentationStyle.rawValue))") + print("!!!! \(Date().timeIntervalSince1970) - testShowModalAsCustom - completed test, final top view controller: \(String(describing: UIApplication.topViewController()))") } func testShowModalOverFullScreen() { From b89cad3a13cf8cc5ebe9f9ab42c59ff8a4b6d4f2 Mon Sep 17 00:00:00 2001 From: Richard Gist Date: Wed, 28 Jul 2021 11:24:19 -0600 Subject: [PATCH 4/7] [flakey-tests] - topViewController starts to act weird and fail with windows.last instead of windows.first - BL RAG Co-authored-by: Brian Lombardo --- .../TestUtilities/TopViewController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ExampleApps/UIKitExample/SwiftCurrent_UIKitTests/TestUtilities/TopViewController.swift b/ExampleApps/UIKitExample/SwiftCurrent_UIKitTests/TestUtilities/TopViewController.swift index 8c632a1ab..945e2e46d 100644 --- a/ExampleApps/UIKitExample/SwiftCurrent_UIKitTests/TestUtilities/TopViewController.swift +++ b/ExampleApps/UIKitExample/SwiftCurrent_UIKitTests/TestUtilities/TopViewController.swift @@ -10,7 +10,7 @@ import Foundation import UIKit extension UIApplication { - static func topViewController(of controller: UIViewController? = UIApplication.shared.windows.last?.rootViewController) -> UIViewController? { + static func topViewController(of controller: UIViewController? = UIApplication.shared.windows.first?.rootViewController) -> UIViewController? { if let navigationController = controller as? UINavigationController, let visible = navigationController.visibleViewController { return topViewController(of: visible) From ea7ab6534509a859ee06968e1eda4ceaeba2efd9 Mon Sep 17 00:00:00 2001 From: Richard Gist Date: Wed, 28 Jul 2021 11:34:46 -0600 Subject: [PATCH 5/7] [flakey-tests] - Forgot that XCTAssertIdentical requires Xcode 12.5 which we dont have in the pipeline - BL RAG Co-authored-by: Brian Lombardo --- .../UIKitExample/SwiftCurrent_UIKitTests/ModalStyleTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ExampleApps/UIKitExample/SwiftCurrent_UIKitTests/ModalStyleTests.swift b/ExampleApps/UIKitExample/SwiftCurrent_UIKitTests/ModalStyleTests.swift index b8e109c68..226160cd3 100644 --- a/ExampleApps/UIKitExample/SwiftCurrent_UIKitTests/ModalStyleTests.swift +++ b/ExampleApps/UIKitExample/SwiftCurrent_UIKitTests/ModalStyleTests.swift @@ -77,7 +77,7 @@ class ModalStyleTests: XCTestCase { let topViewController = standardRoot.loadForTesting() print("!!!! \(Date().timeIntervalSince1970) - testShowModalAsCustom - \(String(describing: topViewController)) was loaded for testing") - XCTAssertIdentical(topViewController, UIApplication.topViewController(), "loadForTesting() failed to update the top view controller") + XCTAssert(topViewController === UIApplication.topViewController(), "\(String(describing: topViewController)) should be \(String(describing: 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, From a7a264aaccd7ed4dd03d5330d987b8188f4cb54e Mon Sep 17 00:00:00 2001 From: Richard Gist Date: Wed, 28 Jul 2021 16:23:39 -0600 Subject: [PATCH 6/7] [flakey-tests] - Adding class setUp to wait for topViewController to not be nil - TT RAG Co-authored-by: Tyler Thompson --- .../SwiftCurrent_UIKitTests/ModalStyleTests.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ExampleApps/UIKitExample/SwiftCurrent_UIKitTests/ModalStyleTests.swift b/ExampleApps/UIKitExample/SwiftCurrent_UIKitTests/ModalStyleTests.swift index 226160cd3..d0d8c2555 100644 --- a/ExampleApps/UIKitExample/SwiftCurrent_UIKitTests/ModalStyleTests.swift +++ b/ExampleApps/UIKitExample/SwiftCurrent_UIKitTests/ModalStyleTests.swift @@ -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() From 955cba2625dfdcae265dbc3712bddf2abee114d8 Mon Sep 17 00:00:00 2001 From: Richard Gist Date: Thu, 29 Jul 2021 09:03:21 -0600 Subject: [PATCH 7/7] [flakey-tests] - Removing debug prints from fixed test and moving them to another flakey test - RAG --- .../ModalStyleTests.swift | 13 ++----------- .../UIKitConsumerPersistenceTests.swift | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/ExampleApps/UIKitExample/SwiftCurrent_UIKitTests/ModalStyleTests.swift b/ExampleApps/UIKitExample/SwiftCurrent_UIKitTests/ModalStyleTests.swift index d0d8c2555..277db3621 100644 --- a/ExampleApps/UIKitExample/SwiftCurrent_UIKitTests/ModalStyleTests.swift +++ b/ExampleApps/UIKitExample/SwiftCurrent_UIKitTests/ModalStyleTests.swift @@ -75,24 +75,15 @@ class ModalStyleTests: XCTestCase { XCTAssertEqual(UIApplication.topViewController()?.modalPresentationStyle, .currentContext) } - // This test has been flakey in the pipeline. Print statements to help diagnose and debug. func testShowModalAsCustom() { - print("!!!! \(Date().timeIntervalSince1970) - testShowModalAsCustom - Starting top view controller: \(String(describing: UIApplication.topViewController()))") - let standardRoot = RootViewController.standard - print("!!!! \(Date().timeIntervalSince1970) - testShowModalAsCustom - About to load \(standardRoot) for testing") - let topViewController = standardRoot.loadForTesting() - print("!!!! \(Date().timeIntervalSince1970) - testShowModalAsCustom - \(String(describing: topViewController)) was loaded for testing") - - XCTAssert(topViewController === UIApplication.topViewController(), "\(String(describing: topViewController)) should be \(String(describing: UIApplication.topViewController())) - loadForTesting() failed to update the top view controller") + RootViewController.standard.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. TopViewController is now: \(String(describing: UIApplication.topViewController()))") XCTAssertUIViewControllerDisplayed(ofType: TestViewController.self) XCTAssertEqual(UIApplication.topViewController()?.modalPresentationStyle.rawValue, UIModalPresentationStyle.custom.rawValue) - print("!!!! \(Date().timeIntervalSince1970) - testShowModalAsCustom - completed test, final top view controller: \(String(describing: UIApplication.topViewController()))") } func testShowModalOverFullScreen() { diff --git a/ExampleApps/UIKitExample/SwiftCurrent_UIKitTests/UIKitConsumerPersistenceTests.swift b/ExampleApps/UIKitExample/SwiftCurrent_UIKitTests/UIKitConsumerPersistenceTests.swift index 14d94d06b..db68d5f7d 100644 --- a/ExampleApps/UIKitExample/SwiftCurrent_UIKitTests/UIKitConsumerPersistenceTests.swift +++ b/ExampleApps/UIKitExample/SwiftCurrent_UIKitTests/UIKitConsumerPersistenceTests.swift @@ -459,13 +459,15 @@ 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 @@ -473,13 +475,21 @@ class UIKitConsumerPersistenceTests: XCTestCase { 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)