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. 149
      scripts/cypress/integration/common/00_pre_configurations.js
  2. 29
      scripts/cypress/plugins/index.js

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

@ -168,81 +168,88 @@ export const genTest = (apiType, dbType) => {
loginPage.signUp(roles.owner.credentials);
});
const createProject = (proj) => {
it(`Create ${proj.basic.name} project`, () => {
// click home button
cy.get(".nc-noco-brand-icon").click();
cy.get(".ant-table-content").then((obj) => {
function cy_createProjectBlock(proj) {
// click home button
cy.get(".nc-noco-brand-icon").click();
cy.get(".ant-table-content").then((obj) => {
// if project already created, open
// else, create a new one
if (true == obj[0].innerHTML.includes(proj.basic.name)) {
projectsPage.openProject(proj.basic.name);
// if project already created, open
// else, create a new one
if (true == obj[0].innerHTML.includes(proj.basic.name)) {
projectsPage.openProject(proj.basic.name);
let projId;
if (dbType === "xcdb") {
let query = `SELECT prefix from nc_projects_v2 where title = "sampleREST"; `;
cy.task("sqliteExecReturnValue", query).then(
(resolve) => {
cy.log(resolve);
projId = resolve.prefix;
setProjectString(projId);
cy.log(projId);
}
);
}
} else {
projectsPage.createProject(proj.basic, proj.config);
cy.wait(5000);
if (dbType === "xcdb") {
// store base URL- to re-visit and delete form view later
let projId;
if (dbType === "xcdb") {
let query = `SELECT prefix from nc_projects_v2 where title = "sampleREST"; `;
cy.task("sqliteExecReturnValue", query).then(
(resolve) => {
cy.log(resolve);
projId = resolve.prefix;
setProjectString(projId);
cy.log(projId);
}
);
}
} else {
projectsPage.createProject(proj.basic, proj.config);
cy.wait(5000);
if (dbType === "xcdb") {
// store base URL- to re-visit and delete form view later
let projId;
cy.url()
.then((url) => {
// project prefix code can include "_"
// projId = url.split("_")[1].split("?")[0];
let startIdx = url.indexOf("_");
let endIdx = url.indexOf("?");
projId = url.slice(startIdx + 1, endIdx);
cy.url()
.then((url) => {
// project prefix code can include "_"
// projId = url.split("_")[1].split("?")[0];
let startIdx = url.indexOf("_");
let endIdx = url.indexOf("?");
projId = url.slice(startIdx + 1, endIdx);
let query = `SELECT prefix from nc_projects_v2 where title = "sampleREST"; `;
cy.task("sqliteExecReturnValue", query)
.then((resolve) => {
cy.log(resolve);
projId = resolve.prefix;
cy.log(projId);
setProjectString(projId);
})
.then(() => {
let query =
prepareSqliteQuery(projId);
for (
let i = 0;
i < query.length;
i++
) {
cy.task("sqliteExec", query[i]);
cy.wait(1000);
}
});
})
.then(() => {
cy.log(projId);
mainPage.openMetaTab();
mainPage.metaSyncValidate(
`${projId}actor`,
`New table, New relation added`
);
mainPage.closeMetaTab();
});
}
let query = `SELECT prefix from nc_projects_v2 where title = "sampleREST"; `;
cy.task("sqliteExecReturnValue", query)
.then((resolve) => {
cy.log(resolve);
projId = resolve.prefix;
cy.log(projId);
setProjectString(projId);
})
.then(() => {
let query =
prepareSqliteQuery(projId);
for (
let i = 0;
i < query.length;
i++
) {
cy.task("sqliteExec", query[i]);
cy.wait(1000);
}
});
})
.then(() => {
cy.log(projId);
mainPage.openMetaTab();
mainPage.metaSyncValidate(
`${projId}actor`,
`New table, New relation added`
);
mainPage.closeMetaTab();
});
}
});
// 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