Skip to content

Commit

Permalink
test: mazerunner old error store test
Browse files Browse the repository at this point in the history
adds a scenario to verify that errors stored in the old directory are reported by multiple clients
  • Loading branch information
fractalwrench committed Apr 23, 2018
1 parent 45e8a35 commit 9afb2be
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
8 changes: 8 additions & 0 deletions features/multi_client.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ Feature: Multi-client support
configuration options. A report which is captured by a given client should
use the correct API key and configuration options.

Scenario: Multiple clients send errors stored in the old directory
When I run "MultiClientOldDirScenario" with the defaults
When I force stop the "com.bugsnag.android.mazerunner" Android app
And I set environment variable "EVENT_TYPE" to "MultiClientOldDirScenario"
And I set environment variable "EVENT_METADATA" to "DeliverReport"
And I start the "com.bugsnag.android.mazerunner" Android app using the "com.bugsnag.android.mazerunner.MainActivity" activity
Then I should receive 2 requests

Scenario: A handled error captured while offline is only sent by the original client
When I run "MultiClientNotifyScenario" with the defaults
When I force stop the "com.bugsnag.android.mazerunner" Android app
Expand Down
15 changes: 15 additions & 0 deletions mazerunner/src/main/java/com/bugsnag/android/TestHarnessHooks.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.bugsnag.android

import android.content.Context
import android.net.ConnectivityManager
import java.io.File
import java.io.FileWriter

/**
* Accesses the session tracker and flushes all stored sessions
Expand Down Expand Up @@ -33,6 +35,19 @@ internal fun createSlowErrorApiClient(context: Context): ErrorReportApiClient {
})
}

/**
* Writes an error to the old directory format (i.e. bugsnag-errors)
*/
internal fun writeErrorToOldDir(client: Client) {
val configuration = Configuration("api-key")
val error = Error.Builder(configuration, RuntimeException(), null).build()
val filename = client.errorStore.getFilename(error)

val file = File(client.errorStore.oldDirectory, filename)
val writer = JsonStream(FileWriter(file))
error.toStream(writer)
}

internal fun writeErrorToStore(client: Client) {
val error = Error.Builder(Configuration("api-key"), RuntimeException(), null).build()
client.errorStore.write(error)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.bugsnag.android.mazerunner.scenarios

import android.content.Context
import com.bugsnag.android.Client
import com.bugsnag.android.Configuration
import com.bugsnag.android.disableAllDelivery
import com.bugsnag.android.writeErrorToOldDir

/**
* Configures two Bugsnag clients with different API keys. A single error report is written to the
* old directory format, which should then be reported by both clients.
*
*/
internal class MultiClientOldDirScenario(config: Configuration,
context: Context) : Scenario(config, context) {
var firstClient: Client? = null
var secondClient: Client? = null

fun configureClients() {
firstClient = Client(context, config)

Thread.sleep(10) // enforce request order
val secondConfig = Configuration("abc123")
secondConfig.endpoint = config.endpoint
secondConfig.sessionEndpoint = config.sessionEndpoint
secondClient = Client(context, secondConfig)
}

override fun run() {
configureClients()

if ("DeliverReport" != eventMetaData) {
disableAllDelivery(firstClient!!)
disableAllDelivery(secondClient!!)
writeErrorToOldDir(firstClient!!)
}
}

}

0 comments on commit 9afb2be

Please sign in to comment.