mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-03 06:40:20 -05:00
797d76f90e
[misc] track redis pub/sub payload sizes on publish GitOrigin-RevId: 7ef7ada34f9f6376abdd2b0b6aa10a5aac56a62f
107 lines
3 KiB
JavaScript
107 lines
3 KiB
JavaScript
/* eslint-disable
|
|
max-len,
|
|
no-return-assign,
|
|
*/
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
// Fix any style issues and re-enable lint.
|
|
/*
|
|
* decaffeinate suggestions:
|
|
* DS101: Remove unnecessary use of Array.from
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
*/
|
|
const SandboxedModule = require('sandboxed-module')
|
|
const sinon = require('sinon')
|
|
require('chai').should()
|
|
const modulePath = require('path').join(
|
|
__dirname,
|
|
'../../../../app/src/Features/Editor/EditorRealTimeController'
|
|
)
|
|
|
|
describe('EditorRealTimeController', function() {
|
|
beforeEach(function() {
|
|
this.rclient = { publish: sinon.stub() }
|
|
this.Metrics = { summary: sinon.stub() }
|
|
this.EditorRealTimeController = SandboxedModule.require(modulePath, {
|
|
globals: {
|
|
console: console
|
|
},
|
|
requires: {
|
|
'../../infrastructure/RedisWrapper': {
|
|
client: () => this.rclient
|
|
},
|
|
'../../infrastructure/Server': {
|
|
io: (this.io = {})
|
|
},
|
|
'settings-sharelatex': { redis: {} },
|
|
'metrics-sharelatex': this.Metrics,
|
|
crypto: (this.crypto = {
|
|
randomBytes: sinon
|
|
.stub()
|
|
.withArgs(4)
|
|
.returns(Buffer.from([0x1, 0x2, 0x3, 0x4]))
|
|
}),
|
|
os: (this.os = { hostname: sinon.stub().returns('somehost') })
|
|
}
|
|
})
|
|
|
|
this.room_id = 'room-id'
|
|
this.message = 'message-to-editor'
|
|
return (this.payload = ['argument one', 42])
|
|
})
|
|
|
|
describe('emitToRoom', function() {
|
|
beforeEach(function() {
|
|
this.message_id = 'web:somehost:01020304-0'
|
|
return this.EditorRealTimeController.emitToRoom(
|
|
this.room_id,
|
|
this.message,
|
|
...Array.from(this.payload)
|
|
)
|
|
})
|
|
|
|
it('should publish the message to redis', function() {
|
|
return this.rclient.publish
|
|
.calledWith(
|
|
'editor-events',
|
|
JSON.stringify({
|
|
room_id: this.room_id,
|
|
message: this.message,
|
|
payload: this.payload,
|
|
_id: this.message_id
|
|
})
|
|
)
|
|
.should.equal(true)
|
|
})
|
|
|
|
it('should track the payload size', function() {
|
|
this.Metrics.summary
|
|
.calledWith(
|
|
'redis.publish.editor-events',
|
|
JSON.stringify({
|
|
room_id: this.room_id,
|
|
message: this.message,
|
|
payload: this.payload,
|
|
_id: this.message_id
|
|
}).length
|
|
)
|
|
.should.equal(true)
|
|
})
|
|
})
|
|
|
|
describe('emitToAll', function() {
|
|
beforeEach(function() {
|
|
this.EditorRealTimeController.emitToRoom = sinon.stub()
|
|
return this.EditorRealTimeController.emitToAll(
|
|
this.message,
|
|
...Array.from(this.payload)
|
|
)
|
|
})
|
|
|
|
it("should emit to the room 'all'", function() {
|
|
return this.EditorRealTimeController.emitToRoom
|
|
.calledWith('all', this.message, ...Array.from(this.payload))
|
|
.should.equal(true)
|
|
})
|
|
})
|
|
})
|