-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add E2E tests for crash loop scenarios
- Loading branch information
1 parent
9087f64
commit d904466
Showing
3 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...arios-bugsnag/src/main/java/com/bugsnag/android/mazerunner/scenarios/CrashLoopScenario.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
17
features/full_tests/batch_1/identify_crashes_on_launch.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |