-
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): quit() ignores errors caused by disconnected connection (…
- Loading branch information
Showing
3 changed files
with
74 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
describe('cluster:quit', () => { | ||
it('quit successfully when server is disconnecting', (done) => { | ||
const slotTable = [ | ||
[0, 1000, ['127.0.0.1', 30001]], | ||
[1001, 16383, ['127.0.0.1', 30002]] | ||
] | ||
const server = new MockServer(30001, (argv, c) => { | ||
if (argv[0] === 'quit') { | ||
c.destroy() | ||
} | ||
}, slotTable) | ||
new MockServer(30002, (argv, c) => { | ||
if (argv[0] === 'quit') { | ||
c.destroy() | ||
} | ||
}, slotTable) | ||
|
||
const cluster = new Redis.Cluster([ | ||
{ host: '127.0.0.1', port: '30001' } | ||
]) | ||
cluster.on('ready', () => { | ||
server.disconnect() | ||
cluster.quit((err, res) => { | ||
expect(err).to.eql(null) | ||
expect(res).to.eql('OK') | ||
done() | ||
}) | ||
}) | ||
}) | ||
|
||
it('failed when quit returns error', function (done) { | ||
const ERROR_MESSAGE = 'quit random error' | ||
const slotTable = [ | ||
[0, 1000, ['127.0.0.1', 30001]], | ||
[1001, 16383, ['127.0.0.1', 30002]] | ||
] | ||
new MockServer(30001, function (argv, c) { | ||
if (argv[0] === 'quit') { | ||
return new Error(ERROR_MESSAGE) | ||
} | ||
}, slotTable) | ||
new MockServer(30002, function (argv, c) { | ||
if (argv[0] === 'quit') { | ||
c.destroy() | ||
} | ||
}, slotTable) | ||
|
||
const cluster = new Redis.Cluster([ | ||
{ host: '127.0.0.1', port: '30001' } | ||
]) | ||
cluster.on('ready', () => { | ||
cluster.quit((err) => { | ||
expect(err.message).to.eql(ERROR_MESSAGE) | ||
done() | ||
}) | ||
}) | ||
}) | ||
}) |
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