Skip to content

Commit

Permalink
test: add mazerunner scenarios for stopping/resuming a session
Browse files Browse the repository at this point in the history
when a session is stopped, no session information should be present in error payloads.
  • Loading branch information
fractalwrench committed Feb 13, 2019
1 parent d031a9c commit 19a2ef9
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.bugsnag.android.mazerunner.scenarios

import android.content.Context
import com.bugsnag.android.Bugsnag
import com.bugsnag.android.Configuration
import android.os.Handler
import android.os.HandlerThread

/**
* Sends 2 exceptions, 1 before resuming a session, and 1 after resuming a session.
*/
internal class ResumedSessionScenario(config: Configuration,
context: Context) : Scenario(config, context) {
init {
config.setAutoCaptureSessions(false)
}

override fun run() {
super.run()
val client = Bugsnag.getClient()
val thread = HandlerThread("HandlerThread")
thread.start()

Handler(thread.looper).post {
// send 1st exception
client.startSession()
client.notifyBlocking(generateException())

// send 2nd exception after resuming a session
client.stopSession()
client.resumeSession()
client.notifyBlocking(generateException())
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.bugsnag.android.mazerunner.scenarios

import android.content.Context
import com.bugsnag.android.Bugsnag
import com.bugsnag.android.Configuration
import android.os.Handler
import android.os.HandlerThread

/**
* Sends an exception after stopping the session
*/
internal class StoppedSessionScenario(config: Configuration,
context: Context) : Scenario(config, context) {
init {
config.setAutoCaptureSessions(false)
}

override fun run() {
super.run()
val client = Bugsnag.getClient()
val thread = HandlerThread("HandlerThread")
thread.start()

Handler(thread.looper).post {
// send 1st exception which should include session info
client.startSession()
client.notifyBlocking(generateException())

// send 2nd exception which should not include session info
client.stopSession()
client.notifyBlocking(generateException())
}
}
}
19 changes: 19 additions & 0 deletions features/session_stopping.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Feature: Stopping and resuming sessions

Scenario: When a session is stopped the error has no session information
When I run "StoppedSessionScenario"
Then I should receive 3 requests
And the request 0 is valid for the session tracking API
And the request 1 is valid for the error reporting API
And the request 2 is valid for the error reporting API
And the payload field "events.0.session" is not null for request 1
And the payload field "events.0.session" is null for request 2

Scenario: When a session is resumed the error uses the previous session information
When I run "ResumedSessionScenario"
Then I should receive 3 requests
And the request 0 is valid for the session tracking API
And the request 1 is valid for the error reporting API
And the request 2 is valid for the error reporting API
And the payload field "events.0.session.events.handled" equals 1 for request 1
And the payload field "events.0.session.events.handled" equals 2 for request 2

0 comments on commit 19a2ef9

Please sign in to comment.