Skip to content

Commit

Permalink
add test for session cached on disk
Browse files Browse the repository at this point in the history
  • Loading branch information
fractalwrench committed Mar 1, 2018
1 parent fee3c43 commit 7b80c02
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
18 changes: 18 additions & 0 deletions features/session_cache.feature
@@ -0,0 +1,18 @@
Feature: Android support

Scenario: Test Unhandled Android Exception with Session
When I run "SessionCacheScenario" with the defaults
Then I should receive no requests

When I force stop the "com.bugsnag.android.mazerunner" Android app
And I set environment variable "EVENT_TYPE" to "Wait"
And I start the "com.bugsnag.android.mazerunner" Android app using the "com.bugsnag.android.mazerunner.MainActivity" activity
Then I should receive a request

And the request is a valid for the session tracking API
And the payload field "sessions" is an array with 1 element
And the session "user.id" equals "123"
And the session "user.email" equals "user@example.com"
And the session "user.name" equals "Joe Bloggs"
And the session "id" is not null
And the session "startedAt" is not null
@@ -0,0 +1,20 @@
package com.bugsnag.android.mazerunner.scenarios

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

/**
* Sends a session which is cached on disk to Bugsnag, then sent on a separate launch.
*/
internal class SessionCacheScenario(config: Configuration,
context: Context) : Scenario(config, context) {

override fun run() {
super.run()
Bugsnag.setUser("123", "user@example.com", "Joe Bloggs")
Bugsnag.startSession()
disableSessionDelivery()
}

}
@@ -0,0 +1,20 @@
package com.bugsnag.android.mazerunner.scenarios

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

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

override fun run() {
super.run()
val thread = HandlerThread("HandlerThread")
thread.start()
Handler(thread.looper).post {
flushAllSessions()
}
}

}

0 comments on commit 7b80c02

Please sign in to comment.