Skip to content

Commit 0c053e0

Browse files
authored
wait for service connection (#2186)
1 parent 02dbd3f commit 0c053e0

File tree

3 files changed

+43
-5
lines changed

3 files changed

+43
-5
lines changed

tests/e2e/tutorials/tutorialBase.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class TutorialBase {
120120
listThem: false
121121
}];
122122

123-
for (let i=0; i<resources.length; i++) {
123+
for (let i = 0; i < resources.length; i++) {
124124
const resource = resources[i];
125125
this.__responsesQueue.addResponseListener(resource.request);
126126
}
@@ -133,7 +133,7 @@ class TutorialBase {
133133
throw (err);
134134
}
135135

136-
for (let i=0; i<resources.length; i++) {
136+
for (let i = 0; i < resources.length; i++) {
137137
const resource = resources[i];
138138
try {
139139
const resp = await this.__responsesQueue.waitUntilResponse(resource.request);
@@ -211,17 +211,19 @@ class TutorialBase {
211211
while ((new Date().getTime()) - start < timeout) {
212212
for (let i = nodeIds.length - 1; i >= 0; i--) {
213213
const nodeId = nodeIds[i];
214-
if (await utils.isServiceReady(this.__page, studyId, nodeId)) {
214+
if (await utils.isServiceReady(this.__page, studyId, nodeId) && await utils.isServiceConnected(this.__page, studyId, nodeId)) {
215215
nodeIds.splice(i, 1);
216216
}
217217
}
218-
await utils.sleep(5000);
218+
219219
if (nodeIds.length === 0) {
220220
console.log("Services ready in", ((new Date().getTime()) - start) / 1000);
221221
// after the service is responsive we need to wait a bit until the iframe is rendered
222222
await utils.sleep(3000);
223223
return;
224224
}
225+
226+
await utils.sleep(2500);
225227
}
226228
const errorMsg = "Timeout reached waiting for services";
227229
console.log(errorMsg, ((new Date().getTime()) - start) / 1000);

tests/e2e/utils/startPuppe.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ function listenToEvents(page) {
8282
async function getPage(browser) {
8383
const page = await browser.newPage();
8484
page.setCacheEnabled(false);
85+
// NOTE: activate to see what happens in puppeteer evaluate function
86+
// page.on('console', consoleObj => console.log(consoleObj.text()));
8587
await page.setViewport({
8688
width: 1920,
8789
height: 1080

tests/e2e/utils/utils.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,39 @@ async function isServiceReady(page, studyId, nodeId) {
211211
return stopListening.includes(status);
212212
}
213213

214+
async function getServiceUrl(page, studyId, nodeId) {
215+
const endPoint = "/projects/" + studyId + "/nodes/" + nodeId;
216+
console.log("-- get service url", endPoint);
217+
const resp = await makeRequest(page, endPoint);
218+
219+
const service_basepath = resp["service_basepath"];
220+
const service_entrypoint = resp["entry_point"];
221+
const service_url = service_basepath + (service_entrypoint ? ("/" + service_entrypoint) : "/");
222+
console.log("Service URL:", nodeId, service_url);
223+
224+
return service_url;
225+
}
226+
227+
async function makePingRequest(page, path) {
228+
// https://github.com/Netflix/pollyjs/issues/149#issuecomment-481108446
229+
await page.setBypassCSP(true);
230+
return await page.evaluate(async (path) => {
231+
const url = (path).replace(/\/\//g, "\/");
232+
console.log("makePingRequest", url);
233+
return fetch(url, { accept: '*/*', cache: 'no-cache' })
234+
.then(response => { console.log("ping response status:", response.status); return response.ok; })
235+
.catch(error => { console.error(error); });
236+
}, path);
237+
}
238+
239+
async function isServiceConnected(page, studyId, nodeId) {
240+
console.log("-- Is Service Connected", nodeId);
241+
const serviceUrl = await getServiceUrl(page, studyId, nodeId);
242+
connected = await makePingRequest(page, serviceUrl);
243+
console.log(connected, "--")
244+
return connected;
245+
}
246+
214247
async function isStudyDone(page, studyId) {
215248
const endPoint = "/projects/" + studyId + "/state";
216249
console.log("-- Is study done", endPoint);
@@ -360,7 +393,7 @@ async function typeInInputElement(page, inputSelector, text) {
360393
});
361394
}
362395

363-
function isElementVisible (page, selector) {
396+
function isElementVisible(page, selector) {
364397
return page.evaluate(selector => {
365398
const element = document.querySelector(selector)
366399
return !!(element && (element.offsetWidth || element.offsetHeight || element.getClientRects().length))
@@ -386,6 +419,7 @@ module.exports = {
386419
dragAndDrop,
387420
waitForResponse,
388421
isServiceReady,
422+
isServiceConnected,
389423
isStudyDone,
390424
isStudyUnlocked,
391425
waitForValidOutputFile,

0 commit comments

Comments
 (0)