Skip to content

Commit

Permalink
test: increase the success rate of testing for subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
luin committed Jun 22, 2018
1 parent dc6a026 commit 1fdd46c
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions test/functional/pub_sub.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,20 @@ describe('pub/sub', function () {
var pub = new Redis();
redis.subscribe('foo', 'bar', function () {
redis.on('ready', function () {
var pending = 2;
redis.on('message', function (channel, message) {
if (!--pending) {
redis.disconnect();
pub.disconnect();
done();
}
});
pub.publish('foo', 'hi1');
pub.publish('bar', 'hi2');
// Execute a random command to make sure that `subscribe`
// is sent
redis.ping(function () {
var pending = 2;
redis.on('message', function (channel, message) {
if (!--pending) {
redis.disconnect();
pub.disconnect();
done();
}
});
pub.publish('foo', 'hi1');
pub.publish('bar', 'hi2');
})
});
redis.disconnect({ reconnect: true });
});
Expand All @@ -172,16 +176,18 @@ describe('pub/sub', function () {
var pub = new Redis();
redis.psubscribe('fo?o', 'ba?r', function () {
redis.on('ready', function () {
var pending = 2;
redis.on('pmessage', function (pattern, channel, message) {
if (!--pending) {
redis.disconnect();
pub.disconnect();
done();
}
redis.ping(function () {
var pending = 2;
redis.on('pmessage', function (pattern, channel, message) {
if (!--pending) {
redis.disconnect();
pub.disconnect();
done();
}
});
pub.publish('fo1o', 'hi1');
pub.publish('ba1r', 'hi2');
});
pub.publish('fo1o', 'hi1');
pub.publish('ba1r', 'hi2');
});
redis.disconnect({ reconnect: true });
});
Expand Down

0 comments on commit 1fdd46c

Please sign in to comment.