Commit cf258e8
[SDK-115] Re-enable PushNotificationIntegrationTest with iOS-aligned wait pattern
Phase-A fix for the push test that the parent SDK-115 commit @ignore'd.
Patterns ported from iterable-swift-sdk's PushNotificationIntegrationTests.
Root causes (from local logcat against BCIT):
1. Token-registration race: BaseIntegrationTest.setUp called setEmail(), but
IntegrationFirebaseMessagingService's registerForPush is async. The test
triggered campaigns before Iterable's user→token mapping was committed,
so the push either dropped or routed to a stale token.
2. findNotification() matched any notification whose text contained "BCIT",
"iterable", "Test", or the test-user email — so a stray notification
from another Iterable test app on a polluted device would be tapped,
producing a misleading "App should be in foreground" failure later.
3. Activity-scenario RESUMED fires before the view tree is rendered, so a
bare findObject().exists() on btnPushNotifications occasionally raced
the inflater.
4. uiDevice.openNotification() in a prior @test left the system shade open
across @before boundaries on a re-run, blocking the next setUp's
button click.
Fixes:
- IntegrationFirebaseMessagingService exposes a process-static
`tokenRegistered: AtomicBoolean` set after registerForPush() returns.
Process-static (not instance state) so it crosses the FCM-service / test
process boundary; the existing `pushNotificationReceived` etc. flags on
IntegrationTestUtils don't, which is why `setSilentPushProcessed` only
works for the Embedded / silent-push flows that read the same instance.
- BaseIntegrationTest.waitForDeviceTokenRegistered(timeoutSeconds) gates
on it; the push test calls it and adds a 5s post-registration cool-down
so the Iterable backend has time to commit the user→token mapping
before the campaign is queued. Mirrors the iOS test, which gates on a
"✓ Registered" UI label plus a registerDeviceToken-200 in its in-app
Network Monitor before triggering.
- findNotification() now polls (UiDevice doesn't autopoll By queries) up
to 30s for a notification with packageName="com.android.systemui" and
title containing "BCIT Push Notification Test". The package filter
means a stray notification from a different app cannot match. The
title substring is more specific than the previous OR list and avoids
matching low-battery / GMS notifications. 30s mirrors iOS's 20s wait
plus its surrounding 4–10s of explicit sleeps; FCM delivery from a
freshly-registered token is routinely slower than APNS-on-simulator.
- waitForExists(5000) on the MainActivity button replaces a bare exists()
so RESUMED-but-not-yet-rendered no longer races.
- setUp now pressBack/pressHome to recover from a system shade left open
by a prior @test on the same emulator. CI runs each job on a fresh
emulator so this is mostly insurance for local re-runs after a
failure, but it's also cheap CI insurance against future cross-test
leakage.
- Remove @ignore.
Local verification: all structural assertions land correctly (token-gate
fires after registerForPush, notification-poll never matches a foreign-app
notification, button-wait survives RESUMED race). Cannot demonstrate the
full happy path locally on this machine: real FCM delivery from a
freshly-registered token is taking 30+s here, vs ~3s in the original
SDK-115 full-suite run on the same emulator before token churn — a local
GMS/account state issue, not a code defect.
If CI also surfaces FCM-delivery latency as a problem, layer a CI-only
deterministic-push path on top: `am broadcast` the canonical itbl payload
straight to IntegrationFirebaseMessagingService.onMessageReceived, mirroring
iOS's `xcrun simctl push booted` shape. Defer that to a follow-up commit
on this branch only if needed.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>1 parent a14f709 commit cf258e8
3 files changed
Lines changed: 85 additions & 24 deletions
File tree
- integration-tests/src
- androidTest/java/com/iterable/integration/tests
- main/java/com/iterable/integration/tests/services
Lines changed: 17 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
164 | 165 | | |
165 | 166 | | |
166 | 167 | | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
167 | 184 | | |
168 | 185 | | |
169 | 186 | | |
| |||
Lines changed: 56 additions & 21 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | 19 | | |
21 | 20 | | |
22 | 21 | | |
23 | 22 | | |
24 | 23 | | |
25 | 24 | | |
26 | | - | |
| 25 | + | |
27 | 26 | | |
28 | 27 | | |
29 | 28 | | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
30 | 37 | | |
31 | 38 | | |
32 | 39 | | |
| |||
35 | 42 | | |
36 | 43 | | |
37 | 44 | | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
38 | 51 | | |
39 | | - | |
| 52 | + | |
40 | 53 | | |
41 | 54 | | |
42 | 55 | | |
43 | 56 | | |
44 | | - | |
| 57 | + | |
45 | 58 | | |
46 | 59 | | |
47 | 60 | | |
| |||
62 | 75 | | |
63 | 76 | | |
64 | 77 | | |
| 78 | + | |
| 79 | + | |
65 | 80 | | |
66 | | - | |
| 81 | + | |
67 | 82 | | |
68 | 83 | | |
69 | 84 | | |
70 | 85 | | |
71 | 86 | | |
72 | 87 | | |
73 | 88 | | |
74 | | - | |
75 | 89 | | |
76 | 90 | | |
77 | 91 | | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
78 | 103 | | |
79 | 104 | | |
80 | 105 | | |
| |||
93 | 118 | | |
94 | 119 | | |
95 | 120 | | |
96 | | - | |
| 121 | + | |
97 | 122 | | |
98 | 123 | | |
99 | 124 | | |
| |||
161 | 186 | | |
162 | 187 | | |
163 | 188 | | |
164 | | - | |
165 | 189 | | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
179 | 213 | | |
| 214 | + | |
180 | 215 | | |
181 | 216 | | |
182 | 217 | | |
| |||
Lines changed: 12 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | | - | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
13 | 21 | | |
14 | | - | |
| 22 | + | |
15 | 23 | | |
16 | 24 | | |
17 | 25 | | |
18 | | - | |
| 26 | + | |
19 | 27 | | |
20 | 28 | | |
21 | 29 | | |
22 | 30 | | |
| 31 | + | |
23 | 32 | | |
24 | 33 | | |
25 | 34 | | |
| |||
0 commit comments