DrainManagerTests.js 2.7 KB

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