Use the main redis instance for locks

This commit is contained in:
James Allen 2016-07-06 11:50:02 +01:00
parent e912ccc562
commit 508a95c19b
5 changed files with 9 additions and 14 deletions

View file

@ -1,7 +1,7 @@
metrics = require('./Metrics')
Settings = require('settings-sharelatex')
rclient = require("./RedisBackend").createClient()
keys = require('./RedisKeyBuilder')
redis = require("redis-sharelatex")
rclient = redis.createClient(Settings.redis.web)
logger = require "logger-sharelatex"
os = require "os"
crypto = require "crypto"
@ -11,6 +11,9 @@ PID = process.pid
RND = crypto.randomBytes(4).toString('hex')
COUNT = 0
keys =
blockingKey: ({doc_id}) -> "Blocking:#{doc_id}"
module.exports = LockManager =
LOCK_TEST_INTERVAL: 50 # 50ms between each test of the lock
MAX_LOCK_WAIT_TIME: 10000 # 10s maximum time to spend trying to get the lock

View file

@ -14,9 +14,7 @@ describe 'LockManager - checking the lock', ()->
mocks =
"logger-sharelatex": log:->
"./RedisKeyBuilder":
blockingKey: ({doc_id}) -> "Blocking:#{doc_id}"
"./RedisBackend":
"redis-sharelatex":
createClient : ()->
auth:->
exists: existsStub

View file

@ -12,9 +12,7 @@ describe 'LockManager - releasing the lock', ()->
evalStub = sinon.stub().yields(1)
mocks =
"logger-sharelatex": log:->
"./RedisKeyBuilder":
blockingKey: ({doc_id}) -> "Blocking:#{doc_id}"
"./RedisBackend":
"redis-sharelatex":
createClient : ()->
auth:->
eval: evalStub

View file

@ -8,9 +8,7 @@ describe 'LockManager - getting the lock', ->
beforeEach ->
@LockManager = SandboxedModule.require modulePath, requires:
"logger-sharelatex": log:->
"./RedisKeyBuilder":
blockingKey: ({doc_id}) -> "Blocking:#{doc_id}"
"./RedisBackend":
"redis-sharelatex":
createClient : () =>
auth:->
"./Metrics": {inc: () ->}

View file

@ -8,9 +8,7 @@ describe 'LockManager - trying the lock', ->
beforeEach ->
@LockManager = SandboxedModule.require modulePath, requires:
"logger-sharelatex": log:->
"./RedisKeyBuilder":
blockingKey: ({doc_id}) -> "Blocking:#{doc_id}"
"./RedisBackend":
"redis-sharelatex":
createClient : () =>
auth:->
set: @set = sinon.stub()