Skip to content

Commit

Permalink
test: add E2E tests for crash loop scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
fractalwrench committed Mar 11, 2021
1 parent 9087f64 commit d904466
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -299,4 +299,10 @@ Java_com_bugsnag_android_mazerunner_scenarios_MultiProcessUnhandledCXXErrorScena
abort();
}

JNIEXPORT void JNICALL
Java_com_bugsnag_android_mazerunner_scenarios_CXXCrashLoopScenario_crash(JNIEnv *env,
jobject instance) {
abort();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.bugsnag.android.mazerunner.scenarios

import android.content.Context
import com.bugsnag.android.Bugsnag
import com.bugsnag.android.Configuration
import com.bugsnag.android.OnErrorCallback

/**
* Triggers a crash loop which Bugsnag allows recovery from.
*/
internal class CXXCrashLoopScenario(
config: Configuration,
context: Context,
eventMetadata: String?
) : Scenario(config, context, eventMetadata) {

init {
config.autoTrackSessions = false
System.loadLibrary("bugsnag-ndk")
System.loadLibrary("cxx-scenarios-bugsnag")
config.addOnError(
OnErrorCallback { event ->
Bugsnag.getLastRunInfo()?.let {
event.addMetadata("LastRunInfo", "crashed", it.crashed)
event.addMetadata("LastRunInfo", "crashedDuringLaunch", it.crashedDuringLaunch)
event.addMetadata(
"LastRunInfo",
"consecutiveLaunchCrashes",
it.consecutiveLaunchCrashes
)
}
true
}
)
}

external fun crash()

override fun startScenario() {
super.startScenario()
val lastRunInfo = Bugsnag.getLastRunInfo()

// the last run info allows the scenario to escape from what would otherwise be
// a crash loop, by conditionally entering a 'safe mode'.
if (lastRunInfo?.crashedDuringLaunch == true) {
Bugsnag.notify(IllegalArgumentException("Safe mode enabled"))
} else {
crash()
}
}
}
17 changes: 17 additions & 0 deletions features/full_tests/batch_1/identify_crashes_on_launch.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Feature: Identifying crashes on launch

Scenario: Escaping from a crash loop by reading LastRunInfo in a JVM error
When I run "JvmCrashLoopScenario" and relaunch the app
When I run "JvmCrashLoopScenario"
And I wait to receive 2 errors
Then the error is valid for the error reporting API version "4.0" for the "Android Bugsnag Notifier" notifier
And the exception "message" equals "First crash"
And the event "metaData.LastRunInfo.crashed" is null
And the event "metaData.LastRunInfo.crashedDuringLaunch" is null
And the event "metaData.LastRunInfo.consecutiveLaunchCrashes" is null
And I discard the oldest error
Then the error is valid for the error reporting API version "4.0" for the "Android Bugsnag Notifier" notifier
And the exception "message" equals "Safe mode enabled"
And the event "metaData.LastRunInfo.crashed" is true
And the event "metaData.LastRunInfo.crashedDuringLaunch" is true
And the event "metaData.LastRunInfo.consecutiveLaunchCrashes" equals 1

0 comments on commit d904466

Please sign in to comment.