diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 16da035..c2e71b3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,6 +10,8 @@ on: jobs: test: + env: + CI: true timeout-minutes: 10 runs-on: ubuntu-latest strategy: diff --git a/package.json b/package.json index 8ede626..2f09ae5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "limitd-redis", - "version": "8.3.1", + "version": "8.4.0", "description": "A database client for limits on top of redis", "main": "index.js", "repository": { @@ -30,6 +30,7 @@ "mockdate": "^3.0.5", "nyc": "^14.1.1", "sinon": "^19.0.2", + "sockopt": "^2.0.1", "toxiproxy-node-client": "^2.0.6" } } diff --git a/test/db.tests.js b/test/db.tests.js index 228de83..a7ff818 100644 --- a/test/db.tests.js +++ b/test/db.tests.js @@ -144,76 +144,6 @@ module.exports.tests = (clientCreator, opts) => { }); }); - describe('KeepAlive', () => { - const checkSocketOption = (portPairs, option, expectedValue, delta, done) => { - const pid = process.pid; - const command = `lsof -a -p ${pid} -i 4 -T f`; - - exec(command, (error, stdout, stderr) => { - if (error) { - return done(error); - } - if (stderr) { - return done(new Error(stderr)); - } - - const keepAliveOption = stdout - .split('\n') - .find(line => - portPairs.some(portPair => - line.includes(`:${portPair.localPort}`) - && line.includes(`:${portPair.remotePort}`) - ) - ); - assert.isNotNull(keepAliveOption, `no entry found for port ${portPairs}: ${stdout}`); - assert.notEqual(keepAliveOption, undefined, `no entry found for port ${portPairs}: ${stdout}`); - assert.include(keepAliveOption, option, `${option} option not found: ${keepAliveOption}`); - - const keepAliveValue = parseInt(keepAliveOption.match(new RegExp(`${option}=(\\d+)`))[1], 10); - assert.isAtLeast(keepAliveValue, expectedValue - delta, `${option} is lesser than expected`); - assert.isAtMost(keepAliveValue, expectedValue + delta, `${option} is greater than expected`); - - done(); - }); - }; - - it('should set SO=KEEPALIVE to 10000 by default', (done) => { - const ports = []; - if (opts.clusterNodes) { - Object.values(db.redis.connectionPool.nodes.all).forEach(node => { - ports.push({ localPort: node.stream.localPort, remotePort: node.stream.remotePort }); - }); - } else { - ports.push({ localPort: db.redis.stream.localPort, remotePort: db.redis.stream.remotePort }); - } - checkSocketOption(ports, 'SO=KEEPALIVE', 10000, 10, done); - }); - - describe('when setting keepAlive option', () => { - const keepAliveValue = 5000; - beforeEach((done) => { - db.close(() => { - db = clientCreator({ buckets, prefix: prefix, keepAlive: keepAliveValue }); - db.once('ready', () => done()); - }); - }); - - it('should set SO=KEEPALIVE to the value specified in the constructor config', (done) => { - const ports = []; - if (opts.clusterNodes) { - Object.values(db.redis.connectionPool.nodes.all) - .filter(node => node.status === 'ready') - .forEach(node => { - ports.push({ localPort: node.stream.localPort, remotePort: node.stream.remotePort }); - }); - } else { - ports.push({ localPort: db.redis.stream.localPort, remotePort: db.redis.stream.remotePort }); - } - checkSocketOption(ports, 'SO=KEEPALIVE', keepAliveValue, 10, done); - }); - }); - }); - describe('#constructor', () => { it('should throw an when missing redis information', () => { assert.throws(() => clientCreator({