YUKI Hiroshi
null+****@clear*****
Wed Feb 13 15:55:09 JST 2013
YUKI Hiroshi 2013-02-13 15:55:09 +0900 (Wed, 13 Feb 2013) New Revision: 24ac722d68795e4316fe790a04645734a5f9c667 https://github.com/groonga/express-kotoumi/commit/24ac722d68795e4316fe790a04645734a5f9c667 Log: test: Mocked backend connections should accept multiple clients Modified files: test/test-utils.js Modified: test/test-utils.js (+27 -18) =================================================================== --- test/test-utils.js 2013-02-13 15:47:50 +0900 (56f2a88) +++ test/test-utils.js 2013-02-13 15:55:09 +0900 (dc00718) @@ -138,32 +138,41 @@ function createClientSocket() { } exports.createClientSocket = createClientSocket; -function createMockedBackendConnection(socketCommands) { +function createMockedBackendConnection(socketCommands, clientCount) { socketCommands = socketCommands || {}; + clientCount = Math.max(clientCount || 0, 1); var connection = nodemock; - var onMessageControllers = {}; + var onMessageControllers = []; var hasSocketCommand = false; - Object.keys(socketCommands).forEach(function(commandName) { - var command = socketCommands[commandName]; - hasSocketCommand = hasSocketCommand || - model.SocketCommand.isInstance(command); - if (model.PublishSubscribe.isInstance(command)) { - onMessageControllers[commandName] = {}; + + for (var i = 0; i < clientCount; i++) { + onMessageControllers.push({}); + + Object.keys(socketCommands).forEach(function(commandName) { + var command = socketCommands[commandName]; + hasSocketCommand = hasSocketCommand || + model.SocketCommand.isInstance(command); + if (model.PublishSubscribe.isInstance(command)) { + onMessageControllers[i][commandName] = {}; + connection = connection + .mock('on') + .takes(commandName, function() {}) + .ctrl(1, onMessageControllers[i][commandName]); + } + }); + + if (hasSocketCommand) { + onMessageControllers[i].error = {}; connection = connection .mock('on') - .takes(commandName, function() {}) - .ctrl(1, onMessageControllers[commandName]); + .takes('error', function() {}) + .ctrl(1, onMessageControllers[i].error); } - }); - - if (hasSocketCommand) { - onMessageControllers.error = {}; - connection = connection - .mock('on') - .takes('error', function() {}) - .ctrl(1, onMessageControllers.error); } + if (clientCount == 1) + onMessageControllers = onMessageControllers[0]; + connection.controllers = onMessageControllers; return connection; } -------------- next part -------------- HTML����������������������������... Download