diff --git a/features/session_cache.feature b/features/session_cache.feature new file mode 100644 index 0000000000..5a9a53a079 --- /dev/null +++ b/features/session_cache.feature @@ -0,0 +1,18 @@ +Feature: Android support + +Scenario: Test Unhandled Android Exception with Session + When I run "SessionCacheScenario" with the defaults + Then I should receive no requests + + When I force stop the "com.bugsnag.android.mazerunner" Android app + And I set environment variable "EVENT_TYPE" to "Wait" + And I start the "com.bugsnag.android.mazerunner" Android app using the "com.bugsnag.android.mazerunner.MainActivity" activity + Then I should receive a request + + And the request is a valid for the session tracking API + And the payload field "sessions" is an array with 1 element + And the session "user.id" equals "123" + And the session "user.email" equals "user@example.com" + And the session "user.name" equals "Joe Bloggs" + And the session "id" is not null + And the session "startedAt" is not null diff --git a/mazerunner/src/main/java/com/bugsnag/android/mazerunner/scenarios/SessionCacheScenario.kt b/mazerunner/src/main/java/com/bugsnag/android/mazerunner/scenarios/SessionCacheScenario.kt new file mode 100644 index 0000000000..375535edda --- /dev/null +++ b/mazerunner/src/main/java/com/bugsnag/android/mazerunner/scenarios/SessionCacheScenario.kt @@ -0,0 +1,20 @@ +package com.bugsnag.android.mazerunner.scenarios + +import android.content.Context +import com.bugsnag.android.Bugsnag +import com.bugsnag.android.Configuration + +/** + * Sends a session which is cached on disk to Bugsnag, then sent on a separate launch. + */ +internal class SessionCacheScenario(config: Configuration, + context: Context) : Scenario(config, context) { + + override fun run() { + super.run() + Bugsnag.setUser("123", "user@example.com", "Joe Bloggs") + Bugsnag.startSession() + disableSessionDelivery() + } + +} diff --git a/mazerunner/src/main/java/com/bugsnag/android/mazerunner/scenarios/Wait.kt b/mazerunner/src/main/java/com/bugsnag/android/mazerunner/scenarios/Wait.kt new file mode 100644 index 0000000000..79b52113da --- /dev/null +++ b/mazerunner/src/main/java/com/bugsnag/android/mazerunner/scenarios/Wait.kt @@ -0,0 +1,20 @@ +package com.bugsnag.android.mazerunner.scenarios + +import android.content.Context +import android.os.Handler +import android.os.HandlerThread +import com.bugsnag.android.Configuration +import com.bugsnag.android.flushAllSessions + +internal class Wait(config: Configuration, context: Context) : Scenario(config, context) { + + override fun run() { + super.run() + val thread = HandlerThread("HandlerThread") + thread.start() + Handler(thread.looper).post { + flushAllSessions() + } + } + +}