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

Add test for launch crash #234

Merged
merged 1 commit into from
Jan 26, 2018
Merged
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
12 changes: 12 additions & 0 deletions sdk/src/androidTest/java/com/bugsnag/android/ErrorStoreTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,18 @@ public void testComparator() throws Exception {
assertTrue(ERROR_REPORT_COMPARATOR.compare(new File(second), new File(startup)) > 0);
}

@Test
public void isStartupCrash() throws Exception {
assertTrue(errorStore.isStartupCrash(0));

config.setLaunchCrashThresholdMs(0);
assertFalse(errorStore.isStartupCrash(0));

config.setLaunchCrashThresholdMs(10000);
assertTrue(errorStore.isStartupCrash(5345));
assertTrue(errorStore.isStartupCrash(9999));
assertFalse(errorStore.isStartupCrash(10000));
}

/**
* Ensures that the file can be serialised back into a JSON report, and contains the same info
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.Date;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
Expand Down Expand Up @@ -50,9 +48,4 @@ public void testMultipleClients() {
assertEquals(2, bugsnagHandler.clientMap.size());
}

@Test
public void testIsCrashOnLaunch() throws Exception {
//TODO:SM Replace this
}

}
6 changes: 5 additions & 1 deletion sdk/src/main/java/com/bugsnag/android/ErrorStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,13 @@ private List<File> findLaunchCrashReports() {
@NonNull
@Override
String getFilename(Error error) {
boolean isStartupCrash = AppData.getDurationMs() < config.getLaunchCrashThresholdMs();
boolean isStartupCrash = isStartupCrash(AppData.getDurationMs());
String suffix = isStartupCrash ? STARTUP_CRASH : "";
return String.format(Locale.US, "%s%d%s.json", storeDirectory, System.currentTimeMillis(), suffix);
}

boolean isStartupCrash(long durationMs) {
return durationMs < config.getLaunchCrashThresholdMs();
}

}