Skip to content

Commit e95d01c

Browse files
committed
Further simplify the usage of the integration test rule
1 parent bace552 commit e95d01c

File tree

7 files changed

+38
-38
lines changed

7 files changed

+38
-38
lines changed

embrace-android-core/src/test/java/io/embrace/android/embracesdk/internal/ndk/NativeCrashProcessorImplTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ internal class NativeCrashProcessorImplTest {
5454
logger,
5555
delegate,
5656
serializer,
57-
FakeSymbolService(mapOf("symbol1" to "test")),
57+
FakeSymbolService(mutableMapOf("symbol1" to "test")),
5858
lazy { storageDir },
5959
worker
6060
)

embrace-android-sdk/src/integrationTest/kotlin/io/embrace/android/embracesdk/testcases/features/DeliveryConnectivityFeatureTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ internal class DeliveryConnectivityFeatureTest {
3434
val envelope = fakeSessionEnvelope(startMs = startMs)
3535
testRule.runTest(
3636
setupAction = {
37-
networkConnectivityService.networkStatus = NetworkStatus.NOT_REACHABLE
37+
fakeNetworkConnectivityService.networkStatus = NetworkStatus.NOT_REACHABLE
3838
payloadStorageService.addPayload(sessionMetadata, envelope)
3939
payloadStorageServiceProvider = { payloadStorageService }
4040
},
@@ -49,7 +49,7 @@ internal class DeliveryConnectivityFeatureTest {
4949
fun `new payload not sent with no connection`() {
5050
testRule.runTest(
5151
setupAction = {
52-
networkConnectivityService.networkStatus = NetworkStatus.NOT_REACHABLE
52+
fakeNetworkConnectivityService.networkStatus = NetworkStatus.NOT_REACHABLE
5353
},
5454
testCaseAction = {
5555
recordSession()
@@ -67,7 +67,7 @@ internal class DeliveryConnectivityFeatureTest {
6767
val envelope = fakeSessionEnvelope(startMs = startMs)
6868
testRule.runTest(
6969
setupAction = {
70-
networkConnectivityService.networkStatus = NetworkStatus.NOT_REACHABLE
70+
fakeNetworkConnectivityService.networkStatus = NetworkStatus.NOT_REACHABLE
7171
payloadStorageService.addPayload(sessionMetadata, envelope)
7272
payloadStorageServiceProvider = { payloadStorageService }
7373
},

embrace-android-sdk/src/integrationTest/kotlin/io/embrace/android/embracesdk/testcases/features/NativeCrashFeatureTest.kt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ internal class NativeCrashFeatureTest {
9595
envelopeResource = fakeLaterEnvelopeResource,
9696
envelopeMetadata = fakeLaterEnvelopeMetadata
9797
)
98+
private val fakeSymbols = mapOf("libfoo.so" to "symbol_content")
9899

99100
private lateinit var cacheStorageService: FakePayloadStorageService
100101

@@ -105,6 +106,8 @@ internal class NativeCrashFeatureTest {
105106
processIdentifier = "8115ec91-3e5e-4d8a-816d-cc40306f9822"
106107
).apply {
107108
getEmbLogger().throwOnInternalError = false
109+
}.also {
110+
it.fakeSymbolService.symbolsForCurrentArch.putAll(fakeSymbols)
108111
}
109112
}
110113

@@ -135,7 +138,7 @@ internal class NativeCrashFeatureTest {
135138
assertEquals(fakeEnvelopeMetadata, metadata)
136139
}
137140
val log = envelope.getLastLog()
138-
assertNativeCrashSent(log, crashData, testRule.setup.symbols)
141+
assertNativeCrashSent(log, crashData, fakeSymbols)
139142
}
140143
)
141144
}
@@ -159,7 +162,7 @@ internal class NativeCrashFeatureTest {
159162
val envelope = getLogEnvelopes(2)
160163
.single { it.resource == fakeEnvelopeResource && it.metadata == fakeEnvelopeMetadata }
161164
val log = envelope.getLogOfType(EmbType.System.NativeCrash)
162-
assertNativeCrashSent(log, crashData, testRule.setup.symbols)
165+
assertNativeCrashSent(log, crashData, fakeSymbols)
163166
}
164167
)
165168
}
@@ -213,8 +216,8 @@ internal class NativeCrashFeatureTest {
213216
val log1 = crashEnvelope1.getLastLog()
214217
val log2 = crashEnvelope2.getLastLog()
215218

216-
assertNativeCrashSent(log1, crashData, testRule.setup.symbols)
217-
assertNativeCrashSent(log2, crashData2, testRule.setup.symbols)
219+
assertNativeCrashSent(log1, crashData, fakeSymbols)
220+
assertNativeCrashSent(log2, crashData2, fakeSymbols)
218221

219222
// sessions updated to include crash IDs
220223
val session1 = sessionEnvelopes.single { it.getSessionId() == crashData.nativeCrash.sessionId }
@@ -255,7 +258,7 @@ internal class NativeCrashFeatureTest {
255258
setupFakeNativeCrash(serializer, crashData)
256259

257260
// simulate JNI call failing to load struct
258-
jniDelegate.addCrashRaw(crashData.getCrashFile().absolutePath, null)
261+
fakeJniDelegate.addCrashRaw(crashData.getCrashFile().absolutePath, null)
259262
},
260263
testCaseAction = {},
261264
assertAction = {
@@ -276,7 +279,7 @@ internal class NativeCrashFeatureTest {
276279
setupFakeNativeCrash(serializer, crashData)
277280

278281
// simulate bad JSON
279-
jniDelegate.addCrashRaw(crashData.getCrashFile().absolutePath, "{")
282+
fakeJniDelegate.addCrashRaw(crashData.getCrashFile().absolutePath, "{")
280283
},
281284
testCaseAction = {},
282285
assertAction = {

embrace-android-sdk/src/integrationTest/kotlin/io/embrace/android/embracesdk/testcases/features/ResurrectionFeatureTest.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import org.robolectric.annotation.Config
3535
internal class ResurrectionFeatureTest {
3636

3737
private val serializer = TestPlatformSerializer()
38+
private val fakeSymbols = mapOf("libfoo.so" to "symbol_content")
3839
private lateinit var cacheStorageService: FakePayloadStorageService
3940

4041
@Rule
@@ -43,6 +44,8 @@ internal class ResurrectionFeatureTest {
4344
EmbraceSetupInterface().apply {
4445
getEmbLogger().throwOnInternalError = false
4546
cacheStorageService = FakePayloadStorageService(processIdProvider = getProcessIdentifierProvider())
47+
}.also {
48+
it.fakeSymbolService.symbolsForCurrentArch.putAll(fakeSymbols)
4649
}
4750
}
4851

@@ -72,7 +75,7 @@ internal class ResurrectionFeatureTest {
7275
}
7376

7477
val log = envelope.getLastLog()
75-
assertNativeCrashSent(log, crashData, testRule.setup.symbols)
78+
assertNativeCrashSent(log, crashData, fakeSymbols)
7679
}
7780
)
7881
}
@@ -99,7 +102,7 @@ internal class ResurrectionFeatureTest {
99102
}
100103

101104
val log = envelope.getLastLog()
102-
assertNativeCrashSent(log, crashData, testRule.setup.symbols)
105+
assertNativeCrashSent(log, crashData, fakeSymbols)
103106
}
104107
)
105108
}
@@ -135,7 +138,7 @@ internal class ResurrectionFeatureTest {
135138
assertEquals(session.resource, resource)
136139
assertEquals(session.metadata, metadata)
137140
val crash = getLastLog()
138-
assertNativeCrashSent(crash, crashData, testRule.setup.symbols)
141+
assertNativeCrashSent(crash, crashData, fakeSymbols)
139142
}
140143
}
141144
)

embrace-android-sdk/src/integrationTest/kotlin/io/embrace/android/embracesdk/testframework/actions/EmbraceActionInterface.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ internal class EmbraceActionInterface(
4848
}
4949

5050
private fun onForeground() {
51-
setup.lifecycleOwner.handleLifecycleEvent(Lifecycle.Event.ON_START)
51+
setup.fakeLifecycleOwner.handleLifecycleEvent(Lifecycle.Event.ON_START)
5252
}
5353

5454
private fun onBackground() {
55-
setup.lifecycleOwner.handleLifecycleEvent(Lifecycle.Event.ON_STOP)
55+
setup.fakeLifecycleOwner.handleLifecycleEvent(Lifecycle.Event.ON_STOP)
5656
}
5757

5858
fun simulateNetworkChange(status: NetworkStatus) {

embrace-android-sdk/src/integrationTest/kotlin/io/embrace/android/embracesdk/testframework/actions/EmbraceSetupInterface.kt

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,17 @@ import io.embrace.android.embracesdk.testframework.SdkIntegrationTestRule
5050
*/
5151
internal class EmbraceSetupInterface @JvmOverloads constructor(
5252
workerToFake: Worker.Background? = null,
53-
priorityWorkerToFake: Worker.Priority? = null,
5453
anrMonitoringThread: Thread? = null,
5554
processIdentifier: String = "integration-test-process",
5655
var useMockWebServer: Boolean = true,
5756
var cacheStorageServiceProvider: Provider<PayloadStorageService>? = null,
5857
var payloadStorageServiceProvider: Provider<PayloadStorageService>? = null,
59-
val networkConnectivityService: FakeNetworkConnectivityService = FakeNetworkConnectivityService(),
60-
var jniDelegate: FakeJniDelegate = FakeJniDelegate(),
61-
var symbols: Map<String, String> = mapOf("libfoo.so" to "symbol_content"),
62-
val lifecycleOwner: TestLifecycleOwner = TestLifecycleOwner(initialState = Lifecycle.State.INITIALIZED),
6358
) {
59+
val fakeNetworkConnectivityService = FakeNetworkConnectivityService()
60+
val fakeJniDelegate = FakeJniDelegate()
61+
val fakeSymbolService = FakeSymbolService()
62+
val fakeLifecycleOwner: TestLifecycleOwner = TestLifecycleOwner(initialState = Lifecycle.State.INITIALIZED)
63+
6464
private val fakeInitModule: FakeInitModule = FakeInitModule(
6565
clock = FakeClock(currentTime = SdkIntegrationTestRule.DEFAULT_SDK_START_TIME_MS),
6666
logger = FakeEmbLogger(ignoredErrors = mutableListOf(InternalErrorType.PROCESS_STATE_CALLBACK_FAIL)),
@@ -70,7 +70,6 @@ internal class EmbraceSetupInterface @JvmOverloads constructor(
7070
private val workerThreadModule: WorkerThreadModule = initWorkerThreadModule(
7171
fakeInitModule = fakeInitModule,
7272
workerToFake = workerToFake,
73-
priorityWorkerToFake = priorityWorkerToFake,
7473
anrMonitoringThread = anrMonitoringThread
7574
)
7675

@@ -112,8 +111,8 @@ internal class EmbraceSetupInterface @JvmOverloads constructor(
112111
systemServiceModule,
113112
androidServicesModule,
114113
storageModule,
115-
{ lifecycleOwner }
116-
) { networkConnectivityService }
114+
{ fakeLifecycleOwner }
115+
) { fakeNetworkConnectivityService }
117116
},
118117
deliveryModuleSupplier = { configModule, initModule, otelModule, workerThreadModule, coreModule, storageModule, essentialServiceModule, androidServicesModule, _, _, _, _, _ ->
119118
val requestExecutionServiceProvider: Provider<RequestExecutionService>? = when {
@@ -151,9 +150,9 @@ internal class EmbraceSetupInterface @JvmOverloads constructor(
151150
storageModule,
152151
essentialServiceModule,
153152
openTelemetryModule,
154-
{ jniDelegate },
153+
{ fakeJniDelegate },
155154
::FakeSharedObjectLoader,
156-
{ FakeSymbolService(symbols) }
155+
{ fakeSymbolService }
157156
)
158157
},
159158
)
@@ -185,36 +184,32 @@ internal class EmbraceSetupInterface @JvmOverloads constructor(
185184
crashData.getCrashFile().createNewFile()
186185
val key = crashData.getCrashFile().absolutePath
187186
val json = serializer.toJson(crashData.nativeCrash, NativeCrashData::class.java)
188-
jniDelegate.addCrashRaw(key, json)
187+
fakeJniDelegate.addCrashRaw(key, json)
189188
}
190189

191-
fun getContext(): Context = coreModule.context
192-
193190
fun getClock(): FakeClock = checkNotNull(fakeInitModule.getFakeClock())
194191

195192
fun getProcessIdentifierProvider(): () -> String = fakeInitModule.processIdentifierProvider
196193

194+
fun getSpanSink(): SpanSink = fakeInitModule.openTelemetryModule.spanSink
195+
196+
fun getCurrentSessionSpan(): CurrentSessionSpan = fakeInitModule.openTelemetryModule.currentSessionSpan
197+
197198
fun getEmbLogger(): FakeEmbLogger = fakeInitModule.logger as FakeEmbLogger
198199

200+
fun getContext(): Context = coreModule.context
201+
199202
fun getFakedWorkerExecutor(): BlockingScheduledExecutorService =
200203
(workerThreadModule as FakeWorkerThreadModule).executor
201204

202-
fun getFakedPriorityWorkerExecutor(): BlockingScheduledExecutorService =
203-
(workerThreadModule as FakeWorkerThreadModule).priorityWorkerExecutor
204-
205205
fun getBlockedThreadDetector(): BlockedThreadDetector = anrModule.blockedThreadDetector
206206

207-
fun getSpanSink(): SpanSink = fakeInitModule.openTelemetryModule.spanSink
208-
209-
fun getCurrentSessionSpan(): CurrentSessionSpan = fakeInitModule.openTelemetryModule.currentSessionSpan
210-
211207
fun getPreferencesService(): PreferencesService = androidServicesModule.preferencesService
212208

213209
private companion object {
214210
fun initWorkerThreadModule(
215211
fakeInitModule: FakeInitModule,
216212
workerToFake: Worker.Background?,
217-
priorityWorkerToFake: Worker.Priority?,
218213
anrMonitoringThread: Thread?,
219214
): WorkerThreadModule =
220215
if (workerToFake == null) {
@@ -223,7 +218,6 @@ internal class EmbraceSetupInterface @JvmOverloads constructor(
223218
FakeWorkerThreadModule(
224219
fakeInitModule = fakeInitModule,
225220
testWorker = workerToFake,
226-
testPriorityWorker = priorityWorkerToFake,
227221
anrMonitoringThread = anrMonitoringThread
228222
)
229223
}

embrace-test-fakes/src/main/kotlin/io/embrace/android/embracesdk/fakes/FakeSymbolService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ package io.embrace.android.embracesdk.fakes
33
import io.embrace.android.embracesdk.internal.ndk.symbols.SymbolService
44

55
class FakeSymbolService(
6-
override val symbolsForCurrentArch: Map<String, String> = emptyMap(),
6+
override val symbolsForCurrentArch: MutableMap<String, String> = mutableMapOf(),
77
) : SymbolService

0 commit comments

Comments
 (0)