Skip to content

Commit

Permalink
remove unnecessary testing, fix columns, feedback
Browse files Browse the repository at this point in the history
Signed-off-by: lpete@vmware.com <lpete@vmware.com>

fix issues with merge

Signed-off-by: lpete@vmware.com <lpete@vmware.com>
  • Loading branch information
PeteLevineA committed Aug 15, 2023
1 parent aae7fad commit 7e14aef
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 95 deletions.
25 changes: 0 additions & 25 deletions .github/workflows/test-db.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/verify_e2e-linux-mysql.yml
Expand Up @@ -60,7 +60,7 @@ jobs:
- run: yarn backstage-cli repo build
- name: run E2E test
run: |
yarn e2e-test run
yarn e2e-test run --dbms=mysql
env:
BACKSTAGE_TEST_DISABLE_DOCKER: 1
BACKSTAGE_TEST_DATABASE_MYSQL8_CONNECTION_STRING: mysql://root:root@localhost:${{ job.services.mysql8.ports[3306] }}/ignored

This file was deleted.

2 changes: 1 addition & 1 deletion packages/e2e-test/package.json
Expand Up @@ -35,8 +35,8 @@
"cross-fetch": "^3.1.5",
"fs-extra": "10.1.0",
"handlebars": "^4.7.3",
"pgtools": "^1.0.0",
"mysql2": "^2.2.5",
"pgtools": "^1.0.0",
"puppeteer": "^17.0.0",
"tree-kill": "^1.2.2"
},
Expand Down
9 changes: 8 additions & 1 deletion packages/e2e-test/src/commands/index.ts
Expand Up @@ -18,5 +18,12 @@ import { Command } from 'commander';
import { run } from './run';

export function registerCommands(program: Command) {
program.command('run').description('Run e2e tests').action(run);
program
.command('run')
.description('Run e2e tests')
.option(
'-db, --dbms',
'Selected database management system for e2e testing, (eg. mysql, postgres)',
)
.action(run);
}
41 changes: 15 additions & 26 deletions packages/e2e-test/src/commands/run.ts
Expand Up @@ -46,7 +46,7 @@ const templatePackagePaths = [
'packages/create-app/templates/default-app/packages/backend/package.json.hbs',
];

export async function run() {
export async function run(dbms: string = 'postgres') {
const rootDir = await fs.mkdtemp(resolvePath(os.tmpdir(), 'backstage-e2e-'));
print(`CLI E2E test root: ${rootDir}\n`);

Expand All @@ -69,17 +69,15 @@ export async function run() {
print('Starting the app');
await testAppServe(pluginId, appDir);

if (Boolean(process.env.POSTGRES_USER) || Boolean(process.env.MYSQL_USER)) {
if (
Boolean(process.env.POSTGRES_USER) ||
Boolean(process.env.BACKSTAGE_TEST_DATABASE_MYSQL8_CONNECTION_STRING)
) {
print('Testing the datbase backend startup');
await preCleanDatabase();
await dropClientDatabases(dbms);
const appConfig = path.resolve(appDir, 'app-config.yaml');
let productionConfig = path.resolve(appDir, 'app-config.production.yaml');
if (Boolean(process.env.MYSQL_HOST)) {
productionConfig = path.resolve(
appDir,
'app-config.production.mysql.yaml',
);
}
const productionConfig = path.resolve(appDir, 'app-config.production.yaml');

await testBackendStart(
appDir,
'--config',
Expand Down Expand Up @@ -435,10 +433,10 @@ async function testAppServe(pluginId: string, appDir: string) {
}
}

/** Drops PG databases */
async function dropDB(database: string, client: string) {
/** Drops databases */
async function dropDB(database: string, dbms: string) {
try {
if (client === 'postgres') {
if (dbms === 'postgres') {
const config = {
host: process.env.POSTGRES_HOST ? process.env.POSTGRES_HOST : '',
port: process.env.POSTGRES_PORT ? process.env.POSTGRES_PORT : '',
Expand All @@ -448,7 +446,7 @@ async function dropDB(database: string, client: string) {
: '',
};
await pgtools.dropdb(config, database);
} else if (client === 'mysql') {
} else if (dbms === 'mysql') {
const connectionString =
process.env.BACKSTAGE_TEST_DATABASE_MYSQL8_CONNECTION_STRING ?? '';
const connection = await mysql.createConnection(connectionString);
Expand All @@ -460,18 +458,8 @@ async function dropDB(database: string, client: string) {
}

/** Clean remnants from prior e2e runs */
async function preCleanDatabase() {
async function dropClientDatabases(dbms: string) {
print('Dropping old DBs');
if (Boolean(process.env.POSTGRES_HOST)) {
await dropClientDatabases('postgres');
}
if (Boolean(process.env.BACKSTAGE_TEST_DATABASE_MYSQL8_CONNECTION_STRING)) {
await dropClientDatabases('mysql');
}
print('Created DBs');
}

async function dropClientDatabases(client: string) {
await Promise.all(
[
'catalog',
Expand All @@ -481,8 +469,9 @@ async function dropClientDatabases(client: string) {
'proxy',
'techdocs',
'search',
].map(name => dropDB(`backstage_plugin_${name}`, client)),
].map(name => dropDB(`backstage_plugin_${name}`, dbms)),
);
print('Created DBs');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion plugins/app-backend/migrations/20211229105307_init.js
Expand Up @@ -25,7 +25,7 @@ exports.up = async function up(knex) {
'A cache of static assets that where previously deployed and may still be lazy-loaded by clients',
);
table
.string('path')
.text('path', 'longtext')
.primary()
.notNullable()
.comment('The path of the file');
Expand Down
20 changes: 10 additions & 10 deletions plugins/app-backend/src/lib/assets/StaticAssetsStore.ts
Expand Up @@ -138,20 +138,20 @@ export class StaticAssetsStore implements StaticAssetProvider {
*/
async trimAssets(options: { maxAgeSeconds: number }) {
const { maxAgeSeconds } = options;
let lastModifiedInterval = `now() + interval '${-maxAgeSeconds} seconds'`;
let lastModifiedInterval = this.#db.raw(
`now() + interval '${-maxAgeSeconds} seconds'`,
);
if (this.#db.client.config.client.includes('mysql')) {
lastModifiedInterval = `date_sub(now(), interval ${maxAgeSeconds} second)`;
lastModifiedInterval = this.#db.raw(
`date_sub(now(), interval ${maxAgeSeconds} second)`,
);
} else if (this.#db.client.config.client.includes('sqlite3')) {
lastModifiedInterval = `datetime('now', ?)`;
lastModifiedInterval = this.#db.raw(`datetime('now', ?)`, [
`-${maxAgeSeconds} seconds`,
]);
}
await this.#db<StaticAssetRow>('static_assets_cache')
.where(
'last_modified_at',
'<=',
this.#db.client.config.client.includes('sqlite3')
? this.#db.raw(lastModifiedInterval, [`-${maxAgeSeconds} seconds`])
: this.#db.raw(lastModifiedInterval),
)
.where('last_modified_at', '<=', lastModifiedInterval)
.delete();
}
}
2 changes: 1 addition & 1 deletion yarn.lock
Expand Up @@ -23664,9 +23664,9 @@ __metadata:
cross-fetch: ^3.1.5
fs-extra: 10.1.0
handlebars: ^4.7.3
mysql2: ^2.2.5
nodemon: ^3.0.1
pgtools: ^1.0.0
mysql2: ^2.2.5
puppeteer: ^17.0.0
tree-kill: ^1.2.2
ts-node: ^10.0.0
Expand Down

0 comments on commit 7e14aef

Please sign in to comment.