Skip to content

Instantly share code, notes, and snippets.

@JuneKelly
Last active February 21, 2018 09:56
Show Gist options
  • Save JuneKelly/83478c96f9d0e5ee853eccebf9790b07 to your computer and use it in GitHub Desktop.
Save JuneKelly/83478c96f9d0e5ee853eccebf9790b07 to your computer and use it in GitHub Desktop.
Lock test failure
// Generated by CoffeeScript 1.12.4
(function() {
var SandboxedModule, chai, modulePath, path, should, sinon;
sinon = require('sinon');
chai = require('chai');
should = chai.should();
path = require('path');
modulePath = path.join(__dirname, '../../../../../app/js/infrastructure/LockManager.js');
SandboxedModule = require('sandboxed-module');
describe('LockManager - trying the lock', function() {
beforeEach(function() {
this.LockManager = SandboxedModule.require(modulePath, {
requires: {
"logger-sharelatex": {
log: function() {}
},
"./RedisWrapper": {
client: (function(_this) {
return function() {
return {
auth: function() {},
set: _this.set = sinon.stub()
};
};
})(this)
},
"settings-sharelatex": {
redis: {}
},
"metrics-sharelatex": {
inc: function() {}
}
}
});
this.callback = sinon.stub();
this.doc_id = "doc-id-123";
return this.key = "lock:web:{" + this.doc_id + "}";
});
describe("when the lock is not set", function() {
beforeEach(function() {
this.set.callsArgWith(5, null, "OK");
return this.LockManager._tryLock(this.key, this.callback);
});
it("should set the lock key with an expiry if it is not set", function() {
return this.set.calledWith(this.key, "locked", "EX", 30, "NX").should.equal(true);
});
return it("should return the callback with true", function() {
return this.callback.calledWith(null, true).should.equal(true);
});
});
return describe("when the lock is already set", function() {
beforeEach(function() {
this.set.callsArgWith(5, null, null);
return this.LockManager._tryLock(this.key, this.callback);
});
return it("should return the callback with false", function() {
return this.callback.calledWith(null, false).should.equal(true);
});
});
});
}).call(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment