-
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.
fix(cluster): subscriber connection leaks
Closes #1325
- Loading branch information
Showing
3 changed files
with
48 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import ConnectionPool from "../../../lib/cluster/ConnectionPool"; | ||
import ClusterSubscriber from "../../../lib/cluster/ClusterSubscriber"; | ||
import { EventEmitter } from "events"; | ||
import MockServer from "../../helpers/mock_server"; | ||
import { expect } from "chai"; | ||
|
||
describe("ClusterSubscriber", () => { | ||
it("cleans up subscribers when selecting a new one", async () => { | ||
const pool = new ConnectionPool({}); | ||
const subscriber = new ClusterSubscriber(pool, new EventEmitter()); | ||
|
||
let rejectSubscribes = false; | ||
const server = new MockServer(30000, (argv) => { | ||
if (rejectSubscribes && argv[0] === "subscribe") { | ||
return new Error("Failed to subscribe"); | ||
} | ||
return "OK"; | ||
}); | ||
|
||
pool.findOrCreate({ host: "127.0.0.1", port: 30000 }); | ||
|
||
subscriber.start(); | ||
await subscriber.getInstance().subscribe("foo"); | ||
rejectSubscribes = true; | ||
|
||
subscriber.start(); | ||
await subscriber.getInstance().echo("hello"); | ||
|
||
subscriber.start(); | ||
await subscriber.getInstance().echo("hello"); | ||
|
||
expect(server.getAllClients()).to.have.lengthOf(1); | ||
subscriber.stop(); | ||
pool.reset([]); | ||
}); | ||
}); |
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