@@ -122,4 +122,77 @@ - (void)test_settingSessionIDOutOfOrder_protoHasLastSessionID {
122
122
XCTAssertEqualObjects (adapter.identity .app_quality_session_id , TestContextSessionID2);
123
123
}
124
124
125
+ - (void )test_promisesChainOnInitPromiseInOrder {
126
+ NSMutableArray <NSString *> *result = @[].mutableCopy ;
127
+ NSMutableArray <NSString *> *expectation = @[].mutableCopy ;
128
+
129
+ for (int j = 0 ; j < 100 ; j++) {
130
+ [expectation addObject: [NSString stringWithFormat: @" %d " , j]];
131
+ }
132
+
133
+ FBLPromise *promise = [self .contextManager setupContextWithReport: self .report
134
+ settings: self .mockSettings
135
+ fileManager: self .fileManager];
136
+
137
+ for (int i = 0 ; i < 100 ; i++) {
138
+ [promise then: ^id _Nullable (id _Nullable value) {
139
+ [result addObject: [NSString stringWithFormat: @" %d " , i]];
140
+ if (i == 99 ) {
141
+ XCTAssertTrue ([result isEqualToArray: expectation]);
142
+ }
143
+ return nil ;
144
+ }];
145
+ }
146
+ }
147
+
148
+ // Check Promise behaviour
149
+ - (void )test_promisesChainOnResolvedPromiseInOrder {
150
+ NSMutableArray <NSString *> *result = @[].mutableCopy ;
151
+ NSMutableArray <NSString *> *expectation = @[].mutableCopy ;
152
+
153
+ for (int j = 0 ; j < 100 ; j++) {
154
+ [expectation addObject: [NSString stringWithFormat: @" %d " , j]];
155
+ }
156
+
157
+ FBLPromise *promise = [FBLPromise pendingPromise ];
158
+ // promise fullfiled before task queued up
159
+ [promise fulfill: nil ];
160
+
161
+ for (int i = 0 ; i < 100 ; i++) {
162
+ [promise then: ^id _Nullable (id _Nullable value) {
163
+ [result addObject: [NSString stringWithFormat: @" %d " , i]];
164
+ if (i == 99 ) {
165
+ XCTAssertTrue ([result isEqualToArray: expectation]);
166
+ }
167
+ return nil ;
168
+ }];
169
+ }
170
+ }
171
+
172
+ // Check Promise behaviour
173
+ - (void )test_promisesChainOnPendingPromiseInOrder {
174
+ NSMutableArray <NSString *> *result = @[].mutableCopy ;
175
+ NSMutableArray <NSString *> *expectation = @[].mutableCopy ;
176
+
177
+ for (int j = 0 ; j < 100 ; j++) {
178
+ [expectation addObject: [NSString stringWithFormat: @" %d " , j]];
179
+ }
180
+
181
+ FBLPromise *promise = [FBLPromise pendingPromise ];
182
+ for (int i = 0 ; i < 100 ; i++) {
183
+ [promise then: ^id _Nullable (id _Nullable value) {
184
+ [result addObject: [NSString stringWithFormat: @" %d " , i]];
185
+ if (i == 99 ) {
186
+ XCTAssertTrue ([result isEqualToArray: expectation]);
187
+ }
188
+ return nil ;
189
+ }];
190
+
191
+ if (i == 99 ) {
192
+ // fullfill after a list of task on queued
193
+ [promise fulfill: nil ];
194
+ }
195
+ }
196
+ }
197
+
125
198
@end
0 commit comments