Skip to content

Commit

Permalink
test: add additional mazerunner scenarios for internal error reports
Browse files Browse the repository at this point in the history
  • Loading branch information
fractalwrench committed Sep 25, 2019
1 parent aa953fa commit 0a45f7a
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package com.bugsnag.android.mazerunner.scenarios
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.os.Build
import android.os.storage.StorageManager

import com.bugsnag.android.Bugsnag
import com.bugsnag.android.Configuration
Expand All @@ -20,10 +22,19 @@ internal class InternalReportScenario(config: Configuration,

if (context is Activity) {
eventMetaData = context.intent.getStringExtra("EVENT_METADATA")
val errDir = File(context.cacheDir, "bugsnag-errors")

if (eventMetaData == "tombstone" && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
errDir.mkdir()
val storageManager = context.getSystemService(Context.STORAGE_SERVICE) as StorageManager
storageManager.setCacheBehaviorGroup(errDir, true)
storageManager.setCacheBehaviorTombstone(errDir, true)
}

if (eventMetaData != "non-crashy") {
disableAllDelivery(config)
} else {
val files = File(context.cacheDir, "bugsnag-errors").listFiles()
val files = errDir.listFiles()
files.forEach { it.writeText("{[]}") }
}
}
Expand Down
50 changes: 48 additions & 2 deletions features/internal_report.feature
Original file line number Diff line number Diff line change
@@ -1,6 +1,29 @@
Feature: Sending internal error reports

Scenario: Send a report about an error triggered within the notifier
@skip_above_android_7
Scenario: Sending internal error reports on API <26
When I run "InternalReportScenario"
And I configure the app to run in the "non-crashy" state
And I relaunch the app
Then I should receive 1 request
And the "Bugsnag-Internal-Error" header equals "true"
And the payload field "apiKey" is null
And the event "context" equals "Crash Report Deserialization"
And the event "session" is null
And the event "breadcrumbs" is null
And the event "app.type" equals "android"
And the event "device.osName" equals "android"
And the event "metaData.BugsnagDiagnostics.filename" is not null
And the event "metaData.BugsnagDiagnostics.notifierName" equals "Android Bugsnag Notifier"
And the event "metaData.BugsnagDiagnostics.apiKey" equals "a35a2a72bd230ac0aa0f52715bbdc6aa"
And the event "metaData.BugsnagDiagnostics.packageName" equals "com.bugsnag.android.mazerunner"
And the event "metaData.BugsnagDiagnostics.notifierVersion" is not null
And the event "metaData.BugsnagDiagnostics.fileLength" equals 4
And the event "metaData.BugsnagDiagnostics.cacheGroup" is null
And the event "metaData.BugsnagDiagnostics.cacheTombstone" is null

@skip_below_android_8
Scenario: Sending internal error reports on API >=26
When I run "InternalReportScenario"
And I configure the app to run in the "non-crashy" state
And I relaunch the app
Expand All @@ -12,11 +35,34 @@ Scenario: Send a report about an error triggered within the notifier
And the event "breadcrumbs" is null
And the event "app.type" equals "android"
And the event "device.osName" equals "android"
And the event "metaData.BugsnagDiagnostics.cacheTombstone" is false
And the event "metaData.BugsnagDiagnostics.filename" is not null
And the event "metaData.BugsnagDiagnostics.notifierName" equals "Android Bugsnag Notifier"
And the event "metaData.BugsnagDiagnostics.apiKey" equals "a35a2a72bd230ac0aa0f52715bbdc6aa"
And the event "metaData.BugsnagDiagnostics.packageName" equals "com.bugsnag.android.mazerunner"
And the event "metaData.BugsnagDiagnostics.notifierVersion" is not null
And the event "metaData.BugsnagDiagnostics.fileLength" equals 4
And the event "metaData.BugsnagDiagnostics.cacheGroup" is false
And the event "metaData.BugsnagDiagnostics.cacheTombstone" is false

@skip_below_android_8
Scenario: Sending internal error reports with cache tombstone + groups enabled
When I configure the app to run in the "tombstone" state
And I run "InternalReportScenario"
And I configure the app to run in the "non-crashy" state
And I relaunch the app
Then I should receive 1 request
And the "Bugsnag-Internal-Error" header equals "true"
And the payload field "apiKey" is null
And the event "context" equals "Crash Report Deserialization"
And the event "session" is null
And the event "breadcrumbs" is null
And the event "app.type" equals "android"
And the event "device.osName" equals "android"
And the event "metaData.BugsnagDiagnostics.filename" is not null
And the event "metaData.BugsnagDiagnostics.notifierName" equals "Android Bugsnag Notifier"
And the event "metaData.BugsnagDiagnostics.apiKey" equals "a35a2a72bd230ac0aa0f52715bbdc6aa"
And the event "metaData.BugsnagDiagnostics.packageName" equals "com.bugsnag.android.mazerunner"
And the event "metaData.BugsnagDiagnostics.notifierVersion" is not null
And the event "metaData.BugsnagDiagnostics.fileLength" equals 4
And the event "metaData.BugsnagDiagnostics.cacheGroup" is true
And the event "metaData.BugsnagDiagnostics.cacheTombstone" is true
17 changes: 17 additions & 0 deletions features/support/env.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'open3'

# Configure app environment
RUNNING_CI = ENV['TRAVIS'] == 'true'

Expand Down Expand Up @@ -31,3 +33,18 @@
ENV['DEVICE_ORIENTATION'] = 'portrait'
run_required_commands([["features/scripts/rotate-device.sh"]])
end

Before('@skip_below_android_8') do |scenario|
skip_this_scenario("Skipping scenario") if get_api_level() < 26
end

Before('@skip_above_android_7') do |scenario|
skip_this_scenario("Skipping scenario") if get_api_level() >= 26
end

def get_api_level
stdout, stderr, status = Open3.capture3("adb shell getprop ro.build.version.sdk")
assert_true(status.success?)
return stdout.to_i
end

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package com.bugsnag.android.mazerunner.scenarios
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.os.Build
import android.os.storage.StorageManager

import com.bugsnag.android.Bugsnag
import com.bugsnag.android.Configuration
Expand All @@ -20,10 +22,19 @@ internal class InternalReportScenario(config: Configuration,

if (context is Activity) {
eventMetaData = context.intent.getStringExtra("eventMetaData")
val errDir = File(context.cacheDir, "bugsnag-errors")

if (eventMetaData == "tombstone" && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
errDir.mkdir()
val storageManager = context.getSystemService(Context.STORAGE_SERVICE) as StorageManager
storageManager.setCacheBehaviorGroup(errDir, true)
storageManager.setCacheBehaviorTombstone(errDir, true)
}

if (eventMetaData != "non-crashy") {
disableAllDelivery(config)
} else {
val files = File(context.cacheDir, "bugsnag-errors").listFiles()
val files = errDir.listFiles()
files.forEach { it.writeText("{[]}") }
}
}
Expand Down
51 changes: 48 additions & 3 deletions tests/features/internal_report.feature
Original file line number Diff line number Diff line change
@@ -1,7 +1,29 @@
Feature: Sending internal error reports

@skip_below_android_9
Scenario: Sending internal error reports below Android 9
@skip_above_android_7
Scenario: Sending internal error reports on API <26
When I run "InternalReportScenario" and relaunch the app
And I configure the app to run in the "non-crashy" state
And I run "InternalReportScenario"
And I wait to receive a request
And the "Bugsnag-Internal-Error" header equals "true"
And the payload field "apiKey" is null
And the event "context" equals "Crash Report Deserialization"
And the event "session" is null
And the event "breadcrumbs" is null
And the event "app.type" equals "android"
And the event "device.osName" equals "android"
And the event "metaData.BugsnagDiagnostics.filename" is not null
And the event "metaData.BugsnagDiagnostics.notifierName" equals "Android Bugsnag Notifier"
And the event "metaData.BugsnagDiagnostics.apiKey" equals "ABCDEFGHIJKLMNOPQRSTUVWXYZ012345"
And the event "metaData.BugsnagDiagnostics.packageName" equals "com.bugsnag.android.mazerunner"
And the event "metaData.BugsnagDiagnostics.notifierVersion" is not null
And the event "metaData.BugsnagDiagnostics.fileLength" equals 4
And the event "metaData.BugsnagDiagnostics.cacheGroup" is null
And the event "metaData.BugsnagDiagnostics.cacheTombstone" is null

@skip_below_android_8
Scenario: Sending internal error reports on API >=26
When I run "InternalReportScenario" and relaunch the app
And I configure the app to run in the "non-crashy" state
And I run "InternalReportScenario"
Expand All @@ -13,11 +35,34 @@ Scenario: Sending internal error reports below Android 9
And the event "breadcrumbs" is null
And the event "app.type" equals "android"
And the event "device.osName" equals "android"
And the event "metaData.BugsnagDiagnostics.cacheTombstone" is false
And the event "metaData.BugsnagDiagnostics.filename" is not null
And the event "metaData.BugsnagDiagnostics.notifierName" equals "Android Bugsnag Notifier"
And the event "metaData.BugsnagDiagnostics.apiKey" equals "ABCDEFGHIJKLMNOPQRSTUVWXYZ012345"
And the event "metaData.BugsnagDiagnostics.packageName" equals "com.bugsnag.android.mazerunner"
And the event "metaData.BugsnagDiagnostics.notifierVersion" is not null
And the event "metaData.BugsnagDiagnostics.fileLength" equals 4
And the event "metaData.BugsnagDiagnostics.cacheGroup" is false
And the event "metaData.BugsnagDiagnostics.cacheTombstone" is false

@skip_below_android_8
Scenario: Sending internal error reports with cache tombstone + groups enabled
And I configure the app to run in the "tombstone" state
When I run "InternalReportScenario" and relaunch the app
And I configure the app to run in the "non-crashy" state
And I run "InternalReportScenario"
And I wait to receive a request
And the "Bugsnag-Internal-Error" header equals "true"
And the payload field "apiKey" is null
And the event "context" equals "Crash Report Deserialization"
And the event "session" is null
And the event "breadcrumbs" is null
And the event "app.type" equals "android"
And the event "device.osName" equals "android"
And the event "metaData.BugsnagDiagnostics.filename" is not null
And the event "metaData.BugsnagDiagnostics.notifierName" equals "Android Bugsnag Notifier"
And the event "metaData.BugsnagDiagnostics.apiKey" equals "ABCDEFGHIJKLMNOPQRSTUVWXYZ012345"
And the event "metaData.BugsnagDiagnostics.packageName" equals "com.bugsnag.android.mazerunner"
And the event "metaData.BugsnagDiagnostics.notifierVersion" is not null
And the event "metaData.BugsnagDiagnostics.fileLength" equals 4
And the event "metaData.BugsnagDiagnostics.cacheGroup" is true
And the event "metaData.BugsnagDiagnostics.cacheTombstone" is true
8 changes: 8 additions & 0 deletions tests/features/support/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
skip_this_scenario("Skipping scenario") if bs_device != 'ANDROID_9'
end

Before('@skip_below_android_8') do |scenario|
skip_this_scenario("Skipping scenario") if bs_device != 'ANDROID_8' && bs_device != 'ANDROID_9'
end

Before('@skip_above_android_7') do |scenario|
skip_this_scenario("Skipping scenario") if bs_device == 'ANDROID_8' || bs_device == 'ANDROID_9'
end

AfterConfiguration do |config|
AppAutomateDriver.new(bs_username, bs_access_key, bs_local_id, bs_device, app_location)
$driver.start_driver
Expand Down

0 comments on commit 0a45f7a

Please sign in to comment.