28
28
import com .google .android .gms .tasks .Tasks ;
29
29
import com .google .firebase .FirebaseApp ;
30
30
import com .google .firebase .FirebaseOptions ;
31
+ import com .google .firebase .concurrent .TestOnlyExecutors ;
31
32
import com .google .firebase .crashlytics .BuildConfig ;
32
33
import com .google .firebase .crashlytics .internal .CrashlyticsNativeComponent ;
33
34
import com .google .firebase .crashlytics .internal .CrashlyticsNativeComponentDeferredProxy ;
@@ -91,7 +92,7 @@ public void testCustomAttributes() throws Exception {
91
92
92
93
final String id = "id012345" ;
93
94
crashlyticsCore .setUserId (id );
94
-
95
+ crashlyticsCore . commonWorker . await ();
95
96
assertEquals (id , metadata .getUserId ());
96
97
97
98
final StringBuffer idBuffer = new StringBuffer (id );
@@ -102,11 +103,13 @@ public void testCustomAttributes() throws Exception {
102
103
final String superLongId = longId + "more chars" ;
103
104
104
105
crashlyticsCore .setUserId (superLongId );
106
+ crashlyticsCore .commonWorker .await ();
105
107
assertEquals (longId , metadata .getUserId ());
106
108
107
109
final String key1 = "key1" ;
108
110
final String value1 = "value1" ;
109
111
crashlyticsCore .setCustomKey (key1 , value1 );
112
+ crashlyticsCore .commonWorker .await ();
110
113
assertEquals (value1 , metadata .getCustomKeys ().get (key1 ));
111
114
112
115
// Adding an existing key with the same value should return false
@@ -120,6 +123,7 @@ public void testCustomAttributes() throws Exception {
120
123
121
124
// test truncation of custom keys and attributes
122
125
crashlyticsCore .setCustomKey (superLongId , superLongValue );
126
+ crashlyticsCore .commonWorker .await ();
123
127
assertNull (metadata .getCustomKeys ().get (superLongId ));
124
128
assertEquals (longValue , metadata .getCustomKeys ().get (longId ));
125
129
@@ -128,23 +132,28 @@ public void testCustomAttributes() throws Exception {
128
132
final String key = "key" + i ;
129
133
final String value = "value" + i ;
130
134
crashlyticsCore .setCustomKey (key , value );
135
+ crashlyticsCore .commonWorker .await ();
131
136
assertEquals (value , metadata .getCustomKeys ().get (key ));
132
137
}
133
138
// should be full now, extra key, value pairs will be dropped.
134
139
final String key = "new key" ;
135
140
crashlyticsCore .setCustomKey (key , "some value" );
141
+ crashlyticsCore .commonWorker .await ();
136
142
assertFalse (metadata .getCustomKeys ().containsKey (key ));
137
143
138
144
// should be able to update existing keys
139
145
crashlyticsCore .setCustomKey (key1 , longValue );
146
+ crashlyticsCore .commonWorker .await ();
140
147
assertEquals (longValue , metadata .getCustomKeys ().get (key1 ));
141
148
142
149
// when we set a key to null, it should still exist with an empty value
143
150
crashlyticsCore .setCustomKey (key1 , null );
151
+ crashlyticsCore .commonWorker .await ();
144
152
assertEquals ("" , metadata .getCustomKeys ().get (key1 ));
145
153
146
154
// keys and values are trimmed.
147
155
crashlyticsCore .setCustomKey (" " + key1 + " " , " " + longValue + " " );
156
+ crashlyticsCore .commonWorker .await ();
148
157
assertTrue (metadata .getCustomKeys ().containsKey (key1 ));
149
158
assertEquals (longValue , metadata .getCustomKeys ().get (key1 ));
150
159
}
@@ -195,6 +204,7 @@ public void testBulkCustomKeys() throws Exception {
195
204
keysAndValues .put (intKey , String .valueOf (intValue ));
196
205
197
206
crashlyticsCore .setCustomKeys (keysAndValues );
207
+ crashlyticsCore .commonWorker .await ();
198
208
199
209
assertEquals (stringValue , metadata .getCustomKeys ().get (stringKey ));
200
210
assertEquals (trimmedValue , metadata .getCustomKeys ().get (trimmedKey ));
@@ -215,6 +225,7 @@ public void testBulkCustomKeys() throws Exception {
215
225
addlKeysAndValues .put (key , value );
216
226
}
217
227
crashlyticsCore .setCustomKeys (addlKeysAndValues );
228
+ crashlyticsCore .commonWorker .await ();
218
229
219
230
// Ensure all keys have been set
220
231
assertEquals (UserMetadata .MAX_ATTRIBUTES , metadata .getCustomKeys ().size (), DELTA );
@@ -232,6 +243,7 @@ public void testBulkCustomKeys() throws Exception {
232
243
extraKeysAndValues .put (key , value );
233
244
}
234
245
crashlyticsCore .setCustomKeys (extraKeysAndValues );
246
+ crashlyticsCore .commonWorker .await ();
235
247
236
248
// Make sure the extra keys were not added
237
249
for (int i = UserMetadata .MAX_ATTRIBUTES ; i < UserMetadata .MAX_ATTRIBUTES + 10 ; ++i ) {
@@ -257,6 +269,7 @@ public void testBulkCustomKeys() throws Exception {
257
269
updatedKeysAndValues .put (intKey , String .valueOf (updatedIntValue ));
258
270
259
271
crashlyticsCore .setCustomKeys (updatedKeysAndValues );
272
+ crashlyticsCore .commonWorker .await ();
260
273
261
274
assertEquals (updatedStringValue , metadata .getCustomKeys ().get (stringKey ));
262
275
assertFalse (Boolean .parseBoolean (metadata .getCustomKeys ().get (booleanKey )));
@@ -429,7 +442,8 @@ CrashlyticsCore build(Context context) {
429
442
new FileStore (context ),
430
443
new SameThreadExecutorService (),
431
444
mock (CrashlyticsAppQualitySessionsSubscriber .class ),
432
- mock (RemoteConfigDeferredProxy .class ));
445
+ mock (RemoteConfigDeferredProxy .class ),
446
+ TestOnlyExecutors .background ());
433
447
return crashlyticsCore ;
434
448
}
435
449
}
0 commit comments