2020-06-23 13:30:34 -04:00
|
|
|
/* eslint-disable
|
|
|
|
camelcase,
|
|
|
|
*/
|
|
|
|
// 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
|
|
|
|
*/
|
|
|
|
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("settings-sharelatex");
|
|
|
|
|
|
|
|
const drain = function(rate, callback) {
|
|
|
|
request.post({
|
|
|
|
url: `http://localhost:3026/drain?rate=${rate}`,
|
2020-02-21 10:11:09 -05:00
|
|
|
auth: {
|
|
|
|
user: Settings.internal.realTime.user,
|
|
|
|
pass: Settings.internal.realTime.pass
|
|
|
|
}
|
2020-06-23 13:30:29 -04:00
|
|
|
}, (error, response, data) => callback(error, data));
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
|
|
|
describe("DrainManagerTests", function() {
|
|
|
|
before(function(done) {
|
|
|
|
FixturesManager.setUpProject({
|
|
|
|
privilegeLevel: "owner",
|
2020-02-21 10:11:09 -05:00
|
|
|
project: {
|
|
|
|
name: "Test Project"
|
|
|
|
}
|
2020-06-23 13:30:29 -04:00
|
|
|
}, (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
|
2020-06-23 13:30:34 -04:00
|
|
|
it("should have disconnected all previous clients", function(done) { return RealTimeClient.getConnectedClients((error, data) => {
|
2020-06-23 13:30:29 -04:00
|
|
|
if (error) { return done(error); }
|
|
|
|
expect(data.length).to.equal(0);
|
|
|
|
return done();
|
2020-06-23 13:30:34 -04:00
|
|
|
}); });
|
2020-06-23 13:30:29 -04:00
|
|
|
|
|
|
|
return describe("with two clients in the project", function() {
|
|
|
|
beforeEach(function(done) {
|
|
|
|
return async.series([
|
|
|
|
cb => {
|
|
|
|
this.clientA = RealTimeClient.connect();
|
|
|
|
return this.clientA.on("connectionAccepted", cb);
|
|
|
|
},
|
|
|
|
|
|
|
|
cb => {
|
|
|
|
this.clientB = RealTimeClient.connect();
|
|
|
|
return this.clientB.on("connectionAccepted", cb);
|
|
|
|
},
|
|
|
|
|
|
|
|
cb => {
|
|
|
|
return this.clientA.emit("joinProject", {project_id: this.project_id}, cb);
|
|
|
|
},
|
|
|
|
|
|
|
|
cb => {
|
|
|
|
return this.clientB.emit("joinProject", {project_id: this.project_id}, cb);
|
|
|
|
}
|
|
|
|
], done);
|
|
|
|
});
|
|
|
|
|
|
|
|
return describe("starting to drain", function() {
|
|
|
|
beforeEach(function(done) {
|
|
|
|
return async.parallel([
|
|
|
|
cb => {
|
|
|
|
return this.clientA.on("reconnectGracefully", cb);
|
|
|
|
},
|
|
|
|
cb => {
|
|
|
|
return this.clientB.on("reconnectGracefully", cb);
|
|
|
|
},
|
|
|
|
|
|
|
|
cb => drain(2, cb)
|
|
|
|
], done);
|
|
|
|
});
|
|
|
|
|
2020-06-23 13:30:34 -04:00
|
|
|
afterEach(function(done) { return drain(0, done); }); // reset drain
|
2020-06-23 13:30:29 -04:00
|
|
|
|
2020-06-23 13:30:34 -04:00
|
|
|
it("should not timeout", function() { return expect(true).to.equal(true); });
|
2020-06-23 13:30:29 -04:00
|
|
|
|
|
|
|
return it("should not have disconnected", function() {
|
|
|
|
expect(this.clientA.socket.connected).to.equal(true);
|
|
|
|
return expect(this.clientB.socket.connected).to.equal(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|