Skip to content

Commit 471d433

Browse files
committed
Fix tests that did not wait for IAM to display
* Some tests try to dismiss IAMs when they are added to queue but before they are displayed. Added an additional wait before running dismissCurrentMessage() to fix some flakyness in these tests. * Delay is upto 1,000ms as a buffer, normally wait is ~10x less
1 parent b9376ba commit 471d433

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

OneSignalSDK/unittest/src/test/java/com/test/onesignal/InAppMessageIntegrationTests.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,17 @@ public void testTimedMessageIsDisplayedOncePerSession() throws Exception {
366366
.pollInterval(new Duration(10, TimeUnit.MILLISECONDS))
367367
.until(() -> OneSignalPackagePrivateHelper.getInAppMessageDisplayQueue().size() == 1);
368368

369+
// After IAM is added to display queue we now need to wait until it is shown
370+
Awaitility.await()
371+
.atMost(new Duration(1_000, TimeUnit.MILLISECONDS))
372+
.pollInterval(new Duration(10, TimeUnit.MILLISECONDS))
373+
.untilAsserted(new ThrowingRunnable() {
374+
@Override
375+
public void run() {
376+
assertTrue(OneSignalPackagePrivateHelper.isInAppMessageShowing());
377+
}
378+
});
379+
369380
OneSignalPackagePrivateHelper.dismissCurrentMessage();
370381

371382
// Check that the IAM is not displayed again
@@ -1331,6 +1342,17 @@ public void testInAppMessageDisplayMultipleTimes_sessionDurationTrigger() throws
13311342
// No schedule should happen, IAM should evaluate to true
13321343
assertEquals(1, OneSignalPackagePrivateHelper.getInAppMessageDisplayQueue().size());
13331344

1345+
// After IAM is added to display queue we now need to wait until it is shown
1346+
Awaitility.await()
1347+
.atMost(new Duration(1_000, TimeUnit.MILLISECONDS))
1348+
.pollInterval(new Duration(10, TimeUnit.MILLISECONDS))
1349+
.untilAsserted(new ThrowingRunnable() {
1350+
@Override
1351+
public void run() throws Exception {
1352+
assertTrue(OneSignalPackagePrivateHelper.isInAppMessageShowing());
1353+
}
1354+
});
1355+
13341356
// Dismiss IAM will make display quantity increase and last display time to change
13351357
OneSignalPackagePrivateHelper.dismissCurrentMessage();
13361358
// Check IAMs was removed from queue

0 commit comments

Comments
 (0)