Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion cucumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const config = [
'--format @cucumber/pretty-formatter',
'--format html:.test-reports/integration/report.html',
'--format json:.test-reports/integration/report.json',
'--publish',
].join(' ')

module.exports = {
Expand Down
6 changes: 5 additions & 1 deletion src/app/worker.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { IRunnable } from '../@types/base'
import { IWebSocketServerAdapter } from '../@types/adapters'

import { closeCacheClient } from '../cache/client'
import { createLogger } from '../factories/logger-factory'
import { FSWatcher } from 'fs'
import { SettingsStatic } from '../utils/settings'
Expand Down Expand Up @@ -57,7 +58,10 @@ export class AppWorker implements IRunnable {
watcher.close()
}
}
this.adapter.close(callback)
this.adapter.close(async () => {
await closeCacheClient()
callback?.()
})
debug('closed')
}
}
7 changes: 7 additions & 0 deletions src/cache/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,10 @@ export const getCacheClient = (): CacheClient => {

return instance
}

export const closeCacheClient = async (): Promise<void> => {
if (instance?.isOpen) {
await instance.disconnect()
instance = undefined
}
}
17 changes: 6 additions & 11 deletions test/integration/features/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ import Sinon from 'sinon'
import { connect, createIdentity, createSubscription, sendEvent } from './helpers'
import { getMasterDbClient, getReadReplicaDbClient } from '../../../src/database/client'
import { AppWorker } from '../../../src/app/worker'
import { CacheClient } from '../../../src/@types/cache'
import { DatabaseClient } from '../../../src/@types/base'
import { Event } from '../../../src/@types/event'
import { getCacheClient } from '../../../src/cache/client'
import { SettingsStatic } from '../../../src/utils/settings'
import { workerFactory } from '../../../src/factories/worker-factory'

Expand All @@ -29,7 +27,6 @@ let worker: AppWorker

let dbClient: DatabaseClient
let rrDbClient: DatabaseClient
let cacheClient: CacheClient

export const streams = new WeakMap<WebSocket, Observable<unknown>>()

Expand All @@ -38,7 +35,6 @@ BeforeAll({ timeout: 1000 }, async function () {
process.env.SECRET = Math.random().toString().repeat(6)
dbClient = getMasterDbClient()
rrDbClient = getReadReplicaDbClient()
cacheClient = getCacheClient()
await dbClient.raw('SELECT 1=1')
await rrDbClient.raw('SELECT 1=1')
Sinon.stub(SettingsStatic, 'watchSettings')
Expand All @@ -57,13 +53,12 @@ BeforeAll({ timeout: 1000 }, async function () {
worker.run()
})

AfterAll(async function() {
worker.close(async () => {
await Promise.all([
dbClient.destroy(),
rrDbClient.destroy(),
cacheClient.disconnect(),
])
AfterAll({ timeout: 30000 }, async function() {
await new Promise<void>((resolve) => {
worker.close(async () => {
await Promise.all([dbClient.destroy(), rrDbClient.destroy()])
resolve()
})
})
})

Expand Down
Loading