diff --git a/back/tests-helper.js b/back/tests-helper.js index 96f75f0642..e15859d635 100644 --- a/back/tests-helper.js +++ b/back/tests-helper.js @@ -17,7 +17,7 @@ async function init() { }); // FIXME: Workaround to wait for loopback to be ready app.emit('started'); - await app.models.Application.status(); + await getStatus(); } async function deinit() { @@ -33,3 +33,20 @@ module.exports = { if (require.main === module) init(); +async function getStatus() { + const MAX_ATTEMPTS = 10; + let attempts = 0; + return new Promise((resolve, reject) => { + const intervalo = setInterval(async() => { + try { + const resultado = await app.models.Application.status(); + clearInterval(intervalo); + resolve(resultado); + } catch (error) { + console.log('Attempt to connect ' + attempts + '/' + MAX_ATTEMPTS); + if (attempts >= MAX_ATTEMPTS)reject(error); + } + attempts++; + }, 100); + }); +}