mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-05 23:29:00 +02:00
8f0913fafe
Make Mongo available to unit tests in all services GitOrigin-RevId: b65bbb69883d5bba31d09802b89f35bdc523fe4d
27 lines
861 B
JavaScript
27 lines
861 B
JavaScript
const Settings = require('@overleaf/settings')
|
|
const redis = require('@overleaf/redis-wrapper')
|
|
const { addConnectionDrainer } = require('./GracefulShutdown')
|
|
|
|
/**
|
|
* A per-feature interface to Redis, looks up the feature in `settings.redis`
|
|
* and returns an appropriate client. Necessary because we don't want to
|
|
* migrate web over to redis-cluster all at once.
|
|
*
|
|
* @param feature - one of 'websessions' | 'ratelimiter' | ...
|
|
*/
|
|
function client(feature) {
|
|
const redisFeatureSettings = Settings.redis[feature] || Settings.redis.web
|
|
const client = redis.createClient(redisFeatureSettings)
|
|
addConnectionDrainer(`redis ${feature}`, async () => {
|
|
await client.disconnect()
|
|
})
|
|
return client
|
|
}
|
|
|
|
async function cleanupTestRedis() {
|
|
const rclient = client()
|
|
await redis.cleanupTestRedis(rclient)
|
|
}
|
|
|
|
module.exports = { client, cleanupTestRedis }
|