File tree Expand file tree Collapse file tree 2 files changed +45
-0
lines changed
iOS_SDK/OneSignalSDK/OneSignalUserTests Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change 11# in tests, we may want to force cast and throw any errors
22disabled_rules :
33 - force_cast
4+ - variable_name
Original file line number Diff line number Diff line change @@ -93,4 +93,48 @@ final class OneSignalUserTests: XCTestCase {
9393 // 1. OpRepo: `deltaQueue.remove(at: index)` index out of bounds
9494 // 2. OSPropertyOperationExecutor: `deltaQueue.append(delta)` EXC_BAD_ACCESS
9595 }
96+
97+ /**
98+ This test reproduced a crash when the property model is being encoded.
99+ */
100+ func testEncodingPropertiesModel_withConcurrency_doesNotCrash( ) throws {
101+ /* Setup */
102+ let propertiesModel = OSPropertiesModel ( changeNotifier: OSEventProducer ( ) )
103+
104+ /* When */
105+ DispatchQueue . concurrentPerform ( iterations: 5_000 ) { i in
106+ // 1. Add tags
107+ for num in 0 ... 9 {
108+ propertiesModel. addTags ( [ " \( i) tag \( num) " : " value " ] )
109+ }
110+
111+ // 2. Encode the model
112+ OneSignalUserDefaults . initShared ( ) . saveCodeableData ( forKey: " PropertyModel " , withValue: propertiesModel)
113+
114+ // 3. Clear the tags
115+ propertiesModel. clearData ( )
116+ }
117+ }
118+
119+ /**
120+ This test reproduced a crash when the identity model is being encoded.
121+ */
122+ func testEncodingIdentityModel_withConcurrency_doesNotCrash( ) throws {
123+ /* Setup */
124+ let identityModel = OSIdentityModel ( aliases: nil , changeNotifier: OSEventProducer ( ) )
125+
126+ /* When */
127+ DispatchQueue . concurrentPerform ( iterations: 5_000 ) { i in
128+ // 1. Add aliases
129+ for num in 0 ... 9 {
130+ identityModel. addAliases ( [ " \( i) alias \( num) " : " value " ] )
131+ }
132+
133+ // 2. Encode the model
134+ OneSignalUserDefaults . initShared ( ) . saveCodeableData ( forKey: " IdentityModel " , withValue: identityModel)
135+
136+ // 2. Clear the aliases
137+ identityModel. clearData ( )
138+ }
139+ }
96140}
You can’t perform that action at this time.
0 commit comments