Skip to content

Commit c32db2c

Browse files
authored
E2-9593 run saveRequestsForLater on same thread as sendRequests (#283)
* test build * run saveRequestsForLater on same thread as sendRequests and update tests * remove extra line
1 parent 6c3f04a commit c32db2c

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

AndroidSDKCore/src/main/java/com/leanplum/internal/RequestOld.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,14 @@ public void sendEventually() {
699699
if (!sent) {
700700
sent = true;
701701
Map<String, Object> args = createArgsDictionary();
702-
saveRequestForLater(args);
702+
Util.executeAsyncTask(true, new AsyncTask<Void, Void, Void>() {
703+
@Override
704+
protected Void doInBackground(Void... params) {
705+
Map<String, Object> args = createArgsDictionary();
706+
saveRequestForLater(args);
707+
return null;
708+
}
709+
});
703710
}
704711
Leanplum.countAggregator().incrementCount("send_eventually");
705712
}

AndroidSDKTests/src/test/java/com/leanplum/internal/RequestOldTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import com.leanplum.Leanplum;
2626
import com.leanplum.__setup.LeanplumTestApp;
27+
import com.leanplum._whitebox.utilities.SynchronousExecutor;
2728

2829
import junit.framework.TestCase;
2930

@@ -34,6 +35,7 @@
3435
import org.robolectric.RobolectricTestRunner;
3536
import org.robolectric.RuntimeEnvironment;
3637
import org.robolectric.annotation.Config;
38+
import org.robolectric.util.ReflectionHelpers;
3739

3840
import java.lang.reflect.InvocationTargetException;
3941
import java.lang.reflect.Method;
@@ -69,6 +71,9 @@ public void setUp() {
6971
Application context = RuntimeEnvironment.application;
7072
assertNotNull(context);
7173
Leanplum.setApplicationContext(context);
74+
75+
// Mock this so async things run synchronously
76+
ReflectionHelpers.setStaticField(Util.class, "singleThreadExecutor", new SynchronousExecutor());
7277
}
7378

7479
/** Test that request include a generated request id **/

0 commit comments

Comments
 (0)