-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
136 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import Redis from "../../../lib/redis"; | ||
import * as sinon from "sinon"; | ||
import { expect } from "chai"; | ||
import { Cluster } from "../../../lib"; | ||
import MockServer from "../../helpers/mock_server"; | ||
|
||
describe("disconnection", function () { | ||
afterEach(() => { | ||
sinon.restore(); | ||
}); | ||
|
||
it("should clear all timers on disconnect", function (done) { | ||
const server = new MockServer(30000); | ||
|
||
const setIntervalCalls = sinon.spy(global, "setInterval"); | ||
const clearIntervalCalls = sinon.spy(global, "clearInterval"); | ||
|
||
const cluster = new Cluster([{ host: "127.0.0.1", port: "30000" }]); | ||
cluster.on("connect", function () { | ||
cluster.disconnect(); | ||
}); | ||
|
||
cluster.on("end", function () { | ||
setTimeout(() => { | ||
// wait for disconnect with refresher. | ||
expect(setIntervalCalls.callCount).to.equal( | ||
clearIntervalCalls.callCount | ||
); | ||
server.disconnect(); | ||
done(); | ||
}, 500); | ||
}); | ||
}); | ||
|
||
it("should clear all timers on server exits", function (done) { | ||
const server = new MockServer(30000); | ||
|
||
const setIntervalCalls = sinon.spy(global, "setInterval"); | ||
const clearIntervalCalls = sinon.spy(global, "clearInterval"); | ||
|
||
const cluster = new Cluster([{ host: "127.0.0.1", port: "30000" }], { | ||
clusterRetryStrategy: null, | ||
}); | ||
cluster.on("end", function () { | ||
expect(setIntervalCalls.callCount).to.equal(clearIntervalCalls.callCount); | ||
done(); | ||
}); | ||
|
||
server.disconnect(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import Redis from "../../lib/redis"; | ||
import * as sinon from "sinon"; | ||
import { expect } from "chai"; | ||
import MockServer from "../helpers/mock_server"; | ||
|
||
describe("disconnection", function () { | ||
afterEach(() => { | ||
sinon.restore(); | ||
}); | ||
|
||
it("should clear all timers on disconnect", function (done) { | ||
const server = new MockServer(30000); | ||
|
||
const setIntervalCalls = sinon.spy(global, "setInterval"); | ||
const clearIntervalCalls = sinon.spy(global, "clearInterval"); | ||
|
||
const redis = new Redis({}); | ||
redis.on("connect", function () { | ||
redis.disconnect(); | ||
}); | ||
|
||
redis.on("end", function () { | ||
expect(setIntervalCalls.callCount).to.equal(clearIntervalCalls.callCount); | ||
server.disconnect(); | ||
done(); | ||
}); | ||
}); | ||
|
||
it("should clear all timers on server exits", function (done) { | ||
const server = new MockServer(30000); | ||
|
||
const setIntervalCalls = sinon.spy(global, "setInterval"); | ||
const clearIntervalCalls = sinon.spy(global, "clearInterval"); | ||
|
||
const redis = new Redis({ | ||
port: 30000, | ||
retryStrategy: null, | ||
}); | ||
redis.on("end", function () { | ||
expect(setIntervalCalls.callCount).to.equal(clearIntervalCalls.callCount); | ||
done(); | ||
}); | ||
|
||
server.disconnect(); | ||
}); | ||
}); |