login.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Copyright 2015 rain1017.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
  12. // implied. See the License for the specific language governing
  13. // permissions and limitations under the License. See the AUTHORS file
  14. // for names of contributors.
  15. 'use strict';
  16. var quick = require('quick-pomelo');
  17. var P = quick.Promise;
  18. var logger = quick.logger.getLogger('test', __filename);
  19. var main = function(){
  20. var connector1 = {host : '127.0.0.1', port : 3100};
  21. var connector2 = {host : '127.0.0.1', port : 3101};
  22. var client1 = quick.mocks.client(connector1);
  23. var client2 = quick.mocks.client(connector2);
  24. var client3 = quick.mocks.client(connector1);
  25. var client4 = quick.mocks.client(connector2);
  26. var playerId = 'p1';
  27. return P.try(function(){
  28. return client1.connect();
  29. })
  30. .then(function(){
  31. return client1.request('player.playerHandler.create', {opts : {_id : playerId}});
  32. })
  33. .then(function(){
  34. return client1.request('connector.entryHandler.login', {token : playerId});
  35. })
  36. .then(function(){
  37. return client2.connect();
  38. })
  39. .then(function(){
  40. // Client1 should be kicked out
  41. return client2.request('connector.entryHandler.login', {token : playerId});
  42. })
  43. .then(function(){
  44. // Explicitly call logout
  45. return client2.request('connector.entryHandler.logout');
  46. })
  47. .then(function(){
  48. return client3.connect();
  49. })
  50. .then(function(){
  51. return client3.request('connector.entryHandler.login', {token : playerId});
  52. })
  53. .then(function(){
  54. // Auto logout on disconnect
  55. return client3.disconnect();
  56. })
  57. .delay(100)
  58. .then(function(){
  59. return client4.connect();
  60. })
  61. .then(function(){
  62. return client4.request('connector.entryHandler.login', {token : playerId});
  63. })
  64. .then(function(){
  65. // Remove and logout
  66. return client4.request('player.playerHandler.remove');
  67. })
  68. .then(function(){
  69. return client4.disconnect();
  70. })
  71. .catch(function(e){
  72. logger.error('%j', e);
  73. })
  74. .finally(function(){
  75. process.exit();
  76. });
  77. };
  78. if (require.main === module) {
  79. main();
  80. }