2020-02-17 12:35:50 -05:00
|
|
|
/* eslint-disable
|
|
|
|
no-unused-vars,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
2020-02-17 12:35:39 -05:00
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
2020-02-17 12:35:59 -05:00
|
|
|
const sinon = require('sinon')
|
2021-03-23 15:08:32 -04:00
|
|
|
const { expect } = require('chai')
|
2021-07-12 12:47:16 -04:00
|
|
|
const Settings = require('@overleaf/settings')
|
2020-02-17 12:35:59 -05:00
|
|
|
const LockManager = require('../../../app/js/LockManager')
|
|
|
|
const rclient = require('redis').createClient(Settings.redis.history) // Only works locally for now
|
|
|
|
const TrackChangesApp = require('./helpers/TrackChangesApp')
|
2015-10-08 09:20:36 -04:00
|
|
|
|
2020-06-04 04:24:21 -04:00
|
|
|
describe('Locking document', function () {
|
|
|
|
before(function (done) {
|
2020-02-17 12:35:59 -05:00
|
|
|
TrackChangesApp.ensureRunning(done)
|
|
|
|
return null
|
|
|
|
})
|
2018-05-24 07:02:27 -04:00
|
|
|
|
2020-06-04 04:24:21 -04:00
|
|
|
return describe('when the lock has expired in redis', function () {
|
|
|
|
before(function (done) {
|
2020-02-17 12:35:59 -05:00
|
|
|
LockManager.LOCK_TTL = 1 // second
|
|
|
|
LockManager.runWithLock(
|
|
|
|
'doc123',
|
2021-07-13 07:04:43 -04:00
|
|
|
releaseA => {
|
2020-02-17 12:35:59 -05:00
|
|
|
// we create a lock A and allow it to expire in redis
|
|
|
|
return setTimeout(
|
|
|
|
() =>
|
|
|
|
// now we create a new lock B and try to release A
|
|
|
|
LockManager.runWithLock(
|
|
|
|
'doc123',
|
2021-07-13 07:04:43 -04:00
|
|
|
releaseB => {
|
2020-02-17 12:35:59 -05:00
|
|
|
return releaseA()
|
|
|
|
}, // try to release lock A to see if it wipes out lock B
|
2021-10-27 05:49:18 -04:00
|
|
|
() => {}
|
2020-02-17 12:35:59 -05:00
|
|
|
),
|
2015-10-08 09:20:36 -04:00
|
|
|
|
2020-02-17 12:35:59 -05:00
|
|
|
// we never release lock B so nothing should happen here
|
|
|
|
1500
|
|
|
|
)
|
|
|
|
}, // enough time to wait until the lock has expired
|
2021-10-27 05:49:18 -04:00
|
|
|
err => {
|
2020-02-17 12:35:59 -05:00
|
|
|
// we get here after trying to release lock A
|
2021-10-27 05:49:18 -04:00
|
|
|
expect(err).to.exist
|
2020-02-17 12:35:59 -05:00
|
|
|
done()
|
2021-10-27 05:49:18 -04:00
|
|
|
}
|
2020-02-17 12:35:59 -05:00
|
|
|
)
|
|
|
|
return null
|
|
|
|
})
|
|
|
|
|
2020-06-04 04:24:21 -04:00
|
|
|
return it('the new lock should not be removed by the expired locker', function (done) {
|
2020-02-17 12:35:59 -05:00
|
|
|
LockManager.checkLock('doc123', (err, isFree) => {
|
2021-10-27 05:49:18 -04:00
|
|
|
if (err) return done(err)
|
2020-02-17 12:35:59 -05:00
|
|
|
expect(isFree).to.equal(false)
|
|
|
|
return done()
|
|
|
|
})
|
|
|
|
return null
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|