Skip to content

Commit

Permalink
Rework test to avoid delivery prior to setting offline state
Browse files Browse the repository at this point in the history
Keeps all of the logic for a single scenario within a single class
Adds helper steps to better show how a user would get into this state
  • Loading branch information
kattrali committed May 30, 2018
1 parent 0dcd183 commit 59dbc09
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 19 deletions.
16 changes: 9 additions & 7 deletions features/startup_crash.feature
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
Feature: All errors are flushed if a startup crash is persisted

Scenario: 1 startup crash and 1 regular crash persisted
When I run "StartupCrashFlushScenario" with the defaults
And I force stop the "com.bugsnag.android.mazerunner" Android app
And I set environment variable "EVENT_METADATA" to "StartupCrash"
And I start the "com.bugsnag.android.mazerunner" Android app using the "com.bugsnag.android.mazerunner.MainActivity" activity
And I force stop the "com.bugsnag.android.mazerunner" Android app
When I configure the app to run in the "CrashOfflineWithDelay" state
And I run "StartupCrashFlushScenario" with the defaults
And I wait for 10 seconds

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
And I configure the app to run in the "CrashOfflineAtStartup" state
And I relaunch the app

And I configure the app to run in the "No crash" state
And I relaunch the app
And I wait for 5 seconds
Then I should receive 2 requests
9 changes: 9 additions & 0 deletions features/steps/build_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,12 @@
And I start the "com.bugsnag.android.mazerunner" Android app using the "com.bugsnag.android.mazerunner.MainActivity" activity
}
end

When("I relaunch the app") do
step('I force stop the "com.bugsnag.android.mazerunner" Android app')
step('I start the "com.bugsnag.android.mazerunner" Android app using the "com.bugsnag.android.mazerunner.MainActivity" activity')
end

When("I configure the app to run in the {string} state") do |event_metadata|
step("I set environment variable \"EVENT_METADATA\" to \"#{event_metadata}\"")
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.bugsnag.android.mazerunner.scenarios

import android.content.Context
import android.os.Handler
import com.bugsnag.android.*

/**
Expand All @@ -11,27 +12,31 @@ import com.bugsnag.android.*
*
* The mazerunner scenario that tests this works in 3 parts:
*
* 1. Generate and persist a normal crash on disc, by increasing the launchCrashThresholdMs at the
* time of recording
* 2. Generate and persist a startup crash on disc, by decreasing the launchCrashThresholdMs at the
* time of recording
* 1. Generate and persist a normal crash on disk, by waiting longer than the threshold for
* a startup crash
* 2. Generate and persist a startup crash on disk, by crashing as soon as the scenario starts
* 3. Send the stored reports. The startup crash should be delivered synchronously on the main thread,
* and the normal crash asynchronously.
*/
internal class StartupCrashFlushScenario(config: Configuration,
context: Context) : Scenario(config, context) {

override fun run() {
disableAllDelivery(config)
super.run()

if ("StartupCrash" == eventMetaData) {
config.launchCrashThresholdMs = Long.MAX_VALUE
if ("CrashOfflineWithDelay" == eventMetaData) {
// Part 1 - Persist a regular crash to disk
disableAllDelivery(config)
super.run()
Handler().postDelayed({
throw RuntimeException("Regular crash")
}, 6000)
} else if ("CrashOfflineAtStartup" == eventMetaData) {
// Part 2 - Persist a startup crash to disk
disableAllDelivery(config)
super.run()
throw RuntimeException("Startup crash")
} else {
config.launchCrashThresholdMs = 0
throw RuntimeException("Regular crash")
// Part 3 - Online, no crashes: send any cached reports
super.run()
}
}

}

0 comments on commit 59dbc09

Please sign in to comment.