1
0
mirror of https://github.com/bpatrik/pigallery2.git synced 2025-01-12 04:23:09 +02:00

fixing test issues

This commit is contained in:
Patrik J. Braun 2019-12-29 09:34:08 +01:00
parent ddb734e64a
commit 95a50b4936
7 changed files with 44 additions and 61 deletions

1
.gitignore vendored
View File

@ -26,3 +26,4 @@ out-tsc/
ffmpeg/
locale.source.xlf
test.*
/db/

View File

@ -4,14 +4,16 @@ import {ObjectManagers} from '../src/backend/model/ObjectManagers';
import {DiskMangerWorker} from '../src/backend/model/threading/DiskMangerWorker';
import {IndexingManager} from '../src/backend/model/database/sql/IndexingManager';
import {SearchManager} from '../src/backend/model/database/sql/SearchManager';
import * as fs from 'fs';
import * as path from 'path';
import * as util from 'util';
import * as rimraf from 'rimraf';
import {SearchTypes} from '../src/common/entities/AutoCompleteItem';
import {Utils} from '../src/common/Utils';
import {GalleryManager} from '../src/backend/model/database/sql/GalleryManager';
import {DirectoryDTO} from '../src/common/entities/DirectoryDTO';
import {ServerConfig} from '../src/common/config/private/IPrivateConfig';
const rimrafPR = util.promisify(rimraf);
export interface BenchmarkResult {
duration: number;
directories?: number;
@ -28,7 +30,7 @@ export class BMIndexingManager extends IndexingManager {
export class Benchmarks {
constructor(public RUNS: number, public dbPath: string) {
constructor(public RUNS: number, public dbFolder: string) {
}
@ -120,11 +122,9 @@ export class Benchmarks {
private resetDB = async () => {
await SQLConnection.close();
if (fs.existsSync(this.dbPath)) {
fs.unlinkSync(this.dbPath);
}
await rimrafPR(this.dbFolder);
Config.Server.Database.type = ServerConfig.DatabaseType.sqlite;
Config.Server.Database.dbFolder = path.dirname(this.dbPath);
Config.Server.Database.dbFolder = this.dbFolder;
await ObjectManagers.InitSQLManagers();
};

View File

@ -8,7 +8,7 @@ import {DiskMangerWorker} from '../src/backend/model/threading/DiskMangerWorker'
const config: { path: string, system: string } = require(path.join(__dirname, 'config.json'));
Config.Server.Media.folder = config.path;
const dbPath = path.join(__dirname, 'test.db');
const dbFolder = __dirname;
ProjectPath.reset();
const RUNS = 50;
@ -52,7 +52,7 @@ const printResult = (result: BenchmarkResult, action: string, actionDetails: str
const run = async () => {
const start = Date.now();
const bm = new Benchmarks(RUNS, dbPath);
const bm = new Benchmarks(RUNS, dbFolder);
// header
await printHeader();

View File

@ -7,28 +7,24 @@ import {PrivateConfigDefaultsClass} from './PrivateConfigDefaultsClass';
declare var process: NodeJS.Process;
let CONFIG_PATH = path.join(__dirname, './../../../../config.json');
// TODO: refactor this
let configPath = process.argv.find(s => s.startsWith('--config-path='));
if (configPath) {
configPath = configPath.replace('--config-path=', '');
if (path.isAbsolute(configPath)) {
CONFIG_PATH = configPath;
} else {
CONFIG_PATH = path.join(__dirname, './../../../../', configPath);
}
console.log('using config path:' + CONFIG_PATH);
}
/**
* This configuration will be only at backend
*/
export class ConfigClass extends PrivateConfigDefaultsClass implements IPrivateConfig {
private static CONFIG_PATH = path.join(__dirname, './../../../../config.json');
constructor() {
super();
// TODO: refactor this
let configPath = process.argv.find(s => s.startsWith('--config-path='));
if (configPath) {
configPath = configPath.replace('--config-path=', '');
if (path.isAbsolute(configPath)) {
ConfigClass.CONFIG_PATH = configPath;
} else {
ConfigClass.CONFIG_PATH = path.join(__dirname, './../../../../', configPath);
}
console.log('using config path:' + ConfigClass.CONFIG_PATH);
}
}
public setDatabaseType(type: ServerConfig.DatabaseType) {
this.Server.Database.type = type;
@ -40,7 +36,7 @@ export class ConfigClass extends PrivateConfigDefaultsClass implements IPrivateC
public load() {
this.addComment();
ConfigLoader.loadBackendConfig(this, ConfigClass.CONFIG_PATH,
ConfigLoader.loadBackendConfig(this, CONFIG_PATH,
[['PORT', 'Server-port'],
['MYSQL_HOST', 'Server-Database-mysql-host'],
['MYSQL_PASSWORD', 'Server-Database-mysql-password'],
@ -69,7 +65,7 @@ export class ConfigClass extends PrivateConfigDefaultsClass implements IPrivateC
public save() {
try {
this.addComment();
ConfigLoader.saveConfigFile(ConfigClass.CONFIG_PATH, this);
ConfigLoader.saveConfigFile(CONFIG_PATH, this);
this.removeComment();
} catch (e) {
throw new Error('Error during saving config: ' + e.toString());

View File

@ -87,7 +87,7 @@ export class PrivateConfigDefaultsClass extends PublicConfigClass implements IPr
afterScheduleName: DefaultsJobs[DefaultsJobs.Indexing]
}
},
{
/* {
name: DefaultsJobs[DefaultsJobs['Photo Converting']],
jobName: DefaultsJobs[DefaultsJobs['Photo Converting']],
config: {},
@ -95,14 +95,14 @@ export class PrivateConfigDefaultsClass extends PublicConfigClass implements IPr
type: JobTriggerType.after,
afterScheduleName: DefaultsJobs[DefaultsJobs['Thumbnail Generation']]
}
},
},*/
{
name: DefaultsJobs[DefaultsJobs['Video Converting']],
jobName: DefaultsJobs[DefaultsJobs['Video Converting']],
config: {},
trigger: {
type: JobTriggerType.after,
afterScheduleName: DefaultsJobs[DefaultsJobs['Photo Converting']]
afterScheduleName: DefaultsJobs[DefaultsJobs['Thumbnail Generation']]
}
},
{

View File

@ -1,11 +1,13 @@
import {Config} from '../../src/common/config/private/Config';
import * as fs from 'fs';
import * as path from 'path';
import * as util from 'util';
import * as rimraf from 'rimraf';
import {SQLConnection} from '../../src/backend/model/database/sql/SQLConnection';
import {ServerConfig} from '../../src/common/config/private/IPrivateConfig';
declare let describe: any;
const savedDescribe = describe;
const rimrafPR = util.promisify(rimraf);
export class SQLTestHelper {
@ -15,12 +17,9 @@ export class SQLTestHelper {
};
public static readonly savedDescribe = savedDescribe;
tempDir: string;
dbPath: string;
constructor(public dbType: ServerConfig.DatabaseType) {
this.tempDir = path.join(__dirname, './tmp');
this.dbPath = path.join(__dirname, './tmp', 'test.db');
}
static describe(name: string, tests: (helper?: SQLTestHelper) => void) {
@ -63,7 +62,7 @@ export class SQLTestHelper {
await this.resetSQLite();
Config.Server.Database.type = ServerConfig.DatabaseType.sqlite;
Config.Server.Database.dbFolder = path.dirname(this.dbPath);
Config.Server.Database.dbFolder = this.tempDir;
}
private async initMySQL() {
@ -75,13 +74,7 @@ export class SQLTestHelper {
private async resetSQLite() {
await SQLConnection.close();
if (fs.existsSync(this.dbPath)) {
fs.unlinkSync(this.dbPath);
}
if (fs.existsSync(this.tempDir)) {
fs.rmdirSync(this.tempDir);
}
await rimrafPR(this.tempDir);
}
private async resetMySQL() {

View File

@ -1,6 +1,7 @@
import {expect} from 'chai';
import * as fs from 'fs';
import * as path from 'path';
import * as util from 'util';
import * as rimraf from 'rimraf';
import {Config} from '../../../../../src/common/config/private/Config';
import {SQLConnection} from '../../../../../src/backend/model/database/sql/SQLConnection';
import {UserEntity} from '../../../../../src/backend/model/database/sql/enitites/UserEntity';
@ -18,36 +19,28 @@ import {MediaDimensionEntity} from '../../../../../src/backend/model/database/sq
import {VersionEntity} from '../../../../../src/backend/model/database/sql/enitites/VersionEntity';
import {ServerConfig} from '../../../../../src/common/config/private/IPrivateConfig';
const rimrafPR = util.promisify(rimraf);
describe('Typeorm integration', () => {
const tempDir = path.join(__dirname, '../../tmp');
const dbPath = path.join(tempDir, 'test.db');
const setUpSqlDB = () => {
if (fs.existsSync(dbPath)) {
fs.unlinkSync(dbPath);
}
if (!fs.existsSync(tempDir)) {
fs.mkdirSync(tempDir);
}
const setUpSqlDB = async () => {
await rimrafPR(tempDir);
Config.Server.Database.type = ServerConfig.DatabaseType.sqlite;
Config.Server.Database.dbFolder = path.dirname(dbPath);
Config.Server.Database.dbFolder = tempDir;
};
const teardownUpSqlDB = async () => {
await SQLConnection.close();
if (fs.existsSync(dbPath)) {
fs.unlinkSync(dbPath);
}
if (fs.existsSync(tempDir)) {
fs.rmdirSync(tempDir);
}
await rimrafPR(tempDir);
};
beforeEach(() => {
setUpSqlDB();
beforeEach(async () => {
await setUpSqlDB();
});
afterEach(async () => {