Skip to content

Commit 35f6ed8

Browse files
committed
add test reproducing crash when encoding models with concurrency
* Adds two tests that encode Identity Model and Properties Model while their aliases and tags dictionary are written to. * The tests try to add data, clear data, and encode these models concurrently
1 parent 8f859e5 commit 35f6ed8

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# in tests, we may want to force cast and throw any errors
22
disabled_rules:
33
- force_cast
4+
- variable_name

iOS_SDK/OneSignalSDK/OneSignalUserTests/OneSignalUserTests.swift

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)