Skip to content

Commit

Permalink
[reconnect] write test cases for issue redis#1138
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandre-abrioux committed May 27, 2020
1 parent 1d4330d commit 6f5a0c1
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
26 changes: 26 additions & 0 deletions test/functional/cluster/connect.ts
Expand Up @@ -384,4 +384,30 @@ describe("cluster:connect", function () {
}
});
});

describe("multiple reconnect", function () {
it("should reconnect after multiple consecutive disconnect(true) are called", function (done) {
new MockServer(30001);
const cluster = new Cluster([{ host: "127.0.0.1", port: "30001" }], {
enableReadyCheck: false,
});
cluster.once("reconnecting", function () {
cluster.disconnect(true);
});
cluster.once("ready", function () {
cluster.disconnect(true);
const rejectTimeout = setTimeout(function () {
cluster.disconnect();
done(new Error("second disconnect(true) didn't reconnect redis"));
}, 1000);
process.nextTick(function () {
cluster.once("ready", function () {
clearTimeout(rejectTimeout);
cluster.disconnect();
done();
});
});
});
});
});
});
23 changes: 23 additions & 0 deletions test/functional/connection.ts
Expand Up @@ -451,4 +451,27 @@ describe("connection", function () {
});
});
});

describe("multiple reconnect", function () {
it("should reconnect after multiple consecutive disconnect(true) are called", function (done) {
const redis = new Redis();
redis.once("reconnecting", function () {
redis.disconnect(true);
});
redis.once("ready", function () {
redis.disconnect(true);
const rejectTimeout = setTimeout(function () {
redis.disconnect();
done(new Error("second disconnect(true) didn't reconnect redis"));
}, 1000);
process.nextTick(function () {
redis.once("ready", function () {
clearTimeout(rejectTimeout);
redis.disconnect();
done();
});
});
});
});
});
});

0 comments on commit 6f5a0c1

Please sign in to comment.