Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add E2E tests for crash loop scenarios #1181

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
fractalwrench marked this conversation as resolved.
Show resolved Hide resolved
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