From c308e60b6bdf3c84c2c8bbfa8c34f65d0793c0a7 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Mon, 8 Feb 2021 11:13:22 +0000 Subject: [PATCH] speed up DocumentUpdaterControllerTests by directly injecting redis into tests --- .../unit/js/DocumentUpdaterControllerTests.js | 41 ++++++++++--------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/services/real-time/test/unit/js/DocumentUpdaterControllerTests.js b/services/real-time/test/unit/js/DocumentUpdaterControllerTests.js index 832ad9490a..738375b32a 100644 --- a/services/real-time/test/unit/js/DocumentUpdaterControllerTests.js +++ b/services/real-time/test/unit/js/DocumentUpdaterControllerTests.js @@ -20,14 +20,14 @@ const modulePath = require('path').join( const MockClient = require('./helpers/MockClient') describe('DocumentUpdaterController', function () { - beforeEach(function () { + beforeEach(function (done) { this.project_id = 'project-id-123' this.doc_id = 'doc-id-123' this.callback = sinon.stub() this.io = { mock: 'socket.io' } this.rclient = [] this.RoomEvents = { on: sinon.stub() } - return (this.EditorUpdatesController = SandboxedModule.require(modulePath, { + this.EditorUpdatesController = SandboxedModule.require(modulePath, { requires: { 'logger-sharelatex': (this.logger = { error: sinon.stub(), @@ -46,13 +46,17 @@ describe('DocumentUpdaterController', function () { pubsub: null } }), - '@overleaf/redis-wrapper': (this.redis = { - createClient: (name) => { - let rclientStub - this.rclient.push((rclientStub = { name })) - return rclientStub + './RedisClientManager': { + createClientList: () => { + this.redis = { + createClient: (name) => { + let rclientStub + this.rclient.push((rclientStub = { name })) + return rclientStub + } + } } - }), + }, './SafeJsonParse': (this.SafeJsonParse = { parse: (data, cb) => cb(null, JSON.parse(data)) }), @@ -64,7 +68,8 @@ describe('DocumentUpdaterController', function () { }), './ChannelManager': (this.ChannelManager = {}) } - })) + }) + done() }) describe('listenForUpdatesFromDocumentUpdater', function () { @@ -78,22 +83,20 @@ describe('DocumentUpdaterController', function () { this.rclient[0].on = sinon.stub() this.rclient[1].subscribe = sinon.stub() this.rclient[1].on = sinon.stub() - return this.EditorUpdatesController.listenForUpdatesFromDocumentUpdater() + this.EditorUpdatesController.listenForUpdatesFromDocumentUpdater() }) it('should subscribe to the doc-updater stream', function () { - return this.rclient[0].subscribe - .calledWith('applied-ops') - .should.equal(true) + this.rclient[0].subscribe.calledWith('applied-ops').should.equal(true) }) it('should register a callback to handle updates', function () { - return this.rclient[0].on.calledWith('message').should.equal(true) + this.rclient[0].on.calledWith('message').should.equal(true) }) - return it('should subscribe to any additional doc-updater stream', function () { + it('should subscribe to any additional doc-updater stream', function () { this.rclient[1].subscribe.calledWith('applied-ops').should.equal(true) - return this.rclient[1].on.calledWith('message').should.equal(true) + this.rclient[1].on.calledWith('message').should.equal(true) }) }) @@ -110,7 +113,7 @@ describe('DocumentUpdaterController', function () { ) }) - return it('should log an error', function () { + it('should log an error', function () { return this.logger.error.called.should.equal(true) }) }) @@ -129,14 +132,14 @@ describe('DocumentUpdaterController', function () { ) }) - return it('should apply the update', function () { + it('should apply the update', function () { return this.EditorUpdatesController._applyUpdateFromDocumentUpdater .calledWith(this.io, this.doc_id, this.message.op) .should.equal(true) }) }) - return describe('with error', function () { + describe('with error', function () { beforeEach(function () { this.message = { doc_id: this.doc_id,