Skip to content

Commit

Permalink
bumped minor version
Browse files Browse the repository at this point in the history
  • Loading branch information
pubalokta committed Nov 12, 2024
1 parent 1ffff4d commit 1d97b19
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 71 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ on:

jobs:
test:
env:
CI: true
timeout-minutes: 10
runs-on: ubuntu-latest
strategy:
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down Expand Up @@ -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"
}
}
70 changes: 0 additions & 70 deletions test/db.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit 1d97b19

Please sign in to comment.