2020-05-06 06:11:22 -04:00
|
|
|
/* eslint-disable
|
|
|
|
no-unused-vars,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
2020-05-06 06:10:51 -04:00
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* DS206: Consider reworking classes to avoid initClass
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
2020-05-06 06:11:36 -04:00
|
|
|
const sinon = require('sinon')
|
|
|
|
const assert = require('assert')
|
|
|
|
const path = require('path')
|
|
|
|
const modulePath = path.join(__dirname, '../../../../app/js/LockManager.js')
|
2023-03-21 08:06:13 -04:00
|
|
|
const projectId = 1234
|
|
|
|
const docId = 5678
|
|
|
|
const blockingKey = `Blocking:${docId}`
|
2020-05-06 06:11:36 -04:00
|
|
|
const SandboxedModule = require('sandboxed-module')
|
2014-02-12 05:40:42 -05:00
|
|
|
|
2020-05-06 06:11:36 -04:00
|
|
|
describe('LockManager - checking the lock', function () {
|
|
|
|
let Profiler
|
|
|
|
const existsStub = sinon.stub()
|
2014-02-12 05:40:42 -05:00
|
|
|
|
2020-05-06 06:11:36 -04:00
|
|
|
const mocks = {
|
2020-11-10 06:32:04 -05:00
|
|
|
'@overleaf/redis-wrapper': {
|
2020-05-06 06:11:36 -04:00
|
|
|
createClient() {
|
|
|
|
return {
|
|
|
|
auth() {},
|
2021-07-13 07:04:42 -04:00
|
|
|
exists: existsStub,
|
2020-05-06 06:11:36 -04:00
|
|
|
}
|
2021-07-13 07:04:42 -04:00
|
|
|
},
|
2020-05-06 06:11:36 -04:00
|
|
|
},
|
2023-05-23 04:10:44 -04:00
|
|
|
'@overleaf/metrics': { inc() {} },
|
2020-05-06 06:11:36 -04:00
|
|
|
'./Profiler': (Profiler = (function () {
|
|
|
|
Profiler = class Profiler {
|
|
|
|
static initClass() {
|
|
|
|
this.prototype.log = sinon.stub().returns({ end: sinon.stub() })
|
|
|
|
this.prototype.end = sinon.stub()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Profiler.initClass()
|
|
|
|
return Profiler
|
2021-07-13 07:04:42 -04:00
|
|
|
})()),
|
2020-05-06 06:11:36 -04:00
|
|
|
}
|
|
|
|
const LockManager = SandboxedModule.require(modulePath, { requires: mocks })
|
2014-02-12 05:40:42 -05:00
|
|
|
|
2020-05-06 06:11:36 -04:00
|
|
|
it('should return true if the key does not exists', function (done) {
|
|
|
|
existsStub.yields(null, '0')
|
2023-03-21 08:06:13 -04:00
|
|
|
return LockManager.checkLock(docId, (err, free) => {
|
2021-10-27 05:49:18 -04:00
|
|
|
if (err) return done(err)
|
2020-05-06 06:11:36 -04:00
|
|
|
free.should.equal(true)
|
|
|
|
return done()
|
|
|
|
})
|
|
|
|
})
|
2014-02-12 05:40:42 -05:00
|
|
|
|
2020-05-06 06:11:36 -04:00
|
|
|
return it('should return false if the key does exists', function (done) {
|
|
|
|
existsStub.yields(null, '1')
|
2023-03-21 08:06:13 -04:00
|
|
|
return LockManager.checkLock(docId, (err, free) => {
|
2021-10-27 05:49:18 -04:00
|
|
|
if (err) return done(err)
|
2020-05-06 06:11:36 -04:00
|
|
|
free.should.equal(false)
|
|
|
|
return done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|