DrainManagerTests.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /* eslint-disable
  2. camelcase,
  3. */
  4. // TODO: This file was created by bulk-decaffeinate.
  5. // Fix any style issues and re-enable lint.
  6. /*
  7. * decaffeinate suggestions:
  8. * DS102: Remove unnecessary code created because of implicit returns
  9. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  10. */
  11. const RealTimeClient = require('./helpers/RealTimeClient')
  12. const FixturesManager = require('./helpers/FixturesManager')
  13. const { expect } = require('chai')
  14. const async = require('async')
  15. const request = require('request')
  16. const Settings = require('settings-sharelatex')
  17. const drain = function (rate, callback) {
  18. request.post(
  19. {
  20. url: `http://localhost:3026/drain?rate=${rate}`,
  21. auth: {
  22. user: Settings.internal.realTime.user,
  23. pass: Settings.internal.realTime.pass
  24. }
  25. },
  26. (error, response, data) => callback(error, data)
  27. )
  28. return null
  29. }
  30. describe('DrainManagerTests', function () {
  31. before(function (done) {
  32. FixturesManager.setUpProject(
  33. {
  34. privilegeLevel: 'owner',
  35. project: {
  36. name: 'Test Project'
  37. }
  38. },
  39. (e, { project_id, user_id }) => {
  40. this.project_id = project_id
  41. this.user_id = user_id
  42. return done()
  43. }
  44. )
  45. return null
  46. })
  47. before(function (done) {
  48. // cleanup to speedup reconnecting
  49. this.timeout(10000)
  50. return RealTimeClient.disconnectAllClients(done)
  51. })
  52. // trigger and check cleanup
  53. it('should have disconnected all previous clients', function (done) {
  54. return RealTimeClient.getConnectedClients((error, data) => {
  55. if (error) {
  56. return done(error)
  57. }
  58. expect(data.length).to.equal(0)
  59. return done()
  60. })
  61. })
  62. return describe('with two clients in the project', function () {
  63. beforeEach(function (done) {
  64. return async.series(
  65. [
  66. (cb) => {
  67. this.clientA = RealTimeClient.connect()
  68. return this.clientA.on('connectionAccepted', cb)
  69. },
  70. (cb) => {
  71. this.clientB = RealTimeClient.connect()
  72. return this.clientB.on('connectionAccepted', cb)
  73. },
  74. (cb) => {
  75. return this.clientA.emit(
  76. 'joinProject',
  77. { project_id: this.project_id },
  78. cb
  79. )
  80. },
  81. (cb) => {
  82. return this.clientB.emit(
  83. 'joinProject',
  84. { project_id: this.project_id },
  85. cb
  86. )
  87. }
  88. ],
  89. done
  90. )
  91. })
  92. return describe('starting to drain', function () {
  93. beforeEach(function (done) {
  94. return async.parallel(
  95. [
  96. (cb) => {
  97. return this.clientA.on('reconnectGracefully', cb)
  98. },
  99. (cb) => {
  100. return this.clientB.on('reconnectGracefully', cb)
  101. },
  102. (cb) => drain(2, cb)
  103. ],
  104. done
  105. )
  106. })
  107. afterEach(function (done) {
  108. return drain(0, done)
  109. }) // reset drain
  110. it('should not timeout', function () {
  111. return expect(true).to.equal(true)
  112. })
  113. return it('should not have disconnected', function () {
  114. expect(this.clientA.socket.connected).to.equal(true)
  115. return expect(this.clientB.socket.connected).to.equal(true)
  116. })
  117. })
  118. })
  119. })