Skip to content

Commit 7634f00

Browse files
Fix flaky tests.
1 parent 7f0be69 commit 7634f00

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

tests/unit-tests/InAppTests.swift

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -560,21 +560,15 @@ class InAppTests: XCTestCase {
560560
func testShowInAppWithCustomActionBackwardCompatibility() {
561561
let customActionScheme = "itbl"
562562
let customActionName = "my_custom_action"
563-
let expectation1 = expectation(description: "verify custom action is called, customActionScheme: \(customActionScheme), customActionName: \(customActionName)")
564-
verifyCustomActionIsCalled(expectation1: expectation1,
565-
customActionScheme: customActionScheme,
563+
verifyCustomActionIsCalled(customActionScheme: customActionScheme,
566564
customActionName: customActionName)
567-
wait(for: [expectation1], timeout: testExpectationTimeout)
568565
}
569566

570567
func testShowInAppWithCustomAction1() {
571568
let customActionScheme = "action"
572569
let customActionName = "my_custom_action"
573-
let expectation1 = expectation(description: "verify custom action is called, customActionScheme: \(customActionScheme), customActionName: \(customActionName)")
574-
verifyCustomActionIsCalled(expectation1: expectation1,
575-
customActionScheme: customActionScheme,
570+
verifyCustomActionIsCalled(customActionScheme: customActionScheme,
576571
customActionName: customActionName)
577-
wait(for: [expectation1], timeout: testExpectationTimeout)
578572
}
579573

580574
// Check that onNew is called just once if the messageId is same.
@@ -1368,8 +1362,9 @@ class InAppTests: XCTestCase {
13681362
wait(for: [expectation1], timeout: testExpectationTimeout)
13691363
}
13701364

1371-
fileprivate func verifyCustomActionIsCalled(expectation1: XCTestExpectation, customActionScheme: String, customActionName: String) {
1372-
let expectation2 = expectation(description: "correct number of messages")
1365+
fileprivate func verifyCustomActionIsCalled(customActionScheme: String, customActionName: String) {
1366+
let expectation1 = expectation(description: "ensure correct number of messages")
1367+
let expectation2 = expectation(description: "verify custom action is called, customActionScheme: \(customActionScheme), customActionName: \(customActionName)")
13731368

13741369
let mockInAppFetcher = MockInAppFetcher()
13751370

@@ -1382,7 +1377,7 @@ class InAppTests: XCTestCase {
13821377
let mockCustomActionDelegate = MockCustomActionDelegate(returnValue: true)
13831378
mockCustomActionDelegate.callback = { actionName, _ in
13841379
XCTAssertEqual(actionName, customActionName)
1385-
expectation1.fulfill()
1380+
expectation2.fulfill()
13861381
}
13871382

13881383
let config = IterableConfig()
@@ -1416,10 +1411,10 @@ class InAppTests: XCTestCase {
14161411
}
14171412
let messages = internalApi.inAppManager.getMessages()
14181413
XCTAssertEqual(messages.count, 1)
1419-
expectation2.fulfill()
1414+
expectation1.fulfill()
14201415
}
14211416

1422-
wait(for: [expectation2], timeout: testExpectationTimeout)
1417+
wait(for: [expectation1, expectation2], timeout: testExpectationTimeout, enforceOrder: true)
14231418
}
14241419
}
14251420

0 commit comments

Comments
 (0)