33
33
34
34
import com .google .android .gms .tasks .Task ;
35
35
import com .google .android .gms .tasks .Tasks ;
36
+ import com .google .firebase .concurrent .TestOnlyExecutors ;
37
+ import com .google .firebase .crashlytics .internal .CrashlyticsWorker ;
36
38
import com .google .firebase .crashlytics .internal .metadata .LogFileManager ;
37
39
import com .google .firebase .crashlytics .internal .metadata .UserMetadata ;
38
40
import com .google .firebase .crashlytics .internal .model .CrashlyticsReport ;
@@ -69,6 +71,8 @@ public class SessionReportingCoordinatorTest {
69
71
70
72
private SessionReportingCoordinator reportingCoordinator ;
71
73
74
+ private CrashlyticsWorker diskWriteWorker = new CrashlyticsWorker (TestOnlyExecutors .background ());
75
+
72
76
@ Before
73
77
public void setUp () {
74
78
MockitoAnnotations .initMocks (this );
@@ -80,7 +84,8 @@ public void setUp() {
80
84
reportSender ,
81
85
logFileManager ,
82
86
reportMetadata ,
83
- idManager );
87
+ idManager ,
88
+ diskWriteWorker );
84
89
}
85
90
86
91
@ Test
@@ -116,7 +121,8 @@ public void testFatalEvent_persistsHighPriorityEventWithAllThreadsForSessionId()
116
121
}
117
122
118
123
@ Test
119
- public void testNonFatalEvent_persistsNormalPriorityEventWithoutAllThreadsForSessionId () {
124
+ public void testNonFatalEvent_persistsNormalPriorityEventWithoutAllThreadsForSessionId ()
125
+ throws Exception {
120
126
final String eventType = "error" ;
121
127
final String sessionId = "testSessionId" ;
122
128
final long timestamp = System .currentTimeMillis ();
@@ -126,6 +132,8 @@ public void testNonFatalEvent_persistsNormalPriorityEventWithoutAllThreadsForSes
126
132
reportingCoordinator .onBeginSession (sessionId , timestamp );
127
133
reportingCoordinator .persistNonFatalEvent (mockException , mockThread , sessionId , timestamp );
128
134
135
+ diskWriteWorker .await ();
136
+
129
137
final boolean expectedAllThreads = false ;
130
138
final boolean expectedHighPriority = false ;
131
139
@@ -136,7 +144,7 @@ public void testNonFatalEvent_persistsNormalPriorityEventWithoutAllThreadsForSes
136
144
}
137
145
138
146
@ Test
139
- public void testNonFatalEvent_addsLogsToEvent () {
147
+ public void testNonFatalEvent_addsLogsToEvent () throws Exception {
140
148
long timestamp = System .currentTimeMillis ();
141
149
142
150
mockEventInteractions ();
@@ -149,14 +157,16 @@ public void testNonFatalEvent_addsLogsToEvent() {
149
157
reportingCoordinator .onBeginSession (sessionId , timestamp );
150
158
reportingCoordinator .persistNonFatalEvent (mockException , mockThread , sessionId , timestamp );
151
159
160
+ diskWriteWorker .await ();
161
+
152
162
verify (mockEventBuilder )
153
163
.setLog (CrashlyticsReport .Session .Event .Log .builder ().setContent (testLog ).build ());
154
164
verify (mockEventBuilder ).build ();
155
165
verify (logFileManager , never ()).clearLog ();
156
166
}
157
167
158
168
@ Test
159
- public void testNonFatalEvent_addsNoLogsToEventWhenNoneAvailable () {
169
+ public void testNonFatalEvent_addsNoLogsToEventWhenNoneAvailable () throws Exception {
160
170
long timestamp = System .currentTimeMillis ();
161
171
162
172
mockEventInteractions ();
@@ -168,6 +178,8 @@ public void testNonFatalEvent_addsNoLogsToEventWhenNoneAvailable() {
168
178
reportingCoordinator .onBeginSession (sessionId , timestamp );
169
179
reportingCoordinator .persistNonFatalEvent (mockException , mockThread , sessionId , timestamp );
170
180
181
+ diskWriteWorker .await ();
182
+
171
183
verify (mockEventBuilder , never ()).setLog (any (CrashlyticsReport .Session .Event .Log .class ));
172
184
verify (mockEventBuilder ).build ();
173
185
verify (logFileManager , never ()).clearLog ();
@@ -212,7 +224,7 @@ public void testFatalEvent_addsNoLogsToEventWhenNoneAvailable() {
212
224
}
213
225
214
226
@ Test
215
- public void testNonFatalEvent_addsSortedKeysToEvent () {
227
+ public void testNonFatalEvent_addsSortedKeysToEvent () throws Exception {
216
228
final long timestamp = System .currentTimeMillis ();
217
229
218
230
mockEventInteractions ();
@@ -243,6 +255,8 @@ public void testNonFatalEvent_addsSortedKeysToEvent() {
243
255
reportingCoordinator .onBeginSession (sessionId , timestamp );
244
256
reportingCoordinator .persistNonFatalEvent (mockException , mockThread , sessionId , timestamp );
245
257
258
+ diskWriteWorker .await ();
259
+
246
260
verify (mockEventAppBuilder ).setCustomAttributes (expectedCustomAttributes );
247
261
verify (mockEventAppBuilder ).setInternalKeys (expectedCustomAttributes );
248
262
verify (mockEventAppBuilder ).build ();
@@ -252,7 +266,7 @@ public void testNonFatalEvent_addsSortedKeysToEvent() {
252
266
}
253
267
254
268
@ Test
255
- public void testNonFatalEvent_addsNoKeysToEventWhenNoneAvailable () {
269
+ public void testNonFatalEvent_addsNoKeysToEventWhenNoneAvailable () throws Exception {
256
270
final long timestamp = System .currentTimeMillis ();
257
271
258
272
mockEventInteractions ();
@@ -266,6 +280,8 @@ public void testNonFatalEvent_addsNoKeysToEventWhenNoneAvailable() {
266
280
reportingCoordinator .onBeginSession (sessionId , timestamp );
267
281
reportingCoordinator .persistNonFatalEvent (mockException , mockThread , sessionId , timestamp );
268
282
283
+ diskWriteWorker .await ();
284
+
269
285
verify (mockEventAppBuilder , never ()).setCustomAttributes (anyList ());
270
286
verify (mockEventAppBuilder , never ()).build ();
271
287
verify (mockEventBuilder , never ()).setApp (mockEventApp );
@@ -274,7 +290,7 @@ public void testNonFatalEvent_addsNoKeysToEventWhenNoneAvailable() {
274
290
}
275
291
276
292
@ Test
277
- public void testNonFatalEvent_addRolloutsEvent () {
293
+ public void testNonFatalEvent_addRolloutsEvent () throws Exception {
278
294
long timestamp = System .currentTimeMillis ();
279
295
String sessionId = "testSessionId" ;
280
296
mockEventInteractions ();
@@ -287,6 +303,8 @@ public void testNonFatalEvent_addRolloutsEvent() {
287
303
reportingCoordinator .onBeginSession (sessionId , timestamp );
288
304
reportingCoordinator .persistNonFatalEvent (mockException , mockThread , sessionId , timestamp );
289
305
306
+ diskWriteWorker .await ();
307
+
290
308
verify (mockEventAppBuilder , never ()).setCustomAttributes (anyList ());
291
309
verify (mockEventAppBuilder , never ()).build ();
292
310
verify (mockEventBuilder , never ()).setApp (mockEventApp );
@@ -417,35 +435,6 @@ public void testFatalEvent_addRolloutsToEvent() {
417
435
verify (mockEventBuilder , times (2 )).build ();
418
436
}
419
437
420
- @ Test
421
- public void onLog_writesToLogFileManager () {
422
- long timestamp = System .currentTimeMillis ();
423
- String log = "this is a log" ;
424
-
425
- reportingCoordinator .onLog (timestamp , log );
426
-
427
- verify (logFileManager ).writeToLog (timestamp , log );
428
- }
429
-
430
- @ Test
431
- public void onCustomKey_writesToReportMetadata () {
432
- final String key = "key" ;
433
- final String value = "value" ;
434
-
435
- reportingCoordinator .onCustomKey (key , value );
436
-
437
- verify (reportMetadata ).setCustomKey (key , value );
438
- }
439
-
440
- @ Test
441
- public void onUserId_writesUserToReportMetadata () {
442
- final String userId = "testUser" ;
443
-
444
- reportingCoordinator .onUserId (userId );
445
-
446
- verify (reportMetadata ).setUserId (userId );
447
- }
448
-
449
438
@ Test
450
439
public void testFinalizeSessionWithNativeEvent_createsCrashlyticsReportWithNativePayload () {
451
440
byte [] testBytes = {0 , 2 , 20 , 10 };
0 commit comments