Skip to content

Commit 44f99b4

Browse files
Fix more memory leaks in unit tests
1 parent 3794160 commit 44f99b4

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

tests/swift-sdk-swift-tests/InAppTests.swift

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -621,10 +621,18 @@ class InAppTests: XCTestCase {
621621
inAppFetcher: mockInAppFetcher
622622
)
623623

624-
mockInAppFetcher.mockInAppPayloadFromServer(internalApi: internalApi, TestInAppPayloadGenerator.createPayloadWithUrl(numMessages: 3)).onSuccess { _ in
624+
mockInAppFetcher.mockInAppPayloadFromServer(internalApi: internalApi, TestInAppPayloadGenerator.createPayloadWithUrl(numMessages: 3)).onSuccess { [weak internalApi] _ in
625+
guard let internalApi = internalApi else {
626+
XCTFail("Expected internalApi to be not nil")
627+
return
628+
}
625629
XCTAssertEqual(internalApi.inAppManager.getMessages().count, 3)
626630
expectation1.fulfill()
627-
mockInAppFetcher.mockInAppPayloadFromServer(internalApi: internalApi, TestInAppPayloadGenerator.createPayloadWithUrl(numMessages: 2)).onSuccess { _ in
631+
mockInAppFetcher.mockInAppPayloadFromServer(internalApi: internalApi, TestInAppPayloadGenerator.createPayloadWithUrl(numMessages: 2)).onSuccess { [weak internalApi] _ in
632+
guard let internalApi = internalApi else {
633+
XCTFail("Expected internalApi to be not nil")
634+
return
635+
}
628636
XCTAssertEqual(internalApi.inAppManager.getMessages().count, 2)
629637
expectation2.fulfill()
630638
}
@@ -1043,7 +1051,11 @@ class InAppTests: XCTestCase {
10431051
inAppPersister: InAppFilePersister()
10441052
)
10451053

1046-
mockInAppFetcher.mockInAppPayloadFromServer(internalApi: internalApi1, TestInAppPayloadGenerator.createPayloadWithUrl(indices: [1, 3, 2])).onSuccess { _ in
1054+
mockInAppFetcher.mockInAppPayloadFromServer(internalApi: internalApi1, TestInAppPayloadGenerator.createPayloadWithUrl(indices: [1, 3, 2])).onSuccess { [weak internalApi1] _ in
1055+
guard let internalApi1 = internalApi1 else {
1056+
XCTFail("Expected internalApi to be not nil")
1057+
return
1058+
}
10471059
XCTAssertEqual(internalApi1.inAppManager.getMessages().count, 3)
10481060
expectation1.fulfill()
10491061
}
@@ -1234,7 +1246,11 @@ class InAppTests: XCTestCase {
12341246
}
12351247
""".toJsonDict()
12361248

1237-
mockInAppFetcher.mockInAppPayloadFromServer(internalApi: internalApi, payloadFromServer).onSuccess { _ in
1249+
mockInAppFetcher.mockInAppPayloadFromServer(internalApi: internalApi, payloadFromServer).onSuccess { [weak internalApi] _ in
1250+
guard let internalApi = internalApi else {
1251+
XCTFail("Expected internalApi to be not nil")
1252+
return
1253+
}
12381254
let messages = internalApi.inAppManager.getInboxMessages()
12391255
XCTAssertEqual(messages.count, 2)
12401256

@@ -1359,7 +1375,11 @@ class InAppTests: XCTestCase {
13591375
campaignId: 1,
13601376
expiresAt: mockDateProvider.currentDate.addingTimeInterval(1.0 * 60.0), // one minute from now
13611377
content: IterableHtmlInAppContent(edgeInsets: .zero, backgroundAlpha: 0.0, html: "<html></html>"))
1362-
mockInAppFetcher.mockMessagesAvailableFromServer(internalApi: internalApi, messages: [message]).onSuccess { _ in
1378+
mockInAppFetcher.mockMessagesAvailableFromServer(internalApi: internalApi, messages: [message]).onSuccess { [weak internalApi] _ in
1379+
guard let internalApi = internalApi else {
1380+
XCTFail("Expected internalApi to be not nil")
1381+
return
1382+
}
13631383
XCTAssertEqual(internalApi.inAppManager.getMessages().count, 1)
13641384

13651385
mockDateProvider.currentDate = mockDateProvider.currentDate.addingTimeInterval(2.0 * 60) // two minutes from now

0 commit comments

Comments
 (0)