Skip to content

Commit ec8c005

Browse files
committed
user action refactor
1 parent 705d7a3 commit ec8c005

File tree

10 files changed

+275
-135
lines changed

10 files changed

+275
-135
lines changed

firebase-crashlytics/firebase-crashlytics.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ dependencies {
9898
testImplementation(libs.mockito.core)
9999
testImplementation(libs.robolectric)
100100
testImplementation(libs.truth)
101+
testImplementation(project(":integ-testing"))
101102

102103
androidTestImplementation(libs.androidx.test.core)
103104
androidTestImplementation(libs.androidx.test.runner)

firebase-crashlytics/src/androidTest/java/com/google/firebase/crashlytics/internal/common/CrashlyticsControllerTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@
3434
import com.google.android.gms.tasks.TaskCompletionSource;
3535
import com.google.android.gms.tasks.Tasks;
3636
import com.google.firebase.FirebaseApp;
37+
import com.google.firebase.concurrent.TestOnlyExecutors;
3738
import com.google.firebase.crashlytics.internal.CrashlyticsNativeComponent;
3839
import com.google.firebase.crashlytics.internal.CrashlyticsTestCase;
40+
import com.google.firebase.crashlytics.internal.CrashlyticsWorker;
3941
import com.google.firebase.crashlytics.internal.DevelopmentPlatformProvider;
4042
import com.google.firebase.crashlytics.internal.NativeSessionFileProvider;
4143
import com.google.firebase.crashlytics.internal.analytics.AnalyticsEventLogger;
@@ -179,7 +181,8 @@ public CrashlyticsController build() {
179181
sessionReportingCoordinator,
180182
nativeComponent,
181183
analyticsEventLogger,
182-
mock(CrashlyticsAppQualitySessionsSubscriber.class));
184+
mock(CrashlyticsAppQualitySessionsSubscriber.class),
185+
new CrashlyticsWorker(TestOnlyExecutors.background()));
183186
return controller;
184187
}
185188
}

firebase-crashlytics/src/androidTest/java/com/google/firebase/crashlytics/internal/common/CrashlyticsCoreInitializationTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.google.android.gms.tasks.Tasks;
2828
import com.google.firebase.FirebaseApp;
2929
import com.google.firebase.FirebaseOptions;
30+
import com.google.firebase.concurrent.TestOnlyExecutors;
3031
import com.google.firebase.crashlytics.internal.CrashlyticsNativeComponent;
3132
import com.google.firebase.crashlytics.internal.CrashlyticsNativeComponentDeferredProxy;
3233
import com.google.firebase.crashlytics.internal.CrashlyticsTestCase;
@@ -144,7 +145,8 @@ public CrashlyticsCore build() {
144145
fileStore,
145146
crashHandlerExecutor,
146147
mock(CrashlyticsAppQualitySessionsSubscriber.class),
147-
mock(RemoteConfigDeferredProxy.class));
148+
mock(RemoteConfigDeferredProxy.class),
149+
TestOnlyExecutors.background());
148150
}
149151
}
150152

firebase-crashlytics/src/androidTest/java/com/google/firebase/crashlytics/internal/common/CrashlyticsCoreTest.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.google.android.gms.tasks.Tasks;
2929
import com.google.firebase.FirebaseApp;
3030
import com.google.firebase.FirebaseOptions;
31+
import com.google.firebase.concurrent.TestOnlyExecutors;
3132
import com.google.firebase.crashlytics.BuildConfig;
3233
import com.google.firebase.crashlytics.internal.CrashlyticsNativeComponent;
3334
import com.google.firebase.crashlytics.internal.CrashlyticsNativeComponentDeferredProxy;
@@ -91,7 +92,7 @@ public void testCustomAttributes() throws Exception {
9192

9293
final String id = "id012345";
9394
crashlyticsCore.setUserId(id);
94-
95+
crashlyticsCore.commonWorker.await();
9596
assertEquals(id, metadata.getUserId());
9697

9798
final StringBuffer idBuffer = new StringBuffer(id);
@@ -102,11 +103,13 @@ public void testCustomAttributes() throws Exception {
102103
final String superLongId = longId + "more chars";
103104

104105
crashlyticsCore.setUserId(superLongId);
106+
crashlyticsCore.commonWorker.await();
105107
assertEquals(longId, metadata.getUserId());
106108

107109
final String key1 = "key1";
108110
final String value1 = "value1";
109111
crashlyticsCore.setCustomKey(key1, value1);
112+
crashlyticsCore.commonWorker.await();
110113
assertEquals(value1, metadata.getCustomKeys().get(key1));
111114

112115
// Adding an existing key with the same value should return false
@@ -120,6 +123,7 @@ public void testCustomAttributes() throws Exception {
120123

121124
// test truncation of custom keys and attributes
122125
crashlyticsCore.setCustomKey(superLongId, superLongValue);
126+
crashlyticsCore.commonWorker.await();
123127
assertNull(metadata.getCustomKeys().get(superLongId));
124128
assertEquals(longValue, metadata.getCustomKeys().get(longId));
125129

@@ -128,23 +132,28 @@ public void testCustomAttributes() throws Exception {
128132
final String key = "key" + i;
129133
final String value = "value" + i;
130134
crashlyticsCore.setCustomKey(key, value);
135+
crashlyticsCore.commonWorker.await();
131136
assertEquals(value, metadata.getCustomKeys().get(key));
132137
}
133138
// should be full now, extra key, value pairs will be dropped.
134139
final String key = "new key";
135140
crashlyticsCore.setCustomKey(key, "some value");
141+
crashlyticsCore.commonWorker.await();
136142
assertFalse(metadata.getCustomKeys().containsKey(key));
137143

138144
// should be able to update existing keys
139145
crashlyticsCore.setCustomKey(key1, longValue);
146+
crashlyticsCore.commonWorker.await();
140147
assertEquals(longValue, metadata.getCustomKeys().get(key1));
141148

142149
// when we set a key to null, it should still exist with an empty value
143150
crashlyticsCore.setCustomKey(key1, null);
151+
crashlyticsCore.commonWorker.await();
144152
assertEquals("", metadata.getCustomKeys().get(key1));
145153

146154
// keys and values are trimmed.
147155
crashlyticsCore.setCustomKey(" " + key1 + " ", " " + longValue + " ");
156+
crashlyticsCore.commonWorker.await();
148157
assertTrue(metadata.getCustomKeys().containsKey(key1));
149158
assertEquals(longValue, metadata.getCustomKeys().get(key1));
150159
}
@@ -195,6 +204,7 @@ public void testBulkCustomKeys() throws Exception {
195204
keysAndValues.put(intKey, String.valueOf(intValue));
196205

197206
crashlyticsCore.setCustomKeys(keysAndValues);
207+
crashlyticsCore.commonWorker.await();
198208

199209
assertEquals(stringValue, metadata.getCustomKeys().get(stringKey));
200210
assertEquals(trimmedValue, metadata.getCustomKeys().get(trimmedKey));
@@ -215,6 +225,7 @@ public void testBulkCustomKeys() throws Exception {
215225
addlKeysAndValues.put(key, value);
216226
}
217227
crashlyticsCore.setCustomKeys(addlKeysAndValues);
228+
crashlyticsCore.commonWorker.await();
218229

219230
// Ensure all keys have been set
220231
assertEquals(UserMetadata.MAX_ATTRIBUTES, metadata.getCustomKeys().size(), DELTA);
@@ -232,6 +243,7 @@ public void testBulkCustomKeys() throws Exception {
232243
extraKeysAndValues.put(key, value);
233244
}
234245
crashlyticsCore.setCustomKeys(extraKeysAndValues);
246+
crashlyticsCore.commonWorker.await();
235247

236248
// Make sure the extra keys were not added
237249
for (int i = UserMetadata.MAX_ATTRIBUTES; i < UserMetadata.MAX_ATTRIBUTES + 10; ++i) {
@@ -257,6 +269,7 @@ public void testBulkCustomKeys() throws Exception {
257269
updatedKeysAndValues.put(intKey, String.valueOf(updatedIntValue));
258270

259271
crashlyticsCore.setCustomKeys(updatedKeysAndValues);
272+
crashlyticsCore.commonWorker.await();
260273

261274
assertEquals(updatedStringValue, metadata.getCustomKeys().get(stringKey));
262275
assertFalse(Boolean.parseBoolean(metadata.getCustomKeys().get(booleanKey)));
@@ -429,7 +442,8 @@ CrashlyticsCore build(Context context) {
429442
new FileStore(context),
430443
new SameThreadExecutorService(),
431444
mock(CrashlyticsAppQualitySessionsSubscriber.class),
432-
mock(RemoteConfigDeferredProxy.class));
445+
mock(RemoteConfigDeferredProxy.class),
446+
TestOnlyExecutors.background());
433447
return crashlyticsCore;
434448
}
435449
}

0 commit comments

Comments
 (0)