Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #231

Merged
merged 17 commits into from
Jan 26, 2018
Merged

Fixes #231

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ Running Tests

Running the test suite requires a connected android device or emulator.

You can run the test suite on a device/emulator as follows:
You can run the test suite on a device/emulator as follows from within the sdk directory:

```shell
./gradlew clean :connectedCheck
../gradlew connectedCheck
```

Running Lint
Expand Down Expand Up @@ -146,6 +146,6 @@ This process is a little ridiculous...

- Make releases to downstream libraries, if appropriate (generally for bug
fixes)

### 7. Update Method Count Badge
- Update the version number specified in the URL for the method count badge in the README.
- Update the version number specified in the URL for the method count badge in the README.
4 changes: 2 additions & 2 deletions example/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ android {
targetSdkVersion Integer.parseInt(project.ANDROID_TARGET_SDK_VERSION)

manifestPlaceholders = [
bugsnagApiKey : "your-api-key",
bugsnagApiKey : "572dd1154e6c5b291e5d1b42e506ae34",
bugsnagBuildUUID : "abc123",
bugsnagAppVersion : "1.0.0",
bugsnagEndpoint : "https://notify.bugsnag.com",
bugsnagSessionsEndpoint : "http://sessions.bugsnag.com",
bugsnagSessionsEndpoint : "https://sessions.bugsnag.com",
bugsnagReleaseStage : "debug",
bugsnagSendThreads : true,
bugsnagEnableExceptionHandler : true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class ExampleActivity extends AppCompatActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bugsnag.setAutoCaptureSessions(true);
setContentView(R.layout.main);
setupToolbarLogo();
performAdditionalBugsnagSetup();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ static Client generateClient() {
}

static Session generateSession() {
return new Session("test", new Date(), new User());
return new Session("test", new Date(), new User(), false);
}

static Configuration generateConfiguration() {
Expand All @@ -55,7 +55,7 @@ static Configuration generateConfiguration() {

static SessionTracker generateSessionTracker() {
return new SessionTracker(generateConfiguration(), BugsnagTestUtils.generateClient(),
generateSessionStore(), generateSessionTrackingApiClient(), InstrumentationRegistry.getContext());
generateSessionStore(), generateSessionTrackingApiClient());
}

@NonNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,7 @@ public void testMultipleClients() {

@Test
public void testIsCrashOnLaunch() throws Exception {
ExceptionHandler handler = new ExceptionHandler(null);
Date now = new Date();
Client client = new Client(context, new Configuration("123"), now);

assertTrue(handler.isCrashOnLaunch(client, now));

client.config.setLaunchCrashThresholdMs(0);
assertFalse(handler.isCrashOnLaunch(client, now));

client.config.setLaunchCrashThresholdMs(10000);
assertFalse(handler.isCrashOnLaunch(client, new Date(now.getTime() + 20000)));
//TODO:SM Replace this
}

}
3 changes: 1 addition & 2 deletions sdk/src/androidTest/java/com/bugsnag/android/ReportTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@
public class ReportTest {

private Report report;
private Configuration config;

@Before
public void setUp() throws Exception {
config = new Configuration("example-api-key");
Configuration config = new Configuration("example-api-key");
Error error = new Error.Builder(config, new RuntimeException("Something broke"), null).build();
report = new Report("api-key", error);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
public class SessionTrackerTest {

private static final String ACTIVITY_NAME = "test";
private static final String FIRST_ACTIVITY = "MyActivity";
private static final String SECOND_ACTIVITY = "SecondActivity";
private static final String FIRST_CB = "onCreate";
private static final String SECOND_CB = "onStart";

private SessionTracker sessionTracker;
private User user;
Expand All @@ -32,44 +28,11 @@ public class SessionTrackerTest {
public void setUp() throws Exception {
configuration = new Configuration("test");
sessionTracker = new SessionTracker(configuration, generateClient(), generateSessionStore(),
generateSessionTrackingApiClient(), InstrumentationRegistry.getContext());
generateSessionTrackingApiClient());
configuration.setAutoCaptureSessions(true);
user = new User();
}

@Test
public void testLifecycleQueueing() throws Exception {
sessionTracker = new SessionTracker(configuration, null, generateSessionStore(),
generateSessionTrackingApiClient(), InstrumentationRegistry.getContext());
sessionTracker.leaveLifecycleBreadcrumb(FIRST_ACTIVITY, FIRST_CB);
sessionTracker.leaveLifecycleBreadcrumb(SECOND_ACTIVITY, SECOND_CB);

assertEquals(2, sessionTracker.breadcrumbQueue.size());

Pair<String, String> poll = sessionTracker.breadcrumbQueue.poll();
assertEquals(FIRST_ACTIVITY, poll.first);
assertEquals(FIRST_CB, poll.second);

poll = sessionTracker.breadcrumbQueue.poll();
assertEquals(SECOND_ACTIVITY, poll.first);
assertEquals(SECOND_CB, poll.second);
}

@Test
public void testNullClientUpdate() throws Exception {
// shouldn't throw npe attempting to access client
sessionTracker = new SessionTracker(configuration, null, generateSessionStore(),
generateSessionTrackingApiClient(), InstrumentationRegistry.getContext());
sessionTracker.updateForegroundTracker(FIRST_ACTIVITY, true, System.currentTimeMillis());
}

@Test
public void testLifecycleLogging() throws Exception {
sessionTracker.leaveLifecycleBreadcrumb(FIRST_ACTIVITY, FIRST_CB);
sessionTracker.leaveLifecycleBreadcrumb(SECOND_ACTIVITY, SECOND_CB);
assertTrue(sessionTracker.breadcrumbQueue.isEmpty());
}

@Test
public void startNewSession() throws Exception {
assertNotNull(sessionTracker);
Expand All @@ -91,12 +54,10 @@ public void startSessionDisabled() throws Exception {

Date date = new Date();
sessionTracker.startNewSession(date, user, true);
assertTrue(sessionTracker.sessionQueue.isEmpty());
assertNotNull(sessionTracker.getCurrentSession());

configuration.setAutoCaptureSessions(true);
sessionTracker.startNewSession(date, user, false);
assertEquals(1, sessionTracker.sessionQueue.size());
assertNotNull(sessionTracker.getCurrentSession());
}

Expand Down Expand Up @@ -156,25 +117,25 @@ public void testBasicInForeground() throws Exception {
public void testInForegroundDuration() throws Exception {
long now = System.currentTimeMillis();
sessionTracker = new SessionTracker(configuration, generateClient(), 0, generateSessionStore(),
generateSessionTrackingApiClient(), InstrumentationRegistry.getContext());
generateSessionTrackingApiClient());

sessionTracker.updateForegroundTracker(ACTIVITY_NAME, false, now);
assertEquals(0, sessionTracker.getDurationInForeground(now));
assertEquals(0, sessionTracker.getDurationInForegroundMs(now));

sessionTracker.updateForegroundTracker(ACTIVITY_NAME, true, now);
assertEquals(0, sessionTracker.getDurationInForeground(now));
assertEquals(0, sessionTracker.getDurationInForegroundMs(now));

sessionTracker.updateForegroundTracker(ACTIVITY_NAME, true, now);
assertEquals(100, sessionTracker.getDurationInForeground(now + 100));
assertEquals(100, sessionTracker.getDurationInForegroundMs(now + 100));

sessionTracker.updateForegroundTracker(ACTIVITY_NAME, false, now);
assertEquals(0, sessionTracker.getDurationInForeground(now + 200));
assertEquals(0, sessionTracker.getDurationInForegroundMs(now + 200));
}

@Test
public void testZeroSessionTimeout() throws Exception {
sessionTracker = new SessionTracker(configuration, generateClient(), 0, generateSessionStore(),
generateSessionTrackingApiClient(), InstrumentationRegistry.getContext());
generateSessionTrackingApiClient());

long now = System.currentTimeMillis();
sessionTracker.updateForegroundTracker(ACTIVITY_NAME, true, now);
Expand All @@ -189,7 +150,7 @@ public void testZeroSessionTimeout() throws Exception {
@Test
public void testSessionTimeout() throws Exception {
sessionTracker = new SessionTracker(configuration, generateClient(), 100, generateSessionStore(),
generateSessionTrackingApiClient(), InstrumentationRegistry.getContext());
generateSessionTrackingApiClient());

long now = System.currentTimeMillis();
sessionTracker.updateForegroundTracker(ACTIVITY_NAME, true, now);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void setUp() throws Exception {

session = generateSession();
appData = new AppData(InstrumentationRegistry.getContext(), new Configuration("a"), generateSessionTracker());
SessionTrackingPayload payload = new SessionTrackingPayload(Collections.singleton(session), appData);
SessionTrackingPayload payload = new SessionTrackingPayload(session, appData);
rootNode = streamableToJson(payload);
}

Expand All @@ -64,17 +64,6 @@ public void testPayloadSerialisation() throws Exception {
assertNotNull(rootNode.getJSONObject("app"));
}

@Test
public void testMultipleSessions() throws Exception {
SessionTrackingPayload payload = new SessionTrackingPayload(Arrays.asList(session, session), appData);
rootNode = streamableToJson(payload);

assertNotNull(rootNode);
JSONArray sessions = rootNode.getJSONArray("sessions");
assertNotNull(sessions);
assertEquals(2, sessions.length());
}

/**
* Serialises sessions from a file instead
*/
Expand Down
10 changes: 5 additions & 5 deletions sdk/src/main/java/com/bugsnag/android/AppData.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
class AppData extends AppDataSummary {

private static final long startTime = SystemClock.elapsedRealtime();
private static final long startTimeMs = SystemClock.elapsedRealtime();

@Nullable
final String appName;
Expand All @@ -43,8 +43,8 @@ public void toStream(@NonNull JsonStream writer) throws IOException {

writer.name("id").value(packageName);
writer.name("buildUUID").value(config.getBuildUUID());
writer.name("duration").value(getDuration());
writer.name("durationInForeground").value(sessionTracker.getDurationInForeground(System.currentTimeMillis()));
writer.name("duration").value(getDurationMs());
writer.name("durationInForeground").value(sessionTracker.getDurationInForegroundMs(System.currentTimeMillis()));
writer.name("inForeground").value(sessionTracker.isInForeground());

// TODO migrate legacy fields
Expand Down Expand Up @@ -117,8 +117,8 @@ private static Boolean isLowMemory(@NonNull Context appContext) {
* Get the time in milliseconds since Bugsnag was initialized, which is a
* good approximation for how long the app has been running.
*/
private static long getDuration() {
return SystemClock.elapsedRealtime() - startTime;
static long getDurationMs() {
return SystemClock.elapsedRealtime() - startTimeMs;
}


Expand Down
Loading