-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #429 from bugsnag/stop-sessions
Add stopSession() and resumeSession() to Client
- Loading branch information
Showing
22 changed files
with
649 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...unner/src/main/java/com/bugsnag/android/mazerunner/scenarios/CXXStartSessionScenario.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.bugsnag.android.mazerunner.scenarios; | ||
|
||
import android.content.Context; | ||
import android.os.Handler; | ||
|
||
import com.bugsnag.android.Bugsnag; | ||
import com.bugsnag.android.Configuration; | ||
|
||
import android.support.annotation.NonNull; | ||
|
||
public class CXXStartSessionScenario extends Scenario { | ||
static { | ||
System.loadLibrary("bugsnag-ndk"); | ||
System.loadLibrary("monochrome"); | ||
System.loadLibrary("entrypoint"); | ||
} | ||
|
||
private Handler handler = new Handler(); | ||
|
||
public native int crash(int counter); | ||
|
||
public CXXStartSessionScenario(@NonNull Configuration config, @NonNull Context context) { | ||
super(config, context); | ||
config.setAutoCaptureSessions(false); | ||
} | ||
|
||
@Override | ||
public void run() { | ||
super.run(); | ||
String metadata = getEventMetaData(); | ||
|
||
if (metadata == null || !metadata.equals("non-crashy")) { | ||
Bugsnag.getClient().startSession(); | ||
|
||
handler.postDelayed(new Runnable() { | ||
@Override | ||
public void run() { | ||
crash(0); | ||
} | ||
}, 8000); | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...runner/src/main/java/com/bugsnag/android/mazerunner/scenarios/CXXStopSessionScenario.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.bugsnag.android.mazerunner.scenarios; | ||
|
||
import android.content.Context; | ||
import android.os.Handler; | ||
|
||
import com.bugsnag.android.Bugsnag; | ||
import com.bugsnag.android.Configuration; | ||
|
||
import android.support.annotation.NonNull; | ||
|
||
public class CXXStopSessionScenario extends Scenario { | ||
static { | ||
System.loadLibrary("bugsnag-ndk"); | ||
System.loadLibrary("monochrome"); | ||
System.loadLibrary("entrypoint"); | ||
} | ||
|
||
private Handler handler = new Handler(); | ||
|
||
public native int crash(int counter); | ||
|
||
public CXXStopSessionScenario(@NonNull Configuration config, @NonNull Context context) { | ||
super(config, context); | ||
config.setAutoCaptureSessions(false); | ||
} | ||
|
||
@Override | ||
public void run() { | ||
super.run(); | ||
String metadata = getEventMetaData(); | ||
|
||
if (metadata == null || !metadata.equals("non-crashy")) { | ||
Bugsnag.getClient().startSession(); | ||
Bugsnag.getClient().stopSession(); | ||
|
||
handler.postDelayed(new Runnable() { | ||
@Override | ||
public void run() { | ||
crash(0); | ||
} | ||
}, 8000); | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...s/mazerunner/src/main/java/com/bugsnag/android/mazerunner/scenarios/NewSessionScenario.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 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 NewSessionScenario(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()) | ||
|
||
// stop tracking the existing session | ||
client.stopSession() | ||
|
||
// send 2nd exception which should contain new session info | ||
client.startSession() | ||
client.notifyBlocking(generateException()) | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...zerunner/src/main/java/com/bugsnag/android/mazerunner/scenarios/ResumedSessionScenario.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...zerunner/src/main/java/com/bugsnag/android/mazerunner/scenarios/StoppedSessionScenario.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
Feature: NDK Session Tracking | ||
|
||
Scenario: Stopped session is not in payload of unhandled NDK error | ||
When I run "CXXStopSessionScenario" | ||
And I wait a bit | ||
And I wait a bit | ||
And I configure the app to run in the "non-crashy" state | ||
And I relaunch the app | ||
Then I should receive 2 requests | ||
And the request 0 is a valid for the session tracking API | ||
And the request 1 is a valid for the error reporting API | ||
And the payload field "events.0.session" is null for request 1 | ||
|
||
Scenario: Started session is in payload of unhandled NDK error | ||
When I run "CXXStartSessionScenario" | ||
And I wait a bit | ||
And I wait a bit | ||
And I configure the app to run in the "non-crashy" state | ||
And I relaunch the app | ||
Then I should receive 2 requests | ||
And the request 0 is a valid for the session tracking API | ||
And the request 1 is a valid for the error reporting API | ||
And the payload field "events.0.session.events.unhandled" equals 1 for request 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
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 | ||
And the payload field "events.0.session.id" of request 1 equals the payload field "events.0.session.id" of request 2 | ||
And the payload field "events.0.session.startedAt" of request 1 equals the payload field "events.0.session.startedAt" of request 2 | ||
|
||
Scenario: When a new session is started the error uses different session information | ||
When I run "NewSessionScenario" | ||
Then I should receive 4 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 session tracking API | ||
And the request 3 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 1 for request 3 | ||
And the payload field "events.0.session.id" of request 1 does not equal the payload field "events.0.session.id" of request 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.