Skip to content

Commit 86f6794

Browse files
committed
test: make clearing the regression test database more explicit
1 parent 6b61875 commit 86f6794

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

spec/regression/initialization.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ export function getTempDatabase(): Database {
4444
});
4545
}
4646

47+
export function getTempDatabaseConfig(): ArangoDBConfig {
48+
return {
49+
url: DATABASE_URL,
50+
databaseName: DATABASE_NAME,
51+
};
52+
}
53+
4754
export interface TestDataEnvironment {
4855
fillTemplateStrings: (data: any) => any;
4956
}

spec/regression/regression-suite.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ import { IDGenerationInfo, IDGenerator } from '../../src/execution/execution-opt
99
import { ProjectOptions } from '../../src/project/project';
1010
import { loadProjectFromDir } from '../../src/project/project-from-fs';
1111
import { Log4jsLoggerProvider } from '../helpers/log4js-logger-provider';
12-
import { createTempDatabase, initTestData, TestDataEnvironment } from './initialization';
12+
import {
13+
createTempDatabase,
14+
getTempDatabaseConfig,
15+
initTestData,
16+
TestDataEnvironment,
17+
} from './initialization';
1318
import { ErrorWithCause } from '../../src/utils/error-with-cause';
1419
import { InitTestDataContext } from './init-test-data-context';
1520
import deepEqual = require('deep-equal');
@@ -55,8 +60,6 @@ export class RegressionSuite {
5560
private schema: GraphQLSchema | undefined;
5661
private testDataEnvironment: TestDataEnvironment | undefined;
5762
private _isSetUpClean = false;
58-
// TODO: this is ugly but provides a quick fix for things broken with the silentAdapter
59-
// TODO: implement better regression test architecture for different db types
6063
private inMemoryDB: InMemoryDB = new InMemoryDB();
6164
private databaseSpecifier: DatabaseSpecifier;
6265
private readonly idGenerator = new PredictableIDGenerator();
@@ -81,7 +84,6 @@ export class RegressionSuite {
8184
? JSON.parse(stripJsonComments(readFileSync(optionsPath, 'utf-8')))
8285
: {};
8386

84-
this.inMemoryDB = new InMemoryDB();
8587
this.idGenerator.resetToPhase('init');
8688
const generalOptions: ProjectOptions = {
8789
processError: (e) => {
@@ -124,6 +126,7 @@ export class RegressionSuite {
124126
const adapter = await this.createAdapter(debugLevelOptions);
125127
this.schema = project.createSchema(adapter);
126128

129+
await this.clearDatabase();
127130
await initAdapter.updateSchema(initProject.getModel());
128131

129132
const testDataJsonPath = resolve(this.path, 'test-data.json');
@@ -168,6 +171,19 @@ export class RegressionSuite {
168171
this._isSetUpClean = true;
169172
}
170173

174+
private async clearDatabase() {
175+
switch (this.databaseSpecifier) {
176+
case 'in-memory':
177+
this.inMemoryDB = new InMemoryDB();
178+
break;
179+
case 'arangodb':
180+
await createTempDatabase();
181+
break;
182+
default:
183+
throw new Error(`Unknown database specifier: ${this.databaseSpecifier}`);
184+
}
185+
}
186+
171187
private async createAdapter(
172188
context: ProjectOptions,
173189
{ isInitSchema = false } = {},
@@ -176,10 +192,9 @@ export class RegressionSuite {
176192
case 'in-memory':
177193
return new InMemoryAdapter({ db: this.inMemoryDB }, context);
178194
case 'arangodb':
179-
const dbConnectionConfig = await createTempDatabase();
180195
return new ArangoDBAdapter(
181196
{
182-
...dbConnectionConfig,
197+
...getTempDatabaseConfig(),
183198
// intentionally set low so we catch issues in tests
184199
// but silent schema uses higher limit because it's used in the setup
185200
queryMemoryLimit: isInitSchema

0 commit comments

Comments
 (0)