Skip to content

Commit

Permalink
test: add e2e session/error empty/partial scenarios to buildkite fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
fractalwrench committed Oct 4, 2019
1 parent 75cb644 commit de0b66f
Show file tree
Hide file tree
Showing 8 changed files with 286 additions and 79 deletions.
68 changes: 0 additions & 68 deletions features/internal_report.feature

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
Feature: Sending internal error reports
Feature: Cached Error Reports

Scenario: If an empty file is in the cache directory then zero requests should be made
When I run "EmptyReportScenario" and relaunch the app
And I configure the app to run in the "non-crashy" state
And I run "EmptyReportScenario"
Then I should receive no requests

@skip_above_android_7
Scenario: Sending internal error reports on API <26
Expand All @@ -15,7 +21,7 @@ Scenario: Sending internal error reports on API <26
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.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
Expand All @@ -37,7 +43,7 @@ Scenario: Sending internal error reports on API >=26
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.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
Expand All @@ -60,9 +66,15 @@ Scenario: Sending internal error reports with cache tombstone + groups enabled
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.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
And the event "metaData.BugsnagDiagnostics.cacheTombstone" is true

Scenario: If a file in the cache directory is deleted before a request completes, zero further requests should be made
When I run "DeletedReportScenario" and relaunch the app
And I configure the app to run in the "non-crashy" state
And I run "DeletedReportScenario"
Then I should receive no requests
19 changes: 19 additions & 0 deletions tests/features/cached_session_reports.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Feature: Cached Session Reports

Scenario: If an empty file is in the cache directory then zero requests should be made
When I run "EmptySessionScenario" and relaunch the app
And I configure the app to run in the "non-crashy" state
And I run "EmptySessionScenario"
Then I should receive no requests

Scenario: Sending internal error reports on API <26
When I run "PartialSessionScenario" and relaunch the app
And I configure the app to run in the "non-crashy" state
And I run "PartialSessionScenario"
Then I should receive no requests

Scenario: If a file in the cache directory is deleted before a request completes, zero further requests should be made
When I run "DeletedSessionScenario" and relaunch the app
And I configure the app to run in the "non-crashy" state
And I run "DeletedSessionScenario"
Then I should receive no requests
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
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 android.util.Log

import com.bugsnag.android.*
import com.bugsnag.android.Configuration
import java.io.File

internal class DeletedReportScenario(config: Configuration,
context: Context) : Scenario(config, context) {

init {
config.setAutoCaptureSessions(false)

if (context is Activity) {
eventMetaData = context.intent.getStringExtra("eventMetaData")

if (eventMetaData != "non-crashy") {
disableAllDelivery(config)
} else {
val ctor = Class.forName("com.bugsnag.android.DefaultDelivery").declaredConstructors[0]
ctor.isAccessible = true
val baseDelivery = ctor.newInstance(null) as Delivery
val errDir = File(context.cacheDir, "bugsnag-errors")

config.delivery = object: Delivery {
override fun deliver(payload: SessionTrackingPayload, config: Configuration) {
baseDelivery.deliver(payload, config)
}

override fun deliver(report: Report, config: Configuration) {
// delete files before they can be delivered
val files = errDir.listFiles()
files.forEach {
Log.d("Bugsnag", "Deleting file: ${it.delete()}")
}

Log.d("Bugsnag", "Files available " + errDir.listFiles()[0].exists())
baseDelivery.deliver(report, config)
}
}
}
}
}

override fun run() {
super.run()

if (eventMetaData != "non-crashy") {
Bugsnag.notify(java.lang.RuntimeException("Whoops"))
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
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.Handler
import android.os.HandlerThread
import android.os.storage.StorageManager
import android.util.Log

import com.bugsnag.android.*
import com.bugsnag.android.Configuration
import java.io.File

internal class DeletedSessionScenario(config: Configuration,
context: Context) : Scenario(config, context) {

init {
config.setAutoCaptureSessions(false)

if (context is Activity) {
eventMetaData = context.intent.getStringExtra("eventMetaData")

if (eventMetaData != "non-crashy") {
disableAllDelivery(config)
} else {
val ctor = Class.forName("com.bugsnag.android.DefaultDelivery").declaredConstructors[0]
ctor.isAccessible = true
val baseDelivery = ctor.newInstance(null) as Delivery
val errDir = File(context.cacheDir, "bugsnag-sessions")

config.delivery = object: Delivery {
override fun deliver(payload: SessionTrackingPayload, config: Configuration) {
// delete files before they can be delivered
val files = errDir.listFiles()
files.forEach {
Log.d("Bugsnag", "Deleting file: ${it.delete()}")
}

Log.d("Bugsnag", "Files available " + errDir.listFiles()[0].exists())
baseDelivery.deliver(payload, config)
}

override fun deliver(report: Report, config: Configuration) {
baseDelivery.deliver(report, config)
}
}
}
}
}

override fun run() {
super.run()

if (eventMetaData != "non-crashy") {
Bugsnag.startSession()
}

val thread = HandlerThread("HandlerThread")
thread.start()

Handler(thread.looper).post {
flushAllSessions()
}
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,40 @@
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
import java.io.File

/**
* Verifies that if a report is empty and a beforeSend callback is set,
* minimal information is still sent to bugsnag.
*/
internal class EmptyReportScenario(config: Configuration,
context: Context) : Scenario(config, context) {

init {
config.setAutoCaptureSessions(false)
config.beforeSend { true }
val files = File(context.cacheDir, "bugsnag-errors").listFiles()
files.forEach { it.writeText("") }

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

if (eventMetaData != "non-crashy") {
disableAllDelivery(config)
} else {
val files = errDir.listFiles()
files.forEach { it.writeText("") }
}
}
}

override fun run() {
super.run()

if (eventMetaData != "non-crashy") {
Bugsnag.notify(java.lang.RuntimeException("Whoops"))
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
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.Handler
import android.os.HandlerThread
import android.os.storage.StorageManager
import android.util.Log

import com.bugsnag.android.*
import com.bugsnag.android.Configuration
import java.io.File

internal class EmptySessionScenario(config: Configuration,
context: Context) : Scenario(config, context) {

init {
config.setAutoCaptureSessions(false)
config.beforeSend { true }

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

if (eventMetaData != "non-crashy") {
disableAllDelivery(config)
} else {
val files = dir.listFiles()
Log.d("Bugsnag", "Empty sessions: ${files}")
files.forEach { it.writeText("") }
}
}
}

override fun run() {
super.run()

if (eventMetaData != "non-crashy") {
Bugsnag.startSession()
}

val thread = HandlerThread("HandlerThread")
thread.start()

Handler(thread.looper).post {
flushAllSessions()
}
}
}
Loading

0 comments on commit de0b66f

Please sign in to comment.