-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: prevent infinite loop if sdk forwards push event back to itself (…
- Loading branch information
1 parent
216341c
commit cdf2f1f
Showing
2 changed files
with
41 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
Tests/MessagingPush/PushHandling/PushEventHandlerTest.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
@testable import CioMessagingPush | ||
import Foundation | ||
import SharedTests | ||
import XCTest | ||
|
||
class PushEventHandlerTest: UnitTest { | ||
private var pushEventHandler: PushEventHandler! | ||
|
||
private var pushEventHandlerProxy: PushEventHandlerProxy { | ||
diGraph.pushEventHandlerProxy | ||
} | ||
|
||
private var pushClickHandler = PushClickHandlerMock() | ||
|
||
override func setUp() { | ||
super.setUp() | ||
|
||
pushEventHandler = IOSPushEventListener(jsonAdapter: diGraph.jsonAdapter, pushEventHandlerProxy: pushEventHandlerProxy, moduleConfig: MessagingPushConfigOptions(), pushClickHandler: pushClickHandler, pushHistory: diGraph.pushHistory, logger: log) | ||
} | ||
|
||
// MARK: onPushAction | ||
|
||
/* | ||
The CIO SDK push event handler forwards push notifications to other push event handlers in the host app. | ||
But, what if the CIO SDK event handler forwards a push event back to the CIO SDK event handler? This could cause an infinite loop. | ||
This test simulates that scenario to make sure that an inifinite loop would not happen. | ||
*/ | ||
func test_onPushAction_expectNoInfiniteLoopIfSdkForwardsPushEventBacktoSdkAgain() { | ||
// The push event handler proxy is what forwards push events to other push event handlers in the app. | ||
// To test if an infinite loop would happen, add ourself as a push event handler to get events forwarded to. | ||
pushEventHandlerProxy.addPushEventHandler(pushEventHandler) | ||
|
||
// Make sure push is not from CIO otherwise event does not get forwarded. | ||
let givenPush = PushNotificationStub.getPushNotSentFromCIO() | ||
|
||
// Send the CIO SDK push event handler an event. If an infinite loop occurs, this test will timeout or crash. | ||
pushEventHandler.onPushAction(PushNotificationActionStub(push: givenPush, didClickOnPush: true)) {} | ||
} | ||
} |