Skip to content

Commit ee1892d

Browse files
zwu52Kai Wu
andauthored
Add Foreground Message Send/Receive Integration Tests (#3216)
* Enable the FCM integration test (IT) for Chrome. Context: the tests were switched off a couple of years ago due to flakiness. It has not been maintained since then. During the time, Some Selenium API methods used were deprecated and removed; the Firebase projects used are no longer managed or owned by the FCM team. Consequently, the test became unfunctional. In the effort of providing safety for the upcoming FCM releases, this PR is created to fix, deflake, refactor and improve the old tests. This PR did the following: - Enabled comprehensive IT for chrome (ver.80). Now we are covering send&foreground recevie for FCM messages (messages with {notification} payload, {data} payload and {notification, data} payload), delete/update token, use default/customized ServiceWorker. - Defalaked test. The IT is now reasonably stable without retry. Previously we are retrying 1 or 3 times. - Optimized test. Previously we create a webDriver for each test, which is slow and annoying. Because a window is created and brought to focus and killed frequently, it makes working on other tasks and testing nearly impossible (Probably using a headless browser would work but I haven't found a satisfying solution to have the app in the state of foreground and background which is a requirement for FCM functions). With the way the tests are organized, the IT only spin up a new web driver when necessary. Some data on performance: (old) 'test-send' take 74 seconds (only measured 'test-send' because the other test suites were not functional at the time); (now) 'test-send', 'test-deleteToken', 'test-updateToken', 'test-useDefaultServiceWorker', 'test-useValidManifest' takes in total 33s (10 run average). - General refactoring. Including refactors on expect blocks, createWebDriver, use const for constants usage, etc. The code should be much easier to understand and maintain. Future work: - Enable test on firefox once I get the notification permission working. - Run the IC against some milestone chrome/firefox version (if it makes sense) to ensure backward compatibility. We should try to avoid #2712 . :) * [AUTOMATED]: License Headers * Enable integration test (IT) for FCM. Context: FCM IT were turned off a couple years ago due to flakiness. It became mostly unfunctional as repo structure change overtime. The goal is to fix and enable IT for more confident developement flow and safer releases. This CL does the following: - Fix the IT to be functional again. The IT is derteminated from my experiements (no longer flaky). Therefore, The CL removed the retry mechasim (previously retry 3 times) which makes running IT cheaper and more enjoyable. - Include IT for test:change for FCM package: the entire IT test suites is resoanblly fast (from my exeperience 1-3 miutes to complete. As it grows larger, maybe it makes run tests in parallel in Saucelab) Futhure work: - Enable testing for firefox * Correct int syntax js doesn't allow underscore for int * This file wasn't auto-saved * Trigger FCM IT why dot.env(FCM_SECRETS) are not included in env? * Test Secrets can be accessed w/o dotenv * Add fcm sercret to workflow * Update test-changed.yml * test send (background only) Because headless chrome doesn't have the concept of foreground and background * remove dotenv * feed secrest into test:all workflow * Update test-all.yml * background messaging checking * [AUTOMATED]: License Headers * rerun * added waiting * wait * Update test-send.js * Update test-send.js * Examine wrong sercret * Update sendMessage.js * Update sendMessage.js * Update sendMessage.js * Update sendMessage.js * Update sendMessage.js * update fcm project * Update package.json * Update test-send.js * open new tab for backgournd receive * removed test-send somehow not workingin github workflow? * Adding Reties * Change timeout limit * retry 3 times * adjust mocha setting * update * Enable foreground tesing * Add emtpy changeset Not a SDK Change Co-authored-by: Kai Wu <[email protected]>
1 parent 992432e commit ee1892d

File tree

2 files changed

+114
-0
lines changed

2 files changed

+114
-0
lines changed

.changeset/tender-hounds-breathe.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

integration/messaging/test/test-send.js

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const sendMessage = require('./utils/sendMessage');
2121
const retrieveToken = require('./utils/retrieveToken');
2222
const seleniumAssistant = require('selenium-assistant');
2323
const getReceivedBackgroundMessages = require('./utils/getReceivedBackgroundMessages');
24+
const getReceivedForegroundMessages = require('./utils/getReceivedForegroundMessages');
2425
const openNewTab = require('./utils/openNewTab');
2526
const createPermittedWebDriver = require('./utils/createPermittedWebDriver');
2627

@@ -35,6 +36,8 @@ const FIELD_NOTIFICATION = 'notification';
3536
// 4 minutes. The fact that the flow includes making a request to the Send Service, storing/retrieving form indexedDb asynchronously makes these test units to have a execution time variance. Therefore, allowing these units to have a longer time to work is crucial.
3637
const TIMEOUT_BACKGROUND_MESSAGE_TEST_UNIT_MILLISECONDS = 240000;
3738

39+
const TIMEOUT_FOREGROUND_MESSAGE_TEST_UNIT_MILLISECONDS = 120000;
40+
3841
// 1 minute. Wait for object store to be created and received message to be stored in idb. This waiting time MUST be longer than the wait time for adding to db in the sw.
3942
const WAIT_TIME_BEFORE_RETRIEVING_BACKGROUND_MESSAGES_MILLISECONDS = 60000;
4043

@@ -122,6 +125,115 @@ describe('Starting Integration Test > Sending and Receiving ', function() {
122125
/* expectedDataPayload= */ getTestDataPayload()
123126
);
124127
});
128+
129+
it('Foreground app can receive a {} empty message in onMessage', async function() {
130+
this.timeout(TIMEOUT_FOREGROUND_MESSAGE_TEST_UNIT_MILLISECONDS);
131+
132+
await seleniumAssistant.killWebDriver(globalWebDriver);
133+
134+
globalWebDriver = createPermittedWebDriver(
135+
/* browser= */ assistantBrowser.getId()
136+
);
137+
138+
await globalWebDriver.get(
139+
`${testServer.serverAddress}/${TEST_DOMAIN}/`
140+
);
141+
142+
let token = await retrieveToken(globalWebDriver);
143+
checkSendResponse(
144+
await sendMessage({
145+
to: token
146+
})
147+
);
148+
149+
await checkMessageReceived(
150+
await getReceivedForegroundMessages(globalWebDriver),
151+
/* expectedNotificationPayload= */ null,
152+
/* expectedDataPayload= */ null
153+
);
154+
});
155+
156+
it('Foreground app can receive a {"notification"} message in onMessage', async function() {
157+
this.timeout(TIMEOUT_FOREGROUND_MESSAGE_TEST_UNIT_MILLISECONDS);
158+
159+
await seleniumAssistant.killWebDriver(globalWebDriver);
160+
161+
globalWebDriver = createPermittedWebDriver(
162+
/* browser= */ assistantBrowser.getId()
163+
);
164+
165+
await globalWebDriver.get(
166+
`${testServer.serverAddress}/${TEST_DOMAIN}/`
167+
);
168+
169+
checkSendResponse(
170+
await sendMessage({
171+
to: await retrieveToken(globalWebDriver),
172+
notification: getTestNotificationPayload()
173+
})
174+
);
175+
176+
await checkMessageReceived(
177+
await getReceivedForegroundMessages(globalWebDriver),
178+
/* expectedNotificationPayload= */ getTestNotificationPayload(),
179+
/* expectedDataPayload= */ null
180+
);
181+
});
182+
183+
it('Foreground app can receive a {"data"} message in onMessage', async function() {
184+
this.timeout(TIMEOUT_FOREGROUND_MESSAGE_TEST_UNIT_MILLISECONDS);
185+
186+
await seleniumAssistant.killWebDriver(globalWebDriver);
187+
188+
globalWebDriver = createPermittedWebDriver(
189+
/* browser= */ assistantBrowser.getId()
190+
);
191+
192+
await globalWebDriver.get(
193+
`${testServer.serverAddress}/${TEST_DOMAIN}/`
194+
);
195+
196+
checkSendResponse(
197+
await sendMessage({
198+
to: await retrieveToken(globalWebDriver),
199+
data: getTestDataPayload()
200+
})
201+
);
202+
203+
await checkMessageReceived(
204+
await getReceivedForegroundMessages(globalWebDriver),
205+
/* expectedNotificationPayload= */ null,
206+
/* expectedDataPayload= */ getTestDataPayload()
207+
);
208+
});
209+
210+
it('Foreground app can receive a {"notification", "data"} message in onMessage', async function() {
211+
this.timeout(TIMEOUT_FOREGROUND_MESSAGE_TEST_UNIT_MILLISECONDS);
212+
213+
await seleniumAssistant.killWebDriver(globalWebDriver);
214+
215+
globalWebDriver = createPermittedWebDriver(
216+
/* browser= */ assistantBrowser.getId()
217+
);
218+
219+
await globalWebDriver.get(
220+
`${testServer.serverAddress}/${TEST_DOMAIN}/`
221+
);
222+
223+
checkSendResponse(
224+
await sendMessage({
225+
to: await retrieveToken(globalWebDriver),
226+
data: getTestDataPayload(),
227+
notification: getTestNotificationPayload()
228+
})
229+
);
230+
231+
await checkMessageReceived(
232+
await getReceivedForegroundMessages(globalWebDriver),
233+
/* expectedNotificationPayload= */ getTestNotificationPayload(),
234+
/* expectedDataPayload= */ getTestDataPayload()
235+
);
236+
});
125237
});
126238
});
127239
});

0 commit comments

Comments
 (0)