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,
dbType: req.body.dbType,
isEmptyProject: req.body.isEmptyProject,
workerId: req.body.workerId
});
res.json(await service.process());

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

@ -23,11 +23,13 @@ const loginRootUser = async () => {
const projectTitleByType = {
sqlite: 'sampleREST',
mysql: 'externalREST',
pg: 'pgExtREST',
pg: 'pgExtREST'
};
export class TestResetService {
private readonly parallelId;
// todo: Hack to resolve issue with pg resetting
private readonly workerId;
private readonly dbType;
private readonly isEmptyProject: boolean;
@ -35,14 +37,17 @@ export class TestResetService {
parallelId,
dbType,
isEmptyProject,
workerId
}: {
parallelId: string;
dbType: string;
isEmptyProject: boolean;
workerId: string;
}) {
this.parallelId = parallelId;
this.dbType = dbType;
this.isEmptyProject = isEmptyProject;
this.workerId = workerId;
}
async process() {
@ -68,6 +73,7 @@ export class TestResetService {
token,
dbType: this.dbType,
parallelId: this.parallelId,
workerId: this.workerId
});
try {
@ -90,10 +96,12 @@ export class TestResetService {
token,
dbType,
parallelId,
workerId
}: {
token: string;
dbType: string;
parallelId: string;
workerId: string;
}) {
const title = `${projectTitleByType[dbType]}${parallelId}`;
const project: Project | undefined = await Project.getByTitle(title);
@ -115,7 +123,7 @@ export class TestResetService {
token,
title,
parallelId,
isEmptyProject: this.isEmptyProject,
isEmptyProject: this.isEmptyProject
});
} else if (dbType == 'mysql') {
await resetMysqlSakilaProject({
@ -123,20 +131,20 @@ export class TestResetService {
title,
parallelId,
oldProject: project,
isEmptyProject: this.isEmptyProject,
isEmptyProject: this.isEmptyProject
});
} else if (dbType == 'pg') {
await resetPgSakilaProject({
token,
title,
parallelId,
parallelId: workerId,
oldProject: project,
isEmptyProject: this.isEmptyProject,
isEmptyProject: this.isEmptyProject
});
}
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({
project_id: project.id,
limit: 1000,
offset: 0,
offset: 0
});
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 pg_credentials = () => ({
const pg_credentials = (context: NcContext) => ({
user: 'postgres',
host: 'localhost',
database: `sakila_${process.env.TEST_PARALLEL_INDEX}`,
// todo: Hack to resolve issue with pg resetting
database: `sakila_${context.workerId}`,
password: 'password',
port: 5432,
});
const pgExec = async (query: string) => {
const pgExec = async (query: string, context: NcContext) => {
// open pg client connection
const client = new Client(pg_credentials());
const client = new Client(pg_credentials(context));
await client.connect();
await client.query(query);

18
tests/playwright/setup/index.ts

@ -1,10 +1,14 @@
import { Page, selectors } from '@playwright/test';
import axios from 'axios';
const workerCount = {};
export interface NcContext {
project: any;
token: string;
dbType?: string;
// todo: Hack to resolve issue with pg resetting
workerId?: string;
}
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;
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}`);
let response;
try {
response = await axios.post(`http://localhost:8080/api/v1/meta/test/reset`, {
parallelId: process.env.TEST_PARALLEL_INDEX,
workerId: workerId,
dbType,
isEmptyProject,
});
@ -59,7 +75,7 @@ const setup = async ({ page, isEmptyProject }: { page: Page; isEmptyProject?: bo
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;

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

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

Loading…
Cancel
Save