Skip to content

Commit

Permalink
test: cancel any background tasks in test runs
Browse files Browse the repository at this point in the history
  • Loading branch information
fractalwrench committed Jun 22, 2018
1 parent 7cc8a23 commit adc20c1
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 0 deletions.
6 changes: 6 additions & 0 deletions sdk/src/androidTest/java/com/bugsnag/android/AppDataTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import org.json.JSONException;
import org.json.JSONObject;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -30,6 +31,11 @@ public void setUp() throws Exception {
config = new Configuration("some-api-key");
}

@After
public void tearDown() throws Exception {
Async.cancelTasks();
}

@Test
public void testManifestData() throws JSONException, IOException {
AppData appData = generateAppData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -34,6 +35,11 @@ public void setUp() throws Exception {
config = new Configuration("api-key");
}

@After
public void tearDown() throws Exception {
Async.cancelTasks();
}

@Test
public void testRunModifiesError() {
final String context = "new-context";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -28,6 +29,11 @@ public void setUp() throws Exception {
sessionTracker = new SessionTracker(configuration, null, sessionStore);
}

@After
public void tearDown() throws Exception {
Async.cancelTasks();
}

@Test
public void testLifecycleBreadcrumbCrash() {
// should not crash with a null client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -27,6 +28,11 @@ public void setUp() throws Exception {
config = new Configuration("api-key");
}

@After
public void tearDown() throws Exception {
Async.cancelTasks();
}

@Test
public void testEndpoints() {
String notify = "https://notify.myexample.com";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import org.json.JSONException;
import org.json.JSONObject;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -36,6 +37,11 @@ public void setUp() throws Exception {
deviceData = new DeviceData(InstrumentationRegistry.getContext(), sharedPref);
}

@After
public void tearDown() throws Exception {
Async.cancelTasks();
}

@Test
public void testSaneValues() throws JSONException, IOException {
JSONObject deviceDataJson = streamableToJson(deviceData);
Expand Down
6 changes: 6 additions & 0 deletions sdk/src/androidTest/java/com/bugsnag/android/ErrorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import org.json.JSONException;
import org.json.JSONObject;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -44,6 +45,11 @@ public void setUp() throws Exception {
error = new Error.Builder(config, exception, null).build();
}

@After
public void tearDown() throws Exception {
Async.cancelTasks();
}

@Test
public void testShouldIgnoreClass() {
config.setIgnoreClasses(new String[]{"java.io.IOException"});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -28,6 +29,11 @@ public void setUp() throws Exception {
config = new Configuration("api-key");
}

@After
public void tearDown() throws Exception {
Async.cancelTasks();
}

@Test
public void testBasicException() throws JSONException, IOException {
Exceptions exceptions = new Exceptions(config, new RuntimeException("oops"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -42,6 +43,11 @@ public void setUp() throws Exception {
file.delete();
}

@After
public void tearDown() throws Exception {
Async.cancelTasks();
}

@Test
public void testSaneValues() throws JSONException, IOException {
final Long nullLong = null;
Expand Down
6 changes: 6 additions & 0 deletions sdk/src/androidTest/java/com/bugsnag/android/ReportTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -34,6 +35,11 @@ public void setUp() throws Exception {
report = new Report("api-key", error);
}

@After
public void tearDown() throws Exception {
Async.cancelTasks();
}

@Test
public void testInMemoryError() throws JSONException, IOException {
JSONObject reportJson = streamableToJson(report);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public void setUp() throws Exception {
*/
@After
public void tearDown() throws Exception {
Async.cancelTasks();
FileUtils.clearFilesInDir(storageDir);
}

Expand Down

0 comments on commit adc20c1

Please sign in to comment.