@@ -57,6 +57,9 @@ final class UserConcurrencyTests: XCTestCase {
5757 /* Setup */
5858 OneSignalCoreImpl . setSharedClient ( MockOneSignalClient ( ) )
5959
60+ // Set JWT to off, before accessing the User Manager
61+ OneSignalUserManagerImpl . sharedInstance. setRequiresUserAuth ( false )
62+
6063 /* When */
6164
6265 // 1. Enqueue 10 Deltas to the Operation Repo
@@ -68,7 +71,7 @@ final class UserConcurrencyTests: XCTestCase {
6871 for _ in 1 ... 4 {
6972 DispatchQueue . global ( ) . async {
7073 print ( " 🧪 flushDeltaQueue on thread \( Thread . current) " )
71- OSOperationRepo . sharedInstance. addFlushDeltaQueueToDispatchQueue ( )
74+ OneSignalUserManagerImpl . sharedInstance. operationRepo . addFlushDeltaQueueToDispatchQueue ( )
7275 }
7376 }
7477
@@ -82,6 +85,7 @@ final class UserConcurrencyTests: XCTestCase {
8285 This test reproduces a crash in the Subscription Executor.
8386 It is possible for two threads to modify and cache queues concurrently.
8487 */
88+ // TODO: revisit this test once subscriptions are addressed for JWT
8589 func testSubscriptionExecutorConcurrency( ) throws {
8690 /* Setup */
8791
@@ -92,18 +96,20 @@ final class UserConcurrencyTests: XCTestCase {
9296 )
9397 OneSignalCoreImpl . setSharedClient ( client)
9498
95- let executor = OSSubscriptionOperationExecutor ( newRecordsState: OSNewRecordsState ( ) )
96- OSOperationRepo . sharedInstance. addExecutor ( executor)
99+ let jwtConfig = OSUserJwtConfig ( )
100+ let executor = OSSubscriptionOperationExecutor ( newRecordsState: OSNewRecordsState ( ) , jwtConfig: jwtConfig)
101+ let operationRepo = OSOperationRepo ( jwtConfig: jwtConfig)
102+ operationRepo. addExecutor ( executor)
97103
98104 /* When */
99105
100106 DispatchQueue . concurrentPerform ( iterations: 50 ) { _ in
101107 // 1. Enqueue Remove Subscription Deltas to the Operation Repo
102- OSOperationRepo . sharedInstance . enqueueDelta ( OSDelta ( name: OS_REMOVE_SUBSCRIPTION_DELTA, identityModelId: UUID ( ) . uuidString, model: OSSubscriptionModel ( type: . email, address: nil , subscriptionId: UUID ( ) . uuidString, reachable: true , isDisabled: false , changeNotifier: OSEventProducer ( ) ) , property: " email " , value: " email " ) )
103- OSOperationRepo . sharedInstance . enqueueDelta ( OSDelta ( name: OS_REMOVE_SUBSCRIPTION_DELTA, identityModelId: UUID ( ) . uuidString, model: OSSubscriptionModel ( type: . email, address: nil , subscriptionId: UUID ( ) . uuidString, reachable: true , isDisabled: false , changeNotifier: OSEventProducer ( ) ) , property: " email " , value: " email " ) )
108+ operationRepo . enqueueDelta ( OSDelta ( name: OS_REMOVE_SUBSCRIPTION_DELTA, identityModelId: UUID ( ) . uuidString, model: OSSubscriptionModel ( type: . email, address: nil , subscriptionId: UUID ( ) . uuidString, reachable: true , isDisabled: false , changeNotifier: OSEventProducer ( ) ) , property: " email " , value: " email " ) )
109+ operationRepo . enqueueDelta ( OSDelta ( name: OS_REMOVE_SUBSCRIPTION_DELTA, identityModelId: UUID ( ) . uuidString, model: OSSubscriptionModel ( type: . email, address: nil , subscriptionId: UUID ( ) . uuidString, reachable: true , isDisabled: false , changeNotifier: OSEventProducer ( ) ) , property: " email " , value: " email " ) )
104110
105111 // 2. Flush Operation Repo
106- OSOperationRepo . sharedInstance . addFlushDeltaQueueToDispatchQueue ( )
112+ operationRepo . addFlushDeltaQueueToDispatchQueue ( )
107113
108114 // 3. Simulate updating the executor's request queue from a network response
109115 executor. executeDeleteSubscriptionRequest ( OSRequestDeleteSubscription ( subscriptionModel: OSSubscriptionModel ( type: . email, address: nil , subscriptionId: UUID ( ) . uuidString, reachable: true , isDisabled: false , changeNotifier: OSEventProducer ( ) ) ) , inBackground: false )
@@ -117,6 +123,8 @@ final class UserConcurrencyTests: XCTestCase {
117123 // Previously caused crash: signal SIGABRT - malloc: double free for ptr
118124 // Assert that every request SDK makes has a response set, and is handled
119125 XCTAssertTrue ( client. allRequestsHandled)
126+ // Ensure the requests are actually made, future proofing
127+ XCTAssertEqual ( client. executedRequests. count, 200 )
120128 }
121129
122130 /**
@@ -131,18 +139,22 @@ final class UserConcurrencyTests: XCTestCase {
131139 OneSignalCoreImpl . setSharedClient ( client)
132140 MockUserRequests . setAddAliasesResponse ( with: client, aliases: aliases)
133141
134- let executor = OSIdentityOperationExecutor ( newRecordsState: OSNewRecordsState ( ) )
135- OSOperationRepo . sharedInstance. addExecutor ( executor)
142+ // Set User Manager's JWT to off, or it blocks requests
143+ OneSignalUserManagerImpl . sharedInstance. setRequiresUserAuth ( false )
144+
145+ let executor = OSIdentityOperationExecutor ( newRecordsState: OSNewRecordsState ( ) , jwtConfig: OneSignalUserManagerImpl . sharedInstance. jwtConfig)
146+ let operationRepo = OSOperationRepo ( jwtConfig: OneSignalUserManagerImpl . sharedInstance. jwtConfig)
147+ operationRepo. addExecutor ( executor)
136148
137149 /* When */
138150
139151 DispatchQueue . concurrentPerform ( iterations: 50 ) { _ in
140152 // 1. Enqueue Add Alias Deltas to the Operation Repo
141- OSOperationRepo . sharedInstance . enqueueDelta ( OSDelta ( name: OS_ADD_ALIAS_DELTA, identityModelId: UUID ( ) . uuidString, model: OSIdentityModel ( aliases: [ OS_ONESIGNAL_ID: UUID ( ) . uuidString] , changeNotifier: OSEventProducer ( ) ) , property: " aliases " , value: aliases) )
142- OSOperationRepo . sharedInstance . enqueueDelta ( OSDelta ( name: OS_ADD_ALIAS_DELTA, identityModelId: UUID ( ) . uuidString, model: OSIdentityModel ( aliases: [ OS_ONESIGNAL_ID: UUID ( ) . uuidString] , changeNotifier: OSEventProducer ( ) ) , property: " aliases " , value: aliases) )
153+ operationRepo . enqueueDelta ( OSDelta ( name: OS_ADD_ALIAS_DELTA, identityModelId: UUID ( ) . uuidString, model: OSIdentityModel ( aliases: [ OS_ONESIGNAL_ID: UUID ( ) . uuidString] , changeNotifier: OSEventProducer ( ) ) , property: " aliases " , value: aliases) )
154+ operationRepo . enqueueDelta ( OSDelta ( name: OS_ADD_ALIAS_DELTA, identityModelId: UUID ( ) . uuidString, model: OSIdentityModel ( aliases: [ OS_ONESIGNAL_ID: UUID ( ) . uuidString] , changeNotifier: OSEventProducer ( ) ) , property: " aliases " , value: aliases) )
143155
144156 // 2. Flush Operation Repo
145- OSOperationRepo . sharedInstance . addFlushDeltaQueueToDispatchQueue ( )
157+ operationRepo . addFlushDeltaQueueToDispatchQueue ( )
146158
147159 // 3. Simulate updating the executor's request queue from a network response
148160 executor. executeAddAliasesRequest ( OSRequestAddAliases ( aliases: aliases, identityModel: OSIdentityModel ( aliases: [ OS_ONESIGNAL_ID: UUID ( ) . uuidString] , changeNotifier: OSEventProducer ( ) ) ) , inBackground: false )
@@ -156,6 +168,8 @@ final class UserConcurrencyTests: XCTestCase {
156168 // Previously caused crash: signal SIGABRT - malloc: double free for ptr
157169 // Assert that every request SDK makes has a response set, and is handled
158170 XCTAssertTrue ( client. allRequestsHandled)
171+ // Ensure the requests are actually made, future proofing
172+ XCTAssertGreaterThanOrEqual ( client. executedRequests. count, 150 )
159173 }
160174
161175 /**
@@ -169,21 +183,24 @@ final class UserConcurrencyTests: XCTestCase {
169183 client. fireSuccessForAllRequests = true
170184 OneSignalCoreImpl . setSharedClient ( client)
171185
186+ // Set JWT to off, before accessing the User Manager
187+ OneSignalUserManagerImpl . sharedInstance. setRequiresUserAuth ( false )
188+
172189 let identityModel = OSIdentityModel ( aliases: [ OS_ONESIGNAL_ID: UUID ( ) . uuidString] , changeNotifier: OSEventProducer ( ) )
173190 OneSignalUserManagerImpl . sharedInstance. addIdentityModelToRepo ( identityModel)
174191
175- let executor = OSPropertyOperationExecutor ( newRecordsState: OSNewRecordsState ( ) )
176- OSOperationRepo . sharedInstance. addExecutor ( executor)
192+ let executor = OSPropertyOperationExecutor ( newRecordsState: OSNewRecordsState ( ) , jwtConfig : OneSignalUserManagerImpl . sharedInstance . jwtConfig )
193+ OneSignalUserManagerImpl . sharedInstance. operationRepo . addExecutor ( executor)
177194
178195 /* When */
179196
180197 DispatchQueue . concurrentPerform ( iterations: 50 ) { _ in
181198 // 1. Enqueue Deltas to the Operation Repo
182- OSOperationRepo . sharedInstance. enqueueDelta ( OSDelta ( name: OS_UPDATE_PROPERTIES_DELTA, identityModelId: identityModel. modelId, model: OSPropertiesModel ( changeNotifier: OSEventProducer ( ) ) , property: " language " , value: UUID ( ) . uuidString) )
183- OSOperationRepo . sharedInstance. enqueueDelta ( OSDelta ( name: OS_UPDATE_PROPERTIES_DELTA, identityModelId: identityModel. modelId, model: OSPropertiesModel ( changeNotifier: OSEventProducer ( ) ) , property: " language " , value: UUID ( ) . uuidString) )
199+ OneSignalUserManagerImpl . sharedInstance. operationRepo . enqueueDelta ( OSDelta ( name: OS_UPDATE_PROPERTIES_DELTA, identityModelId: identityModel. modelId, model: OSPropertiesModel ( changeNotifier: OSEventProducer ( ) ) , property: " language " , value: UUID ( ) . uuidString) )
200+ OneSignalUserManagerImpl . sharedInstance. operationRepo . enqueueDelta ( OSDelta ( name: OS_UPDATE_PROPERTIES_DELTA, identityModelId: identityModel. modelId, model: OSPropertiesModel ( changeNotifier: OSEventProducer ( ) ) , property: " language " , value: UUID ( ) . uuidString) )
184201
185202 // 2. Flush Operation Repo
186- OSOperationRepo . sharedInstance. addFlushDeltaQueueToDispatchQueue ( )
203+ OneSignalUserManagerImpl . sharedInstance. operationRepo . addFlushDeltaQueueToDispatchQueue ( )
187204
188205 // 3. Simulate updating the executor's request queue from a network response
189206 executor. executeUpdatePropertiesRequest ( OSRequestUpdateProperties ( params: [ " properties " : [ " language " : UUID ( ) . uuidString] , " refresh_device_metadata " : false ] , identityModel: identityModel) , inBackground: false )
@@ -194,6 +211,8 @@ final class UserConcurrencyTests: XCTestCase {
194211
195212 /* Then */
196213 // No crash
214+ // Ensure the requests are actually made, future proofing
215+ XCTAssertGreaterThanOrEqual ( client. executedRequests. count, 75 )
197216 }
198217
199218 /**
@@ -213,13 +232,16 @@ final class UserConcurrencyTests: XCTestCase {
213232 let identityModel1 = OSIdentityModel ( aliases: [ OS_ONESIGNAL_ID: UUID ( ) . uuidString] , changeNotifier: OSEventProducer ( ) )
214233 let identityModel2 = OSIdentityModel ( aliases: [ OS_ONESIGNAL_ID: UUID ( ) . uuidString] , changeNotifier: OSEventProducer ( ) )
215234
216- let userExecutor = OSUserExecutor ( newRecordsState: OSNewRecordsState ( ) )
235+ // Set User Manager's JWT to off, or it blocks requests
236+ OneSignalUserManagerImpl . sharedInstance. setRequiresUserAuth ( false )
237+
238+ let userExecutor = OSUserExecutor ( newRecordsState: OSNewRecordsState ( ) , jwtConfig: OneSignalUserManagerImpl . sharedInstance. jwtConfig)
217239
218240 /* When */
219241
220242 DispatchQueue . concurrentPerform ( iterations: 50 ) { _ in
221243 let identifyRequest = OSRequestIdentifyUser ( aliasLabel: OS_EXTERNAL_ID, aliasId: UUID ( ) . uuidString, identityModelToIdentify: identityModel1, identityModelToUpdate: identityModel2)
222- let fetchRequest = OSRequestFetchUser ( identityModel: identityModel1, aliasLabel : OS_ONESIGNAL_ID , aliasId : UUID ( ) . uuidString, onNewSession: false )
244+ let fetchRequest = OSRequestFetchUser ( identityModel: identityModel1, onesignalId : UUID ( ) . uuidString, onNewSession: false )
223245
224246 // Append and execute requests simultaneously
225247 userExecutor. appendToQueue ( identifyRequest)
@@ -233,6 +255,8 @@ final class UserConcurrencyTests: XCTestCase {
233255
234256 /* Then */
235257 // No crash
258+ // Ensure the requests are actually made, future proofing
259+ XCTAssertGreaterThanOrEqual ( client. executedRequests. count, 75 )
236260 }
237261
238262 /**
0 commit comments