Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
laurent22 committed May 11, 2024
1 parent 777b080 commit 400aa33
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/server/src/db.replication.test.ts
@@ -1,5 +1,5 @@
import { afterAllTests, beforeAllDb, beforeEachDb, createFolder, createUserAndSession, db, dbSlave, expectThrow, models, packageRootDir, updateFolder } from './utils/testing/testUtils';
import { connectDb, disconnectDb, reconnectDb, sqliteSyncSlave } from './db';
import { connectDb, disconnectDb, isPostgres, reconnectDb, sqliteSyncSlave } from './db';
import { ChangeType, Event } from './services/database/types';
import { DatabaseConfig, DatabaseConfigClient } from './utils/types';
import { createDb } from './tools/dbTools';
Expand Down Expand Up @@ -29,6 +29,8 @@ const afterTest = async () => {
describe('db.replication', () => {

it('should reconnect a database', async () => {
if (isPostgres(db())) return;

await beforeTest();

await disconnectDb(db());
Expand Down Expand Up @@ -56,6 +58,8 @@ describe('db.replication', () => {
});

it('should manually sync an SQLite slave instance', async () => {
if (isPostgres(db())) return;

const masterConfig: DatabaseConfig = {
client: DatabaseConfigClient.SQLite,
name: `${packageRootDir}/db-master-test.sqlite`,
Expand Down Expand Up @@ -87,6 +91,8 @@ describe('db.replication', () => {
});

test('should track changes - using replication', async () => {
if (isPostgres(db())) return;

await beforeTest({ DB_USE_SLAVE: '1' });

const { session, user } = await createUserAndSession(1, true);
Expand Down
4 changes: 4 additions & 0 deletions packages/server/src/db.ts
Expand Up @@ -128,6 +128,10 @@ export async function waitForConnection(dbConfig: DatabaseConfig): Promise<Conne
}

export const clientType = (db: DbConnection): DatabaseConfigClient => {
// We have this extra check so that in tests we can quickly find out the database backend
// without having to use an initialized connection.
if (process.env.JOPLIN_TESTS_SERVER_DB === 'pg') return DatabaseConfigClient.PostgreSQL;
if (process.env.JOPLIN_TESTS_SERVER_DB === 'sqlite') return DatabaseConfigClient.SQLite;
return db.client.config.client;
};

Expand Down

0 comments on commit 400aa33

Please sign in to comment.