2020-06-23 13:30:34 -04:00
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
2020-06-23 13:30:29 -04:00
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
2020-06-23 13:30:45 -04:00
|
|
|
const RealTimeClient = require('./helpers/RealTimeClient')
|
|
|
|
const FixturesManager = require('./helpers/FixturesManager')
|
|
|
|
|
|
|
|
const { expect } = require('chai')
|
|
|
|
|
|
|
|
const async = require('async')
|
|
|
|
const request = require('request')
|
|
|
|
|
|
|
|
const drain = function (rate, callback) {
|
|
|
|
request.post(
|
|
|
|
{
|
2024-04-25 08:56:00 -04:00
|
|
|
url: `http://127.0.0.1:3026/drain?rate=${rate}`,
|
2020-06-23 13:30:45 -04:00
|
|
|
},
|
|
|
|
(error, response, data) => callback(error, data)
|
|
|
|
)
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('DrainManagerTests', function () {
|
|
|
|
before(function (done) {
|
|
|
|
FixturesManager.setUpProject(
|
|
|
|
{
|
|
|
|
privilegeLevel: 'owner',
|
|
|
|
project: {
|
2021-07-13 07:04:45 -04:00
|
|
|
name: 'Test Project',
|
|
|
|
},
|
2020-06-23 13:30:45 -04:00
|
|
|
},
|
2023-03-20 10:10:40 -04:00
|
|
|
(e, { project_id: projectId, user_id: userId }) => {
|
|
|
|
this.project_id = projectId
|
|
|
|
this.user_id = userId
|
2020-06-23 13:30:45 -04:00
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
return null
|
|
|
|
})
|
|
|
|
|
|
|
|
before(function (done) {
|
|
|
|
// cleanup to speedup reconnecting
|
|
|
|
this.timeout(10000)
|
|
|
|
return RealTimeClient.disconnectAllClients(done)
|
|
|
|
})
|
|
|
|
|
|
|
|
// trigger and check cleanup
|
|
|
|
it('should have disconnected all previous clients', function (done) {
|
|
|
|
return RealTimeClient.getConnectedClients((error, data) => {
|
|
|
|
if (error) {
|
|
|
|
return done(error)
|
|
|
|
}
|
|
|
|
expect(data.length).to.equal(0)
|
|
|
|
return done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
return describe('with two clients in the project', function () {
|
|
|
|
beforeEach(function (done) {
|
|
|
|
return async.series(
|
|
|
|
[
|
2021-07-13 07:04:45 -04:00
|
|
|
cb => {
|
2023-11-29 09:50:21 -05:00
|
|
|
this.clientA = RealTimeClient.connect(this.project_id, cb)
|
2020-06-23 13:30:45 -04:00
|
|
|
},
|
|
|
|
|
2021-07-13 07:04:45 -04:00
|
|
|
cb => {
|
2023-11-29 09:50:21 -05:00
|
|
|
this.clientB = RealTimeClient.connect(this.project_id, cb)
|
2021-07-13 07:04:45 -04:00
|
|
|
},
|
2020-06-23 13:30:45 -04:00
|
|
|
],
|
|
|
|
done
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
return describe('starting to drain', function () {
|
|
|
|
beforeEach(function (done) {
|
|
|
|
return async.parallel(
|
|
|
|
[
|
2021-07-13 07:04:45 -04:00
|
|
|
cb => {
|
2020-06-23 13:30:45 -04:00
|
|
|
return this.clientA.on('reconnectGracefully', cb)
|
|
|
|
},
|
2021-07-13 07:04:45 -04:00
|
|
|
cb => {
|
2020-06-23 13:30:45 -04:00
|
|
|
return this.clientB.on('reconnectGracefully', cb)
|
|
|
|
},
|
|
|
|
|
2021-07-13 07:04:45 -04:00
|
|
|
cb => drain(2, cb),
|
2020-06-23 13:30:45 -04:00
|
|
|
],
|
|
|
|
done
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
afterEach(function (done) {
|
|
|
|
return drain(0, done)
|
|
|
|
}) // reset drain
|
|
|
|
|
|
|
|
it('should not timeout', function () {
|
|
|
|
return expect(true).to.equal(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
return it('should not have disconnected', function () {
|
|
|
|
expect(this.clientA.socket.connected).to.equal(true)
|
|
|
|
return expect(this.clientB.socket.connected).to.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|