overleaf/services/real-time/test/acceptance/js/DrainManagerTests.js

136 lines
3.3 KiB
JavaScript
Raw Normal View History

/* eslint-disable
camelcase,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const RealTimeClient = require('./helpers/RealTimeClient')
const FixturesManager = require('./helpers/FixturesManager')
const { expect } = require('chai')
const async = require('async')
const request = require('request')
const Settings = require('@overleaf/settings')
const drain = function (rate, callback) {
request.post(
{
url: `http://localhost:3026/drain?rate=${rate}`,
auth: {
user: Settings.internal.realTime.user,
2021-07-13 11:04:45 +00:00
pass: Settings.internal.realTime.pass,
},
},
(error, response, data) => callback(error, data)
)
return null
}
describe('DrainManagerTests', function () {
before(function (done) {
FixturesManager.setUpProject(
{
privilegeLevel: 'owner',
project: {
2021-07-13 11:04:45 +00:00
name: 'Test Project',
},
},
(e, { project_id, user_id }) => {
this.project_id = project_id
this.user_id = user_id
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 11:04:45 +00:00
cb => {
this.clientA = RealTimeClient.connect()
return this.clientA.on('connectionAccepted', cb)
},
2021-07-13 11:04:45 +00:00
cb => {
this.clientB = RealTimeClient.connect()
return this.clientB.on('connectionAccepted', cb)
},
2021-07-13 11:04:45 +00:00
cb => {
return this.clientA.emit(
'joinProject',
{ project_id: this.project_id },
cb
)
},
2021-07-13 11:04:45 +00:00
cb => {
return this.clientB.emit(
'joinProject',
{ project_id: this.project_id },
cb
)
2021-07-13 11:04:45 +00:00
},
],
done
)
})
return describe('starting to drain', function () {
beforeEach(function (done) {
return async.parallel(
[
2021-07-13 11:04:45 +00:00
cb => {
return this.clientA.on('reconnectGracefully', cb)
},
2021-07-13 11:04:45 +00:00
cb => {
return this.clientB.on('reconnectGracefully', cb)
},
2021-07-13 11:04:45 +00:00
cb => drain(2, cb),
],
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)
})
})
})
})