DrainManagerTests.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 drain = function (rate, callback) {
  17. request.post(
  18. {
  19. url: `http://localhost:3026/drain?rate=${rate}`,
  20. },
  21. (error, response, data) => callback(error, data)
  22. )
  23. return null
  24. }
  25. describe('DrainManagerTests', function () {
  26. before(function (done) {
  27. FixturesManager.setUpProject(
  28. {
  29. privilegeLevel: 'owner',
  30. project: {
  31. name: 'Test Project',
  32. },
  33. },
  34. (e, { project_id, user_id }) => {
  35. this.project_id = project_id
  36. this.user_id = user_id
  37. return done()
  38. }
  39. )
  40. return null
  41. })
  42. before(function (done) {
  43. // cleanup to speedup reconnecting
  44. this.timeout(10000)
  45. return RealTimeClient.disconnectAllClients(done)
  46. })
  47. // trigger and check cleanup
  48. it('should have disconnected all previous clients', function (done) {
  49. return RealTimeClient.getConnectedClients((error, data) => {
  50. if (error) {
  51. return done(error)
  52. }
  53. expect(data.length).to.equal(0)
  54. return done()
  55. })
  56. })
  57. return describe('with two clients in the project', function () {
  58. beforeEach(function (done) {
  59. return async.series(
  60. [
  61. cb => {
  62. this.clientA = RealTimeClient.connect()
  63. return this.clientA.on('connectionAccepted', cb)
  64. },
  65. cb => {
  66. this.clientB = RealTimeClient.connect()
  67. return this.clientB.on('connectionAccepted', cb)
  68. },
  69. cb => {
  70. return this.clientA.emit(
  71. 'joinProject',
  72. { project_id: this.project_id },
  73. cb
  74. )
  75. },
  76. cb => {
  77. return this.clientB.emit(
  78. 'joinProject',
  79. { project_id: this.project_id },
  80. cb
  81. )
  82. },
  83. ],
  84. done
  85. )
  86. })
  87. return describe('starting to drain', function () {
  88. beforeEach(function (done) {
  89. return async.parallel(
  90. [
  91. cb => {
  92. return this.clientA.on('reconnectGracefully', cb)
  93. },
  94. cb => {
  95. return this.clientB.on('reconnectGracefully', cb)
  96. },
  97. cb => drain(2, cb),
  98. ],
  99. done
  100. )
  101. })
  102. afterEach(function (done) {
  103. return drain(0, done)
  104. }) // reset drain
  105. it('should not timeout', function () {
  106. return expect(true).to.equal(true)
  107. })
  108. return it('should not have disconnected', function () {
  109. expect(this.clientA.socket.connected).to.equal(true)
  110. return expect(this.clientB.socket.connected).to.equal(true)
  111. })
  112. })
  113. })
  114. })