fixing test issues
This commit is contained in:
parent
ddb734e64a
commit
95a50b4936
1
.gitignore
vendored
1
.gitignore
vendored
@ -26,3 +26,4 @@ out-tsc/
|
|||||||
ffmpeg/
|
ffmpeg/
|
||||||
locale.source.xlf
|
locale.source.xlf
|
||||||
test.*
|
test.*
|
||||||
|
/db/
|
||||||
|
|||||||
@ -4,14 +4,16 @@ import {ObjectManagers} from '../src/backend/model/ObjectManagers';
|
|||||||
import {DiskMangerWorker} from '../src/backend/model/threading/DiskMangerWorker';
|
import {DiskMangerWorker} from '../src/backend/model/threading/DiskMangerWorker';
|
||||||
import {IndexingManager} from '../src/backend/model/database/sql/IndexingManager';
|
import {IndexingManager} from '../src/backend/model/database/sql/IndexingManager';
|
||||||
import {SearchManager} from '../src/backend/model/database/sql/SearchManager';
|
import {SearchManager} from '../src/backend/model/database/sql/SearchManager';
|
||||||
import * as fs from 'fs';
|
import * as util from 'util';
|
||||||
import * as path from 'path';
|
import * as rimraf from 'rimraf';
|
||||||
import {SearchTypes} from '../src/common/entities/AutoCompleteItem';
|
import {SearchTypes} from '../src/common/entities/AutoCompleteItem';
|
||||||
import {Utils} from '../src/common/Utils';
|
import {Utils} from '../src/common/Utils';
|
||||||
import {GalleryManager} from '../src/backend/model/database/sql/GalleryManager';
|
import {GalleryManager} from '../src/backend/model/database/sql/GalleryManager';
|
||||||
import {DirectoryDTO} from '../src/common/entities/DirectoryDTO';
|
import {DirectoryDTO} from '../src/common/entities/DirectoryDTO';
|
||||||
import {ServerConfig} from '../src/common/config/private/IPrivateConfig';
|
import {ServerConfig} from '../src/common/config/private/IPrivateConfig';
|
||||||
|
|
||||||
|
const rimrafPR = util.promisify(rimraf);
|
||||||
|
|
||||||
export interface BenchmarkResult {
|
export interface BenchmarkResult {
|
||||||
duration: number;
|
duration: number;
|
||||||
directories?: number;
|
directories?: number;
|
||||||
@ -28,7 +30,7 @@ export class BMIndexingManager extends IndexingManager {
|
|||||||
|
|
||||||
export class Benchmarks {
|
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 () => {
|
private resetDB = async () => {
|
||||||
await SQLConnection.close();
|
await SQLConnection.close();
|
||||||
if (fs.existsSync(this.dbPath)) {
|
await rimrafPR(this.dbFolder);
|
||||||
fs.unlinkSync(this.dbPath);
|
|
||||||
}
|
|
||||||
Config.Server.Database.type = ServerConfig.DatabaseType.sqlite;
|
Config.Server.Database.type = ServerConfig.DatabaseType.sqlite;
|
||||||
Config.Server.Database.dbFolder = path.dirname(this.dbPath);
|
Config.Server.Database.dbFolder = this.dbFolder;
|
||||||
await ObjectManagers.InitSQLManagers();
|
await ObjectManagers.InitSQLManagers();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import {DiskMangerWorker} from '../src/backend/model/threading/DiskMangerWorker'
|
|||||||
|
|
||||||
const config: { path: string, system: string } = require(path.join(__dirname, 'config.json'));
|
const config: { path: string, system: string } = require(path.join(__dirname, 'config.json'));
|
||||||
Config.Server.Media.folder = config.path;
|
Config.Server.Media.folder = config.path;
|
||||||
const dbPath = path.join(__dirname, 'test.db');
|
const dbFolder = __dirname;
|
||||||
ProjectPath.reset();
|
ProjectPath.reset();
|
||||||
const RUNS = 50;
|
const RUNS = 50;
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ const printResult = (result: BenchmarkResult, action: string, actionDetails: str
|
|||||||
|
|
||||||
const run = async () => {
|
const run = async () => {
|
||||||
const start = Date.now();
|
const start = Date.now();
|
||||||
const bm = new Benchmarks(RUNS, dbPath);
|
const bm = new Benchmarks(RUNS, dbFolder);
|
||||||
|
|
||||||
// header
|
// header
|
||||||
await printHeader();
|
await printHeader();
|
||||||
|
|||||||
@ -7,29 +7,25 @@ import {PrivateConfigDefaultsClass} from './PrivateConfigDefaultsClass';
|
|||||||
|
|
||||||
declare var process: NodeJS.Process;
|
declare var process: NodeJS.Process;
|
||||||
|
|
||||||
/**
|
let CONFIG_PATH = path.join(__dirname, './../../../../config.json');
|
||||||
* 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
|
// TODO: refactor this
|
||||||
let configPath = process.argv.find(s => s.startsWith('--config-path='));
|
let configPath = process.argv.find(s => s.startsWith('--config-path='));
|
||||||
if (configPath) {
|
if (configPath) {
|
||||||
configPath = configPath.replace('--config-path=', '');
|
configPath = configPath.replace('--config-path=', '');
|
||||||
if (path.isAbsolute(configPath)) {
|
if (path.isAbsolute(configPath)) {
|
||||||
ConfigClass.CONFIG_PATH = configPath;
|
CONFIG_PATH = configPath;
|
||||||
} else {
|
} else {
|
||||||
ConfigClass.CONFIG_PATH = path.join(__dirname, './../../../../', configPath);
|
CONFIG_PATH = path.join(__dirname, './../../../../', configPath);
|
||||||
}
|
|
||||||
console.log('using config path:' + ConfigClass.CONFIG_PATH);
|
|
||||||
}
|
}
|
||||||
|
console.log('using config path:' + CONFIG_PATH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This configuration will be only at backend
|
||||||
|
*/
|
||||||
|
export class ConfigClass extends PrivateConfigDefaultsClass implements IPrivateConfig {
|
||||||
|
|
||||||
|
|
||||||
public setDatabaseType(type: ServerConfig.DatabaseType) {
|
public setDatabaseType(type: ServerConfig.DatabaseType) {
|
||||||
this.Server.Database.type = type;
|
this.Server.Database.type = type;
|
||||||
if (type === ServerConfig.DatabaseType.memory) {
|
if (type === ServerConfig.DatabaseType.memory) {
|
||||||
@ -40,7 +36,7 @@ export class ConfigClass extends PrivateConfigDefaultsClass implements IPrivateC
|
|||||||
|
|
||||||
public load() {
|
public load() {
|
||||||
this.addComment();
|
this.addComment();
|
||||||
ConfigLoader.loadBackendConfig(this, ConfigClass.CONFIG_PATH,
|
ConfigLoader.loadBackendConfig(this, CONFIG_PATH,
|
||||||
[['PORT', 'Server-port'],
|
[['PORT', 'Server-port'],
|
||||||
['MYSQL_HOST', 'Server-Database-mysql-host'],
|
['MYSQL_HOST', 'Server-Database-mysql-host'],
|
||||||
['MYSQL_PASSWORD', 'Server-Database-mysql-password'],
|
['MYSQL_PASSWORD', 'Server-Database-mysql-password'],
|
||||||
@ -69,7 +65,7 @@ export class ConfigClass extends PrivateConfigDefaultsClass implements IPrivateC
|
|||||||
public save() {
|
public save() {
|
||||||
try {
|
try {
|
||||||
this.addComment();
|
this.addComment();
|
||||||
ConfigLoader.saveConfigFile(ConfigClass.CONFIG_PATH, this);
|
ConfigLoader.saveConfigFile(CONFIG_PATH, this);
|
||||||
this.removeComment();
|
this.removeComment();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new Error('Error during saving config: ' + e.toString());
|
throw new Error('Error during saving config: ' + e.toString());
|
||||||
|
|||||||
@ -87,7 +87,7 @@ export class PrivateConfigDefaultsClass extends PublicConfigClass implements IPr
|
|||||||
afterScheduleName: DefaultsJobs[DefaultsJobs.Indexing]
|
afterScheduleName: DefaultsJobs[DefaultsJobs.Indexing]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
/* {
|
||||||
name: DefaultsJobs[DefaultsJobs['Photo Converting']],
|
name: DefaultsJobs[DefaultsJobs['Photo Converting']],
|
||||||
jobName: DefaultsJobs[DefaultsJobs['Photo Converting']],
|
jobName: DefaultsJobs[DefaultsJobs['Photo Converting']],
|
||||||
config: {},
|
config: {},
|
||||||
@ -95,14 +95,14 @@ export class PrivateConfigDefaultsClass extends PublicConfigClass implements IPr
|
|||||||
type: JobTriggerType.after,
|
type: JobTriggerType.after,
|
||||||
afterScheduleName: DefaultsJobs[DefaultsJobs['Thumbnail Generation']]
|
afterScheduleName: DefaultsJobs[DefaultsJobs['Thumbnail Generation']]
|
||||||
}
|
}
|
||||||
},
|
},*/
|
||||||
{
|
{
|
||||||
name: DefaultsJobs[DefaultsJobs['Video Converting']],
|
name: DefaultsJobs[DefaultsJobs['Video Converting']],
|
||||||
jobName: DefaultsJobs[DefaultsJobs['Video Converting']],
|
jobName: DefaultsJobs[DefaultsJobs['Video Converting']],
|
||||||
config: {},
|
config: {},
|
||||||
trigger: {
|
trigger: {
|
||||||
type: JobTriggerType.after,
|
type: JobTriggerType.after,
|
||||||
afterScheduleName: DefaultsJobs[DefaultsJobs['Photo Converting']]
|
afterScheduleName: DefaultsJobs[DefaultsJobs['Thumbnail Generation']]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,11 +1,13 @@
|
|||||||
import {Config} from '../../src/common/config/private/Config';
|
import {Config} from '../../src/common/config/private/Config';
|
||||||
import * as fs from 'fs';
|
|
||||||
import * as path from 'path';
|
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 {SQLConnection} from '../../src/backend/model/database/sql/SQLConnection';
|
||||||
import {ServerConfig} from '../../src/common/config/private/IPrivateConfig';
|
import {ServerConfig} from '../../src/common/config/private/IPrivateConfig';
|
||||||
|
|
||||||
declare let describe: any;
|
declare let describe: any;
|
||||||
const savedDescribe = describe;
|
const savedDescribe = describe;
|
||||||
|
const rimrafPR = util.promisify(rimraf);
|
||||||
|
|
||||||
export class SQLTestHelper {
|
export class SQLTestHelper {
|
||||||
|
|
||||||
@ -15,12 +17,9 @@ export class SQLTestHelper {
|
|||||||
};
|
};
|
||||||
public static readonly savedDescribe = savedDescribe;
|
public static readonly savedDescribe = savedDescribe;
|
||||||
tempDir: string;
|
tempDir: string;
|
||||||
dbPath: string;
|
|
||||||
|
|
||||||
constructor(public dbType: ServerConfig.DatabaseType) {
|
constructor(public dbType: ServerConfig.DatabaseType) {
|
||||||
this.tempDir = path.join(__dirname, './tmp');
|
this.tempDir = path.join(__dirname, './tmp');
|
||||||
this.dbPath = path.join(__dirname, './tmp', 'test.db');
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static describe(name: string, tests: (helper?: SQLTestHelper) => void) {
|
static describe(name: string, tests: (helper?: SQLTestHelper) => void) {
|
||||||
@ -63,7 +62,7 @@ export class SQLTestHelper {
|
|||||||
await this.resetSQLite();
|
await this.resetSQLite();
|
||||||
|
|
||||||
Config.Server.Database.type = ServerConfig.DatabaseType.sqlite;
|
Config.Server.Database.type = ServerConfig.DatabaseType.sqlite;
|
||||||
Config.Server.Database.dbFolder = path.dirname(this.dbPath);
|
Config.Server.Database.dbFolder = this.tempDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async initMySQL() {
|
private async initMySQL() {
|
||||||
@ -75,13 +74,7 @@ export class SQLTestHelper {
|
|||||||
|
|
||||||
private async resetSQLite() {
|
private async resetSQLite() {
|
||||||
await SQLConnection.close();
|
await SQLConnection.close();
|
||||||
|
await rimrafPR(this.tempDir);
|
||||||
if (fs.existsSync(this.dbPath)) {
|
|
||||||
fs.unlinkSync(this.dbPath);
|
|
||||||
}
|
|
||||||
if (fs.existsSync(this.tempDir)) {
|
|
||||||
fs.rmdirSync(this.tempDir);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async resetMySQL() {
|
private async resetMySQL() {
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import {expect} from 'chai';
|
import {expect} from 'chai';
|
||||||
import * as fs from 'fs';
|
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
import * as util from 'util';
|
||||||
|
import * as rimraf from 'rimraf';
|
||||||
import {Config} from '../../../../../src/common/config/private/Config';
|
import {Config} from '../../../../../src/common/config/private/Config';
|
||||||
import {SQLConnection} from '../../../../../src/backend/model/database/sql/SQLConnection';
|
import {SQLConnection} from '../../../../../src/backend/model/database/sql/SQLConnection';
|
||||||
import {UserEntity} from '../../../../../src/backend/model/database/sql/enitites/UserEntity';
|
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 {VersionEntity} from '../../../../../src/backend/model/database/sql/enitites/VersionEntity';
|
||||||
import {ServerConfig} from '../../../../../src/common/config/private/IPrivateConfig';
|
import {ServerConfig} from '../../../../../src/common/config/private/IPrivateConfig';
|
||||||
|
|
||||||
|
|
||||||
|
const rimrafPR = util.promisify(rimraf);
|
||||||
|
|
||||||
describe('Typeorm integration', () => {
|
describe('Typeorm integration', () => {
|
||||||
|
|
||||||
|
|
||||||
const tempDir = path.join(__dirname, '../../tmp');
|
const tempDir = path.join(__dirname, '../../tmp');
|
||||||
const dbPath = path.join(tempDir, 'test.db');
|
const setUpSqlDB = async () => {
|
||||||
const setUpSqlDB = () => {
|
await rimrafPR(tempDir);
|
||||||
if (fs.existsSync(dbPath)) {
|
|
||||||
fs.unlinkSync(dbPath);
|
|
||||||
}
|
|
||||||
if (!fs.existsSync(tempDir)) {
|
|
||||||
fs.mkdirSync(tempDir);
|
|
||||||
}
|
|
||||||
|
|
||||||
Config.Server.Database.type = ServerConfig.DatabaseType.sqlite;
|
Config.Server.Database.type = ServerConfig.DatabaseType.sqlite;
|
||||||
Config.Server.Database.dbFolder = path.dirname(dbPath);
|
Config.Server.Database.dbFolder = tempDir;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const teardownUpSqlDB = async () => {
|
const teardownUpSqlDB = async () => {
|
||||||
await SQLConnection.close();
|
await SQLConnection.close();
|
||||||
if (fs.existsSync(dbPath)) {
|
await rimrafPR(tempDir);
|
||||||
fs.unlinkSync(dbPath);
|
|
||||||
}
|
|
||||||
if (fs.existsSync(tempDir)) {
|
|
||||||
fs.rmdirSync(tempDir);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(async () => {
|
||||||
setUpSqlDB();
|
await setUpSqlDB();
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user