Browse Source

fix(test): Temporary fix for pg sakila resetting issue

pull/4406/head
Muhammed Mustafa 2 years ago committed by Pranav C
parent
commit
3f3f9e55f3
  1. 1
      packages/nocodb/src/lib/meta/api/testApis.ts
  2. 22
      packages/nocodb/src/lib/services/test/TestResetService/index.ts
  3. 9
      tests/playwright/setup/db.ts
  4. 18
      tests/playwright/setup/index.ts
  5. 2
      tests/playwright/tests/metaSync.spec.ts

1
packages/nocodb/src/lib/meta/api/testApis.ts

@ -6,6 +6,7 @@ export async function reset(req: Request<any, any>, res) {
parallelId: req.body.parallelId, parallelId: req.body.parallelId,
dbType: req.body.dbType, dbType: req.body.dbType,
isEmptyProject: req.body.isEmptyProject, isEmptyProject: req.body.isEmptyProject,
workerId: req.body.workerId
}); });
res.json(await service.process()); res.json(await service.process());

22
packages/nocodb/src/lib/services/test/TestResetService/index.ts

@ -23,11 +23,13 @@ const loginRootUser = async () => {
const projectTitleByType = { const projectTitleByType = {
sqlite: 'sampleREST', sqlite: 'sampleREST',
mysql: 'externalREST', mysql: 'externalREST',
pg: 'pgExtREST', pg: 'pgExtREST'
}; };
export class TestResetService { export class TestResetService {
private readonly parallelId; private readonly parallelId;
// todo: Hack to resolve issue with pg resetting
private readonly workerId;
private readonly dbType; private readonly dbType;
private readonly isEmptyProject: boolean; private readonly isEmptyProject: boolean;
@ -35,14 +37,17 @@ export class TestResetService {
parallelId, parallelId,
dbType, dbType,
isEmptyProject, isEmptyProject,
workerId
}: { }: {
parallelId: string; parallelId: string;
dbType: string; dbType: string;
isEmptyProject: boolean; isEmptyProject: boolean;
workerId: string;
}) { }) {
this.parallelId = parallelId; this.parallelId = parallelId;
this.dbType = dbType; this.dbType = dbType;
this.isEmptyProject = isEmptyProject; this.isEmptyProject = isEmptyProject;
this.workerId = workerId;
} }
async process() { async process() {
@ -68,6 +73,7 @@ export class TestResetService {
token, token,
dbType: this.dbType, dbType: this.dbType,
parallelId: this.parallelId, parallelId: this.parallelId,
workerId: this.workerId
}); });
try { try {
@ -90,10 +96,12 @@ export class TestResetService {
token, token,
dbType, dbType,
parallelId, parallelId,
workerId
}: { }: {
token: string; token: string;
dbType: string; dbType: string;
parallelId: string; parallelId: string;
workerId: string;
}) { }) {
const title = `${projectTitleByType[dbType]}${parallelId}`; const title = `${projectTitleByType[dbType]}${parallelId}`;
const project: Project | undefined = await Project.getByTitle(title); const project: Project | undefined = await Project.getByTitle(title);
@ -115,7 +123,7 @@ export class TestResetService {
token, token,
title, title,
parallelId, parallelId,
isEmptyProject: this.isEmptyProject, isEmptyProject: this.isEmptyProject
}); });
} else if (dbType == 'mysql') { } else if (dbType == 'mysql') {
await resetMysqlSakilaProject({ await resetMysqlSakilaProject({
@ -123,20 +131,20 @@ export class TestResetService {
title, title,
parallelId, parallelId,
oldProject: project, oldProject: project,
isEmptyProject: this.isEmptyProject, isEmptyProject: this.isEmptyProject
}); });
} else if (dbType == 'pg') { } else if (dbType == 'pg') {
await resetPgSakilaProject({ await resetPgSakilaProject({
token, token,
title, title,
parallelId, parallelId: workerId,
oldProject: project, oldProject: project,
isEmptyProject: this.isEmptyProject, isEmptyProject: this.isEmptyProject
}); });
} }
return { return {
project: await Project.getByTitle(title), project: await Project.getByTitle(title)
}; };
} }
} }
@ -169,7 +177,7 @@ const removeProjectUsersFromCache = async (project: Project) => {
const projectUsers: ProjectUser[] = await ProjectUser.getUsersList({ const projectUsers: ProjectUser[] = await ProjectUser.getUsersList({
project_id: project.id, project_id: project.id,
limit: 1000, limit: 1000,
offset: 0, offset: 0
}); });
for (const projectUser of projectUsers) { for (const projectUser of projectUsers) {

9
tests/playwright/setup/db.ts

@ -11,17 +11,18 @@ const isSqlite = (context: NcContext) => context.dbType === 'sqlite';
const isPg = (context: NcContext) => context.dbType === 'pg'; const isPg = (context: NcContext) => context.dbType === 'pg';
const pg_credentials = () => ({ const pg_credentials = (context: NcContext) => ({
user: 'postgres', user: 'postgres',
host: 'localhost', host: 'localhost',
database: `sakila_${process.env.TEST_PARALLEL_INDEX}`, // todo: Hack to resolve issue with pg resetting
database: `sakila_${context.workerId}`,
password: 'password', password: 'password',
port: 5432, port: 5432,
}); });
const pgExec = async (query: string) => { const pgExec = async (query: string, context: NcContext) => {
// open pg client connection // open pg client connection
const client = new Client(pg_credentials()); const client = new Client(pg_credentials(context));
await client.connect(); await client.connect();
await client.query(query); await client.query(query);

18
tests/playwright/setup/index.ts

@ -1,10 +1,14 @@
import { Page, selectors } from '@playwright/test'; import { Page, selectors } from '@playwright/test';
import axios from 'axios'; import axios from 'axios';
const workerCount = {};
export interface NcContext { export interface NcContext {
project: any; project: any;
token: string; token: string;
dbType?: string; dbType?: string;
// todo: Hack to resolve issue with pg resetting
workerId?: string;
} }
selectors.setTestIdAttribute('data-testid'); selectors.setTestIdAttribute('data-testid');
@ -13,11 +17,23 @@ const setup = async ({ page, isEmptyProject }: { page: Page; isEmptyProject?: bo
let dbType = process.env.CI ? process.env.E2E_DB_TYPE : process.env.E2E_DEV_DB_TYPE; let dbType = process.env.CI ? process.env.E2E_DB_TYPE : process.env.E2E_DEV_DB_TYPE;
dbType = dbType || 'sqlite'; dbType = dbType || 'sqlite';
let workerId;
// todo: Hack to resolve issue with pg resetting
if (dbType === 'pg') {
const workerIndex = process.env.TEST_PARALLEL_INDEX;
if (!workerCount[workerIndex]) {
workerCount[workerIndex] = 0;
}
workerCount[workerIndex]++;
workerId = String(Number(workerIndex) + Number(workerCount[workerIndex]) * 4);
}
// if (!process.env.CI) console.time(`setup ${process.env.TEST_PARALLEL_INDEX}`); // if (!process.env.CI) console.time(`setup ${process.env.TEST_PARALLEL_INDEX}`);
let response; let response;
try { try {
response = await axios.post(`http://localhost:8080/api/v1/meta/test/reset`, { response = await axios.post(`http://localhost:8080/api/v1/meta/test/reset`, {
parallelId: process.env.TEST_PARALLEL_INDEX, parallelId: process.env.TEST_PARALLEL_INDEX,
workerId: workerId,
dbType, dbType,
isEmptyProject, isEmptyProject,
}); });
@ -59,7 +75,7 @@ const setup = async ({ page, isEmptyProject }: { page: Page; isEmptyProject?: bo
await page.goto(`/#/nc/${project.id}/auth`, { waitUntil: 'networkidle' }); await page.goto(`/#/nc/${project.id}/auth`, { waitUntil: 'networkidle' });
return { project, token, dbType } as NcContext; return { project, token, dbType, workerId } as NcContext;
}; };
export default setup; export default setup;

2
tests/playwright/tests/metaSync.spec.ts

@ -24,7 +24,7 @@ test.describe('Meta sync', () => {
dbExec = mysqlExec; dbExec = mysqlExec;
break; break;
case 'pg': case 'pg':
dbExec = pgExec; dbExec = query => pgExec(query, context);
break; break;
} }
}); });

Loading…
Cancel
Save