LockManagerTests.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* eslint-disable
  2. handle-callback-err,
  3. no-unused-vars,
  4. */
  5. // TODO: This file was created by bulk-decaffeinate.
  6. // Fix any style issues and re-enable lint.
  7. /*
  8. * decaffeinate suggestions:
  9. * DS102: Remove unnecessary code created because of implicit returns
  10. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  11. */
  12. const sinon = require("sinon");
  13. const chai = require("chai");
  14. chai.should();
  15. const { expect } = chai;
  16. const mongojs = require("../../../app/js/mongojs");
  17. const { ObjectId } = mongojs;
  18. const Settings = require("settings-sharelatex");
  19. const LockManager = require("../../../app/js/LockManager");
  20. const rclient = require("redis").createClient(Settings.redis.history); // Only works locally for now
  21. const TrackChangesApp = require("./helpers/TrackChangesApp");
  22. describe("Locking document", function() {
  23. before(function(done){
  24. TrackChangesApp.ensureRunning(done);
  25. return null;
  26. });
  27. return describe("when the lock has expired in redis", function() {
  28. before(function(done) {
  29. LockManager.LOCK_TTL = 1; // second
  30. LockManager.runWithLock("doc123", releaseA => {
  31. // we create a lock A and allow it to expire in redis
  32. return setTimeout(() =>
  33. // now we create a new lock B and try to release A
  34. LockManager.runWithLock("doc123", releaseB => {
  35. return releaseA();
  36. } // try to release lock A to see if it wipes out lock B
  37. , (error) => {})
  38. // we never release lock B so nothing should happen here
  39. , 1500);
  40. } // enough time to wait until the lock has expired
  41. , error =>
  42. // we get here after trying to release lock A
  43. done()
  44. );
  45. return null;
  46. });
  47. return it("the new lock should not be removed by the expired locker", function(done) {
  48. LockManager.checkLock("doc123", (err, isFree) => {
  49. expect(isFree).to.equal(false);
  50. return done();
  51. });
  52. return null;
  53. });
  54. });
  55. });