Skip to content

Commit

Permalink
test: add E2E tests for autoNotify/autoDetectAnrs
Browse files Browse the repository at this point in the history
  • Loading branch information
fractalwrench committed May 4, 2021
1 parent 458a9b5 commit a27c2af
Show file tree
Hide file tree
Showing 11 changed files with 275 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -353,4 +353,14 @@ Java_com_bugsnag_android_mazerunner_scenarios_CXXMarkLaunchCompletedScenario_cra
jobject thiz) {
abort();
}

JNIEXPORT void JNICALL
Java_com_bugsnag_android_mazerunner_scenarios_UnhandledNdkAutoNotifyTrueScenario_crash(JNIEnv *env) {
abort();
}

JNIEXPORT void JNICALL
Java_com_bugsnag_android_mazerunner_scenarios_UnhandledNdkAutoNotifyFalseScenario_crash(JNIEnv *env) {
abort();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.bugsnag.android.mazerunner.scenarios

import android.content.Context
import com.bugsnag.android.Bugsnag
import com.bugsnag.android.Configuration
import com.bugsnag.android.mazerunner.getZeroEventsLogMessages
import com.bugsnag.android.setAutoNotify

class UnhandledNdkAutoNotifyFalseScenario(
config: Configuration,
context: Context,
eventMetadata: String?
) : Scenario(config, context, eventMetadata) {

init {
System.loadLibrary("cxx-scenarios")
}

external fun crash()

override fun startScenario() {
super.startScenario()
setAutoNotify(Bugsnag.getClient(), false)
crash()
}

override fun getInterceptedLogMessages(): List<String> {
return getZeroEventsLogMessages(startBugsnagOnly)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.bugsnag.android.mazerunner.scenarios

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

class UnhandledNdkAutoNotifyTrueScenario(
config: Configuration,
context: Context,
eventMetadata: String?
) : Scenario(config, context, eventMetadata) {

init {
System.loadLibrary("cxx-scenarios")
}

external fun crash()

override fun startScenario() {
super.startScenario()
setAutoNotify(Bugsnag.getClient(), false)
setAutoNotify(Bugsnag.getClient(), true)
crash()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<CurrentIssues>
<ID>MagicNumber:AnrHelper.kt$1000</ID>
<ID>MagicNumber:AnrHelper.kt$&lt;no name provided&gt;$60000</ID>
<ID>MagicNumber:AutoDetectAnrsFalseScenario.kt$AutoDetectAnrsFalseScenario$100000</ID>
<ID>MagicNumber:AutoDetectAnrsTrueScenario.kt$AutoDetectAnrsTrueScenario$100000</ID>
<ID>MagicNumber:BugsnagInitScenario.kt$BugsnagInitScenario$25</ID>
<ID>MagicNumber:HandledKotlinSmokeScenario.kt$HandledKotlinSmokeScenario$999</ID>
<ID>MagicNumber:JvmAnrSleepScenario.kt$JvmAnrSleepScenario$100000</ID>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,11 @@ fun generateEvent(client: Client): Event {
event.device = generateDeviceWithState()
return event
}

fun setAutoNotify(client: Client, enabled: Boolean) {
client.setAutoNotify(enabled)
}

fun setAutoDetectAnrs(client: Client, enabled: Boolean) {
client.setAutoDetectAnrs(enabled)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.bugsnag.android.mazerunner.scenarios

import android.content.Context
import android.os.Handler
import android.os.Looper
import com.bugsnag.android.Bugsnag
import com.bugsnag.android.Configuration
import com.bugsnag.android.mazerunner.getZeroEventsLogMessages
import com.bugsnag.android.setAutoDetectAnrs

internal class AutoDetectAnrsFalseScenario(
config: Configuration,
context: Context,
eventMetadata: String?
) : Scenario(config, context, eventMetadata) {

init {
config.enabledErrorTypes.anrs = true
}

override fun startScenario() {
super.startScenario()
setAutoDetectAnrs(Bugsnag.getClient(), false)

val main = Handler(Looper.getMainLooper())
main.postDelayed(
Runnable {
Thread.sleep(100000)
},
1
) // A moment of delay so there is something to 'tap' onscreen
}

override fun getInterceptedLogMessages(): List<String> {
return getZeroEventsLogMessages(startBugsnagOnly)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.bugsnag.android.mazerunner.scenarios

import android.content.Context
import android.os.Handler
import android.os.Looper
import com.bugsnag.android.Bugsnag
import com.bugsnag.android.Configuration
import com.bugsnag.android.setAutoDetectAnrs

internal class AutoDetectAnrsTrueScenario(
config: Configuration,
context: Context,
eventMetadata: String?
) : Scenario(config, context, eventMetadata) {

init {
config.enabledErrorTypes.anrs = true
}

override fun startScenario() {
super.startScenario()
setAutoDetectAnrs(Bugsnag.getClient(), false)
setAutoDetectAnrs(Bugsnag.getClient(), true)

val main = Handler(Looper.getMainLooper())
main.postDelayed(
Runnable {
Thread.sleep(100000)
},
1
) // A moment of delay so there is something to 'tap' onscreen
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.bugsnag.android.mazerunner.scenarios

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

class HandledJvmAutoNotifyFalseScenario(
config: Configuration,
context: Context,
eventMetadata: String?
) : Scenario(config, context, eventMetadata) {

override fun startScenario() {
super.startScenario()
setAutoNotify(Bugsnag.getClient(), false)
Bugsnag.notify(generateException())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.bugsnag.android.mazerunner.scenarios

import android.content.Context
import com.bugsnag.android.Bugsnag
import com.bugsnag.android.Configuration
import com.bugsnag.android.mazerunner.getZeroEventsLogMessages
import com.bugsnag.android.setAutoNotify

class UnhandledJvmAutoNotifyFalseScenario(
config: Configuration,
context: Context,
eventMetadata: String?
) : Scenario(config, context, eventMetadata) {

override fun startScenario() {
super.startScenario()
setAutoNotify(Bugsnag.getClient(), false)
throw generateException()
}

override fun getInterceptedLogMessages(): List<String> {
return getZeroEventsLogMessages(startBugsnagOnly)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.bugsnag.android.mazerunner.scenarios

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

class UnhandledJvmAutoNotifyTrueScenario(
config: Configuration,
context: Context,
eventMetadata: String?
) : Scenario(config, context, eventMetadata) {

override fun startScenario() {
super.startScenario()
setAutoNotify(Bugsnag.getClient(), false)
setAutoNotify(Bugsnag.getClient(), true)
throw generateException()
}
}
66 changes: 66 additions & 0 deletions features/full_tests/batch_1/auto_notify.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
Feature: Switching automatic error detection on/off for Unity

Scenario: Handled JVM exceptions are captured with autoNotify=false
When I run "HandledJvmAutoNotifyFalseScenario"
Then I wait to receive an error
And the error is valid for the error reporting API version "4.0" for the "Android Bugsnag Notifier" notifier
And the exception "message" equals "HandledJvmAutoNotifyFalseScenario"

Scenario: JVM exception not captured with autoNotify=false
When I run "UnhandledJvmAutoNotifyFalseScenario" and relaunch the app
And I configure Bugsnag for "UnhandledJvmAutoNotifyFalseScenario"
Then Bugsnag confirms it has no errors to send

Scenario: NDK signal not captured with autoNotify=false
When I run "UnhandledNdkAutoNotifyFalseScenario" and relaunch the app
And I configure Bugsnag for "UnhandledNdkAutoNotifyFalseScenario"
Then Bugsnag confirms it has no errors to send

@skip_android_8_1
Scenario: ANR not captured with autoDetectAnrs=false
When I run "AutoDetectAnrsFalseScenario" and relaunch the app
And I configure Bugsnag for "AutoDetectAnrsFalseScenario"
Then Bugsnag confirms it has no errors to send

Scenario: JVM exception captured with autoNotify reenabled
When I run "UnhandledJvmAutoNotifyTrueScenario" and relaunch the app
And I configure Bugsnag for "UnhandledJvmAutoNotifyTrueScenario"
Then I wait to receive an error
And the error is valid for the error reporting API version "4.0" for the "Android Bugsnag Notifier" notifier
And the error payload field "events" is an array with 1 elements
And the exception "errorClass" equals "java.lang.RuntimeException"
And the exception "message" equals "UnhandledJvmAutoNotifyTrueScenario"
And the exception "type" equals "android"
And the event "unhandled" is true
And the event "severity" equals "error"

Scenario: NDK signal captured with autoNotify reenabled
When I run "UnhandledNdkAutoNotifyTrueScenario" and relaunch the app
And I configure Bugsnag for "UnhandledNdkAutoNotifyTrueScenario"
Then I wait to receive an error
And the error is valid for the error reporting API version "4.0" for the "Android Bugsnag Notifier" notifier
And the error payload field "events" is an array with 1 elements
And the exception "message" equals "Abort program"
And the exception "type" equals "c"
And the event "unhandled" is true
And the event "severity" equals "error"
And the event "severityReason.type" equals "signal"
And the event "severityReason.unhandledOverridden" is false

@skip_android_8_1
Scenario: ANR captured with autoDetectAnrs reenabled
When I run "AutoDetectAnrsTrueScenario"
And I wait for 2 seconds
And I tap the screen 3 times
And I wait for 4 seconds
And I clear any error dialogue
And I wait to receive an error
Then the error is valid for the error reporting API version "4.0" for the "Android Bugsnag Notifier" notifier
And the error payload field "events" is an array with 1 elements
And the exception "errorClass" equals "ANR"
And the exception "message" starts with " Input dispatching timed out"
And the exception "type" equals "android"
And the event "unhandled" is true
And the event "severity" equals "error"
And the event "severityReason.type" equals "anrError"
And the event "severityReason.unhandledOverridden" is false

0 comments on commit a27c2af

Please sign in to comment.