Repository navigation
[SDK-791] Display in-app messages on the main thread when showMessage is called off it #1102
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
Open
joaodordio
wants to merge
3
commits into
master
Choose a base branch
from
fix/SDK-791-show-message-main-thread
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
b2de2cc
[SDK-791] Display in-app messages on the main thread when showMessageβ¦
joaodordio cc3f827
[SDK-791] Document deferred read/consume state and assert it in tests
joaodordio 6eedcb6
Update iterableapi/src/main/java/com/iterable/iterableapi/IterableInAβ¦
joaodordio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
iterableapi/src/test/java/com/iterable/iterableapi/IterableInAppManagerThreadingTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| package com.iterable.iterableapi; | ||
|
|
||
| import static android.os.Looper.getMainLooper; | ||
| import static junit.framework.Assert.assertFalse; | ||
| import static junit.framework.Assert.assertNotNull; | ||
| import static junit.framework.Assert.assertNull; | ||
| import static junit.framework.Assert.assertTrue; | ||
| import static org.robolectric.Shadows.shadowOf; | ||
|
|
||
| import android.os.Handler; | ||
| import android.os.HandlerThread; | ||
|
|
||
| import androidx.activity.ComponentActivity; | ||
|
|
||
| import org.junit.After; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
| import org.robolectric.Robolectric; | ||
| import org.robolectric.android.controller.ActivityController; | ||
| import org.robolectric.shadows.ShadowDialog; | ||
|
|
||
| import java.util.concurrent.CountDownLatch; | ||
| import java.util.concurrent.TimeUnit; | ||
| import java.util.concurrent.atomic.AtomicReference; | ||
|
|
||
| public class IterableInAppManagerThreadingTest extends BaseTest { | ||
|
|
||
| private ActivityController<ComponentActivity> controller; | ||
| private IterableInAppManager inAppManager; | ||
| private IterableInAppMessage message; | ||
|
|
||
| @Before | ||
| public void setUp() throws Exception { | ||
| IterableTestUtils.createIterableApiNew(); | ||
| controller = Robolectric.buildActivity(ComponentActivity.class).create().start().resume(); | ||
| shadowOf(getMainLooper()).idle(); | ||
| inAppManager = IterableApi.getInstance().getInAppManager(); | ||
| message = InAppTestUtils.getTestInAppMessage(); | ||
| } | ||
|
|
||
| @After | ||
| public void tearDown() { | ||
| if (ShadowDialog.getLatestDialog() != null) { | ||
| ShadowDialog.getLatestDialog().dismiss(); | ||
| } | ||
| if (controller != null) { | ||
| controller.pause().stop().destroy(); | ||
| } | ||
| IterableTestUtils.resetIterableApi(); | ||
| } | ||
|
|
||
| @Test | ||
| public void showMessage_fromBackgroundLooperThread_displaysOnMainThreadWithoutCrashing() throws InterruptedException { | ||
| // A looper thread, like the React Native native-modules thread. | ||
| HandlerThread background = new HandlerThread("background"); | ||
| background.start(); | ||
| final AtomicReference<Throwable> thrown = new AtomicReference<>(); | ||
| final CountDownLatch done = new CountDownLatch(1); | ||
| new Handler(background.getLooper()).post(new Runnable() { | ||
| @Override | ||
| public void run() { | ||
| try { | ||
| inAppManager.showMessage(message, true, null); | ||
| } catch (Throwable t) { | ||
| thrown.set(t); | ||
| } finally { | ||
| done.countDown(); | ||
| } | ||
| } | ||
| }); | ||
| assertTrue(done.await(5, TimeUnit.SECONDS)); | ||
| background.quitSafely(); | ||
|
|
||
| assertNull(thrown.get()); | ||
| assertNull(IterableInAppDialogNotification.getInstance()); | ||
| assertFalse(message.isRead()); | ||
| assertFalse(message.isMarkedForDeletion()); | ||
|
|
||
| shadowOf(getMainLooper()).idle(); | ||
|
|
||
| assertNotNull(IterableInAppDialogNotification.getInstance()); | ||
| assertTrue(message.isRead()); | ||
| assertTrue(message.isMarkedForDeletion()); | ||
| } | ||
|
|
||
| @Test | ||
| public void showMessage_fromMainThread_displaysSynchronously() { | ||
| inAppManager.showMessage(message, true, null); | ||
|
|
||
| assertNotNull(IterableInAppDialogNotification.getInstance()); | ||
| assertTrue(message.isRead()); | ||
| assertTrue(message.isMarkedForDeletion()); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
~L252β254 and ~L268: Threading Javadoc is missing on two public overloads
What the spec says: SDK-791 acceptance criteria: βJavadoc on showMessage states the threading behaviour.β The work item names the 4-argument overload as the method that changes.
Why it conflicts: Callers of showMessage(message, location) and showMessage(message, consume, clickCallback, location) do not see the new contract on the method they invoke. The documented overloads do state it, so the checkbox is met for those entry points.
Suggested action: Add the same threading sentence to the location overload and the 4-argument overload.