Skip to content

Commit 5e4dcd3

Browse files
authored
Merge pull request #1584 from OneSignal/fix/flaky_test_shouldSetExpireTimeCorrectlyWhenMissingFromPayload
[Fix Tests] Top Flaky tests; shouldSetExpireTimeCorrectlyWhenMissingFromPayload and HMS osIAMPreview_showsPreview
2 parents d3acf89 + 72449b2 commit 5e4dcd3

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ public long getElapsedRealtime() {
2020
return mockedElapsedTime != null ? mockedElapsedTime : super.getElapsedRealtime();
2121
}
2222

23+
public void freezeTime() {
24+
mockedTime = getCurrentTimeMillis();
25+
mockedElapsedTime = getElapsedRealtime();
26+
}
27+
2328
public void setMockedTime(Long mockedTime) {
2429
this.mockedTime = mockedTime;
2530
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1271,11 +1271,14 @@ public void notShowNotificationPastTTL() throws Exception {
12711271
@Test
12721272
@Config(shadows = { ShadowGenerateNotification.class })
12731273
public void shouldSetExpireTimeCorrectlyWhenMissingFromPayload() throws Exception {
1274+
time.freezeTime();
12741275
NotificationBundleProcessor_ProcessFromFCMIntentService(blankActivity, getBaseNotifBundle());
12751276
threadAndTaskWait();
12761277

1278+
long currentTime = time.getCurrentTimeMillis() / 1_000L;
12771279
long expireTime = (Long)TestHelpers.getAllNotificationRecords(dbHelper).get(0).get(NotificationTable.COLUMN_NAME_EXPIRE_TIME);
1278-
assertEquals((System.currentTimeMillis() / 1_000L) + 259_200, expireTime);
1280+
long expectedExpireTime = currentTime + 259_200;
1281+
assertEquals(expectedExpireTime, expireTime);
12791282
}
12801283

12811284
// TODO: Once we figure out the correct way to process notifications with high priority using the WorkManager

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ public void osIAMPreview_showsPreview() throws Exception {
200200
);
201201

202202
helper_startHMSOpenActivity(intent);
203+
threadAndTaskWait();
204+
threadAndTaskWait();
203205
assertEquals("PGh0bWw+PC9odG1sPgoKPHNjcmlwdD4KICAgIHNldFBsYXllclRhZ3MobnVsbCk7Cjwvc2NyaXB0Pg==", ShadowOSWebView.lastData);
204206
}
205207
}

0 commit comments

Comments
 (0)