Browse Source

test: CY wait for PG connection to be up

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>
pull/3597/head
Raju Udava 2 years ago committed by Pranav C
parent
commit
fa8b806a84
  1. 23
      scripts/cypress/integration/common/00_pre_configurations.js
  2. 29
      scripts/cypress/plugins/index.js

23
scripts/cypress/integration/common/00_pre_configurations.js

@ -168,9 +168,7 @@ export const genTest = (apiType, dbType) => {
loginPage.signUp(roles.owner.credentials);
});
const createProject = (proj) => {
it(`Create ${proj.basic.name} project`, () => {
function cy_createProjectBlock(proj) {
// click home button
cy.get(".nc-noco-brand-icon").click();
cy.get(".ant-table-content").then((obj) => {
@ -238,11 +236,20 @@ export const genTest = (apiType, dbType) => {
}
}
});
}
// hack to disable dark mode
cy.fileHook();
const createProject = (proj) => {
it(`Create ${proj.basic.name} project`, () => {
if(dbType === "postgres") {
// wait for docker compose to start
cy.task(
'pgExecTest',
`SELECT 1+1`, {timeout: 120000}
).then(() => cy_createProjectBlock(proj));
}
else {
cy_createProjectBlock(proj);
}
});
};
@ -251,7 +258,7 @@ export const genTest = (apiType, dbType) => {
} else if (dbType === "mysql") {
createProject(staticProjects.externalREST);
} else if (dbType === "postgres") {
createProject(staticProjects.pgExternalREST);
createProject(staticProjects.externalREST);
}
});
};

29
scripts/cypress/plugins/index.js

@ -77,6 +77,9 @@ module.exports = (on, config) => {
_pgExec(query);
return null;
},
pgExecTest: (query) => {
return _pgExecTest(query);
}
});
let server, port, close
@ -202,6 +205,32 @@ function _pgExec(query) {
});
}
function _pgExecTest(query, retryCount = 60) {
return new Promise((resolve, reject) => {
// open pg client connection
const client = new Client(pg_credentials);
client.connect().catch(() => {
client.end();
});
// query & terminate
client.query(query, (err, res) => {
if (err) {
if (retryCount--)
return setTimeout(() => _pgExecTest(query, retryCount).then(resolve).catch(reject), 2000);
else
reject(err);
}
console.log('==== success ===', res);
resolve(true);
client.end();
});
});
}
/**
* @copyright Copyright (c) 2021, Xgene Cloud Ltd
*

Loading…
Cancel
Save