Skip to content

Commit

Permalink
Merge branch 'next' into use-buffered-streams
Browse files Browse the repository at this point in the history
  • Loading branch information
fractalwrench committed May 9, 2018
2 parents 4969511 + f76d408 commit 8564c42
Show file tree
Hide file tree
Showing 15 changed files with 398 additions and 102 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# Changelog

## 4.3.4 (2018-05-02)

### Bug fixes

* Avoid adding extra comma separator in JSON if File input is empty or null
[#284](https://github.com/bugsnag/bugsnag-android/pull/284)

* Thread safety fixes to JSON file serialisation
[#295](https://github.com/bugsnag/bugsnag-android/pull/295)

* Prevent potential automatic activity lifecycle breadcrumb crash
[#300](https://github.com/bugsnag/bugsnag-android/pull/300)

* Fix serialisation issue with leading to incorrect dashboard display of breadcrumbs
[#306](https://github.com/bugsnag/bugsnag-android/pull/306)

## 4.3.3 (2018-04-04)

### Bug fixes
Expand Down
3 changes: 2 additions & 1 deletion features/breadcrumb.feature
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Scenario: Manually added breadcrumbs are sent in report
And the event "breadcrumbs.1.metaData.Foo" equals "Bar"

And the event "breadcrumbs.0.timestamp" is not null
And the event "breadcrumbs.0.name" equals "Hello Breadcrumb!"
And the event "breadcrumbs.0.name" equals "manual"
And the event "breadcrumbs.0.type" equals "manual"
And the event "breadcrumbs.0.metaData" is not null
And the event "breadcrumbs.0.metaData.message" equals "Hello Breadcrumb!"
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ org.gradle.jvmargs=-Xmx1536m
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
VERSION_NAME=4.3.3
VERSION_NAME=4.3.4
GROUP=com.bugsnag
POM_SCM_URL=https://github.com/bugsnag/bugsnag-android
POM_SCM_CONNECTION=scm:git@github.com:bugsnag/bugsnag-android.git
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.bugsnag.android;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(AndroidJUnit4.class)
@SmallTest
public class BreadcrumbLifecycleCrashTest {

private SessionTracker sessionTracker;

/**
* Creates a SessionTracker with a null client
*
* @throws Exception if the SessionTracker couldn't be created
*/
@Before
public void setUp() throws Exception {
Configuration configuration = new Configuration("api-key");
Context context = InstrumentationRegistry.getContext();
SessionStore sessionStore = new SessionStore(configuration, context);
SessionTrackingApiClient apiClient = BugsnagTestUtils.generateSessionTrackingApiClient();
sessionTracker = new SessionTracker(configuration, null, sessionStore, apiClient);
}

@Test
public void testLifecycleBreadcrumbCrash() {
// should not crash with a null client
sessionTracker.leaveLifecycleBreadcrumb("FooActivity", "onCreate");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package com.bugsnag.android;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

@RunWith(AndroidJUnit4.class)
@SmallTest
public class ClientNotifyAsyncTest {

private Client client;
private NullCheckClient apiClient;

/**
* Generates a configuration and clears sharedPrefs values to begin the test with a clean slate
*
* @throws Exception if initialisation failed
*/
@Before
public void setUp() throws Exception {
client = BugsnagTestUtils.generateClient();
apiClient = new NullCheckClient();
client.setErrorReportApiClient(apiClient);
}

@Test
public void testNotifyAsyncMetadata() throws Exception {
MetaData metaData = new MetaData();
metaData.addToTab("animals", "dog", true);

client.notify(new RuntimeException("Foo"), metaData);
assertNull(apiClient.report);
apiClient.nullCheckLatch.countDown();

apiClient.awaitReport();
assertNotNull(apiClient.report);
MetaData data = apiClient.report.getError().getMetaData();
assertTrue((Boolean) data.getTab("animals").get("dog"));
}

@Test
public void testNotifyAsyncSeverity() throws Exception {
client.notify(new RuntimeException("Foo"), Severity.INFO);
assertNull(apiClient.report);
apiClient.nullCheckLatch.countDown();

apiClient.awaitReport();
assertNotNull(apiClient.report);
assertEquals(Severity.INFO, apiClient.report.getError().getSeverity());
}

@Test
public void testNotifyAsyncSeverityMetadata() throws Exception {
MetaData metaData = new MetaData();
metaData.addToTab("animals", "bird", "chicken");

client.notify(new RuntimeException("Foo"), Severity.ERROR, metaData);
assertNull(apiClient.report);
apiClient.nullCheckLatch.countDown();

apiClient.awaitReport();
assertNotNull(apiClient.report);
MetaData data = apiClient.report.getError().getMetaData();
assertEquals("chicken", data.getTab("animals").get("bird"));
assertEquals(Severity.ERROR, apiClient.report.getError().getSeverity());
}

@Test
public void testNotifyAsyncCallback() throws Exception {
client.notify(new RuntimeException("Foo"), new Callback() {
@Override
public void beforeNotify(Report report) {
report.getError().setContext("Manual");
}
});
assertNull(apiClient.report);
apiClient.nullCheckLatch.countDown();

apiClient.awaitReport();
assertNotNull(apiClient.report);
assertEquals("Manual", apiClient.report.getError().getContext());
}

static class NullCheckClient extends ClientNotifyTest.FakeClient {

CountDownLatch nullCheckLatch = new CountDownLatch(1);

@Override
public void postReport(String urlString,
Report report,
Map<String, String> headers)
throws NetworkException, BadResponseException {
try {
nullCheckLatch.await(100, TimeUnit.MILLISECONDS);
} catch (InterruptedException exception) {
exception.printStackTrace();
}
super.postReport(urlString, report, headers);
}
}

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.bugsnag.android;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
Expand Down Expand Up @@ -78,60 +75,6 @@ public void beforeNotify(Report report) {
assertEquals("Message", error.getExceptionMessage());
}

@Test
public void testNotifyAsyncMetadata() throws Exception {
MetaData metaData = new MetaData();
metaData.addToTab("animals", "dog", true);

client.notify(new RuntimeException("Foo"), metaData);
assertNull(apiClient.report);

apiClient.awaitReport();
assertNotNull(apiClient.report);
MetaData data = apiClient.report.getError().getMetaData();
assertTrue((Boolean) data.getTab("animals").get("dog"));
}

@Test
public void testNotifyAsyncSeverity() throws Exception {
client.notify(new RuntimeException("Foo"), Severity.INFO);
assertNull(apiClient.report);

apiClient.awaitReport();
assertNotNull(apiClient.report);
assertEquals(Severity.INFO, apiClient.report.getError().getSeverity());
}

@Test
public void testNotifyAsyncSeverityMetadata() throws Exception {
MetaData metaData = new MetaData();
metaData.addToTab("animals", "bird", "chicken");

client.notify(new RuntimeException("Foo"), Severity.ERROR, metaData);
assertNull(apiClient.report);

apiClient.awaitReport();
assertNotNull(apiClient.report);
MetaData data = apiClient.report.getError().getMetaData();
assertEquals("chicken", data.getTab("animals").get("bird"));
assertEquals(Severity.ERROR, apiClient.report.getError().getSeverity());
}

@Test
public void testNotifyAsyncCallback() throws Exception {
client.notify(new RuntimeException("Foo"), new Callback() {
@Override
public void beforeNotify(Report report) {
report.getError().setContext("Manual");
}
});
assertNull(apiClient.report);

apiClient.awaitReport();
assertNotNull(apiClient.report);
assertEquals("Manual", apiClient.report.getError().getContext());
}

static class FakeClient implements ErrorReportApiClient {

CountDownLatch latch = new CountDownLatch(1);
Expand All @@ -143,7 +86,7 @@ public void postReport(String urlString,
Map<String, String> headers)
throws NetworkException, BadResponseException {
try {
Thread.sleep(1); // simulate async request
Thread.sleep(10); // simulate async request
} catch (InterruptedException ignored) {
ignored.printStackTrace();
}
Expand Down

0 comments on commit 8564c42

Please sign in to comment.