Browse Source

test: revert to older reset mechanism

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>
pull/6544/head
Raju Udava 1 year ago
parent
commit
f4e92dfadc
  1. 85
      tests/playwright/setup/index.ts

85
tests/playwright/setup/index.ts

@ -8,6 +8,9 @@ import { isEE } from './db';
import { resetSakilaPg } from './knexHelper';
import path from 'path';
// Use local reset logic instead of remote
const enableLocalInit = true;
// MySQL Configuration
const mysqlConfig = {
client: 'mysql2',
@ -153,8 +156,6 @@ export interface NcContext {
workerId?: string;
rootUser: UserType & { password: string };
workspace: WorkspaceType;
defaultProjectTitle: string;
defaultTableTitle: string;
}
selectors.setTestIdAttribute('data-testid');
@ -216,18 +217,8 @@ async function localInit({
const ws = await api['workspace'].list();
for (const w of ws.list) {
// check if w.title starts with workspaceTitle
if (w.title.startsWith(`ws_pgExtREST${process.env.TEST_PARALLEL_INDEX}`)) {
if (w.title.startsWith(`ws_pgExtREST_p${process.env.TEST_PARALLEL_INDEX}`)) {
try {
const projects = await api.workspaceProject.list(w.id);
for (const project of projects.list) {
try {
await api.project.delete(project.id);
} catch (e) {
console.log(`Error deleting project: ws delete`, project);
}
}
await api['workspace'].delete(w.id);
} catch (e) {
console.log(`Error deleting workspace: ${w.id}`, `user-${parallelId}@nocodb.com`, isSuperUser);
@ -246,7 +237,7 @@ async function localInit({
for (const p of projects.list) {
// check if p.title starts with projectTitle
if (
p.title.startsWith(`pgExtREST${process.env.TEST_PARALLEL_INDEX}`) ||
p.title.startsWith(`pgExtREST_p${process.env.TEST_PARALLEL_INDEX}`) ||
p.title.startsWith(`xcdb_p${process.env.TEST_PARALLEL_INDEX}`)
) {
try {
@ -358,25 +349,38 @@ const setup = async ({
const workerIndex = process.env.TEST_WORKER_INDEX;
const parallelIndex = process.env.TEST_PARALLEL_INDEX;
const workerId = parallelIndex;
const workerId = `_p${parallelIndex}_w${workerIndex}_c${(+workerIndex + 1) * 1000 + workerCount[parallelIndex]}`;
workerCount[+parallelIndex]++;
// console.log(process.env.TEST_PARALLEL_INDEX, '#Setup', workerId);
try {
// Localised reset logic
response = await localInit({
workerId: parallelIndex,
isEmptyProject,
projectType,
isSuperUser,
dbType,
});
if (enableLocalInit) {
response = await localInit({
workerId,
isEmptyProject,
projectType,
isSuperUser,
dbType,
});
}
// Remote reset logic
else {
response = await axios.post(`http://localhost:8080/api/v1/meta/test/reset`, {
parallelId: process.env.TEST_PARALLEL_INDEX,
workerId: workerId,
dbType,
projectType,
isEmptyProject,
});
}
} catch (e) {
console.error(`Error resetting project: ${process.env.TEST_PARALLEL_INDEX}`, e);
}
if (response.status !== 200 || !response.data?.token || !response.data?.project) {
console.error('Failed to reset test data', response.data, response.status, dbType);
console.error('Failed to reset test data', response.data, response.status, enableLocalInit, dbType);
throw new Error('Failed to reset test data');
}
const token = response.data.token;
@ -386,12 +390,7 @@ const setup = async ({
email: `user@nocodb.com`,
password: getDefaultPwd(),
});
if (!isEE())
await axios.post(
`http://localhost:8080/api/v1/license`,
{ key: '' },
{ headers: { 'xc-auth': admin.data.token } }
);
await axios.post(`http://localhost:8080/api/v1/license`, { key: '' }, { headers: { 'xc-auth': admin.data.token } });
} catch (e) {
// ignore error: some roles will not have permission for license reset
// console.error(`Error resetting project: ${process.env.TEST_PARALLEL_INDEX}`, e);
@ -443,19 +442,25 @@ const setup = async ({
}
await page.goto(projectUrl, { waitUntil: 'networkidle' });
return {
project,
token,
dbType,
workerId,
rootUser,
workspace,
defaultProjectTitle: 'Getting Started',
defaultTableTitle: 'Features',
} as NcContext;
return { project, token, dbType, workerId, rootUser, workspace } as NcContext;
};
export const unsetup = async (context: NcContext): Promise<void> => {};
export const unsetup = async (context: NcContext): Promise<void> => {
if (context.token && context.project) {
// try to delete the project
try {
// Init SDK using token
const api = new Api({
baseURL: `http://localhost:8080/`,
headers: {
'xc-auth': context.token,
},
});
await api.project.delete(context.project.id);
} catch (e) {}
}
};
// Reference
// packages/nocodb/src/lib/services/test/TestResetService/resetPgSakilaProject.ts

Loading…
Cancel
Save