From 2e002b7c36707a83e50aba1a072df9ec4fb9888f Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Thu, 25 Jul 2024 10:25:05 +0530 Subject: [PATCH] test: add test for connection resource cleanup with replicas --- test/connection/connection.spec.ts | 32 ++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/test/connection/connection.spec.ts b/test/connection/connection.spec.ts index aaf55c41..e49d4162 100644 --- a/test/connection/connection.spec.ts +++ b/test/connection/connection.spec.ts @@ -122,6 +122,38 @@ test.group('Connection | setup', (group) => { await connection.disconnect() }).waitForDone() + + test('cleanup read/write clients when connection is closed', async ({ assert }) => { + let disconnectEmitsCount = 0 + + const config = getConfig() + config.replicas! = { + write: { + connection: { + host: '10.0.0.1', + }, + }, + read: { + connection: [ + { + host: '10.0.0.1', + }, + ], + }, + } + + const connection = new Connection('primary', config, logger) + connection.connect() + connection.on('disconnect', () => { + disconnectEmitsCount++ + }) + + await connection.disconnect() + + assert.equal(disconnectEmitsCount, 2) + assert.isUndefined(connection.client) + assert.isUndefined(connection.readClient) + }).skip(['sqlite', 'better_sqlite', 'libsql'].includes(process.env.DB!)) }) if (process.env.DB === 'mysql') {