@@ -64,6 +64,7 @@ - (void)testCacheResetAfterEverySuccessfulFetch {
64
64
// Trigger the RC config fetch
65
65
remoteConfig.fetchStatus = FIRRemoteConfigFetchStatusSuccess;
66
66
remoteConfig.lastFetchTime = nil ;
67
+ configFlags.appStartConfigFetchDelayInSeconds = 0.0 ;
67
68
[configFlags update ];
68
69
69
70
// Verify the expected remote config values
@@ -109,10 +110,63 @@ - (void)testConfigUpdate {
109
110
FPRRemoteConfigFlags *configFlags =
110
111
[[FPRRemoteConfigFlags alloc ] initWithRemoteConfig: (FIRRemoteConfig *)remoteConfig];
111
112
remoteConfig.fetchStatus = FIRRemoteConfigFetchStatusSuccess;
113
+ configFlags.appStartConfigFetchDelayInSeconds = 0.0 ;
112
114
[configFlags update ];
113
115
XCTAssertNotNil (configFlags.lastFetchedTime );
114
116
}
115
117
118
+ /* * Validate the configuration update does not happen during app start. */
119
+ - (void )testConfigFetchDoesNotHappenDuringAppStart {
120
+ FPRFakeRemoteConfig *remoteConfig = [[FPRFakeRemoteConfig alloc ] init ];
121
+ remoteConfig.lastFetchTime = nil ;
122
+
123
+ NSTimeInterval appStartConfigFetchDelay = 5.0 ;
124
+ FPRRemoteConfigFlags *configFlags =
125
+ [[FPRRemoteConfigFlags alloc ] initWithRemoteConfig: (FIRRemoteConfig *)remoteConfig];
126
+ remoteConfig.lastFetchTime = nil ;
127
+ configFlags.lastFetchedTime = nil ;
128
+ configFlags.applicationStartTime = [NSDate date ];
129
+ configFlags.appStartConfigFetchDelayInSeconds = appStartConfigFetchDelay;
130
+ configFlags.lastFetchStatus = FIRRemoteConfigFetchStatusNoFetchYet;
131
+
132
+ XCTestExpectation *expectation =
133
+ [self expectationWithDescription: @" Dummy expectation to wait for the fetch delay." ];
134
+ dispatch_after (
135
+ dispatch_time (DISPATCH_TIME_NOW, (int64_t )((appStartConfigFetchDelay - 2 ) * NSEC_PER_SEC)),
136
+ dispatch_get_main_queue (), ^{
137
+ [configFlags update ];
138
+ [expectation fulfill ];
139
+ XCTAssertTrue (configFlags.lastFetchStatus == FIRRemoteConfigFetchStatusNoFetchYet);
140
+ });
141
+ [self waitForExpectationsWithTimeout: (appStartConfigFetchDelay) handler: nil ];
142
+ }
143
+
144
+ /* * Validate the configuration update happens after a delay during app start. */
145
+ - (void )testConfigFetchAfterDelayDuringAppStart {
146
+ FPRFakeRemoteConfig *remoteConfig = [[FPRFakeRemoteConfig alloc ] init ];
147
+ remoteConfig.lastFetchTime = nil ;
148
+
149
+ NSTimeInterval appStartConfigFetchDelay = 3.0 ;
150
+ FPRRemoteConfigFlags *configFlags =
151
+ [[FPRRemoteConfigFlags alloc ] initWithRemoteConfig: (FIRRemoteConfig *)remoteConfig];
152
+ remoteConfig.lastFetchTime = nil ;
153
+ configFlags.lastFetchedTime = nil ;
154
+ configFlags.applicationStartTime = [NSDate date ];
155
+ configFlags.appStartConfigFetchDelayInSeconds = appStartConfigFetchDelay;
156
+ configFlags.lastFetchStatus = FIRRemoteConfigFetchStatusNoFetchYet;
157
+
158
+ XCTestExpectation *expectation =
159
+ [self expectationWithDescription: @" Dummy expectation to wait for the fetch delay." ];
160
+ dispatch_after (
161
+ dispatch_time (DISPATCH_TIME_NOW, (int64_t )((appStartConfigFetchDelay + 2 ) * NSEC_PER_SEC)),
162
+ dispatch_get_main_queue (), ^{
163
+ [configFlags update ];
164
+ [expectation fulfill ];
165
+ XCTAssertTrue (configFlags.lastFetchStatus == FIRRemoteConfigFetchStatusSuccess);
166
+ });
167
+ [self waitForExpectationsWithTimeout: (appStartConfigFetchDelay + 3 ) handler: nil ];
168
+ }
169
+
116
170
/* * Validate the configuration update does not happen immediately after fetching. */
117
171
- (void )testConfigUpdateDoesNotHappenImmediately {
118
172
FPRFakeRemoteConfig *remoteConfig = [[FPRFakeRemoteConfig alloc ] init ];
@@ -123,6 +177,7 @@ - (void)testConfigUpdateDoesNotHappenImmediately {
123
177
[[FPRRemoteConfigFlags alloc ] initWithRemoteConfig: (FIRRemoteConfig *)remoteConfig];
124
178
125
179
remoteConfig.fetchStatus = FIRRemoteConfigFetchStatusSuccess;
180
+ configFlags.appStartConfigFetchDelayInSeconds = 0.0 ;
126
181
[configFlags update ];
127
182
XCTAssertNotNil (configFlags.lastFetchedTime );
128
183
@@ -146,6 +201,7 @@ - (void)testConfigUpdateHappensIfIntialFetchHasNotHappened {
146
201
[[FPRRemoteConfigFlags alloc ] initWithRemoteConfig: (FIRRemoteConfig *)remoteConfig];
147
202
148
203
remoteConfig.fetchStatus = FIRRemoteConfigFetchStatusSuccess;
204
+ configFlags.appStartConfigFetchDelayInSeconds = 0.0 ;
149
205
[configFlags update ];
150
206
XCTAssertNotNil (configFlags.lastFetchedTime );
151
207
@@ -179,18 +235,21 @@ - (void)testConfigFetchHappensAfterDelay {
179
235
180
236
FPRRemoteConfigFlags *configFlags =
181
237
[[FPRRemoteConfigFlags alloc ] initWithRemoteConfig: (FIRRemoteConfig *)remoteConfig];
238
+ configFlags.appStartConfigFetchDelayInSeconds = 0.0 ;
182
239
183
240
remoteConfig.fetchStatus = FIRRemoteConfigFetchStatusSuccess;
184
241
XCTestExpectation *expectation =
185
242
[self expectationWithDescription: @" Dummy expectation to wait for the fetch delay." ];
186
- dispatch_after (dispatch_time (DISPATCH_TIME_NOW,
187
- (int64_t )((kFPRConfigAppStartDelayInSeconds + 5 ) * NSEC_PER_SEC)),
188
- dispatch_get_main_queue (), ^{
189
- [expectation fulfill ];
190
- XCTAssertNotNil (configFlags.lastFetchedTime );
191
- XCTAssertNotNil (remoteConfig.lastFetchTime );
192
- });
193
- [self waitForExpectationsWithTimeout: (kFPRConfigAppStartDelayInSeconds + 6 ) handler: nil ];
243
+ dispatch_after (
244
+ dispatch_time (DISPATCH_TIME_NOW,
245
+ (int64_t )((kFPRMinAppStartConfigFetchDelayInSeconds + 5 ) * NSEC_PER_SEC)),
246
+ dispatch_get_main_queue (), ^{
247
+ [configFlags update ];
248
+ [expectation fulfill ];
249
+ XCTAssertNotNil (configFlags.lastFetchedTime );
250
+ XCTAssertNotNil (remoteConfig.lastFetchTime );
251
+ });
252
+ [self waitForExpectationsWithTimeout: (kFPRMinAppStartConfigFetchDelayInSeconds + 6 ) handler: nil ];
194
253
}
195
254
196
255
#pragma mark - App config related tests
0 commit comments