Skip to content

Commit

Permalink
test: add test for connection resource cleanup with replicas
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Jul 25, 2024
1 parent a9eac4b commit 2e002b7
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test/connection/connection.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down

0 comments on commit 2e002b7

Please sign in to comment.