|
|
@@ -7,7 +7,7 @@ const tk = require('timekeeper')
|
|
|
|
|
|
describe('RedisManager', function () {
|
|
|
beforeEach(function () {
|
|
|
- this.multi = { exec: sinon.stub().yields() }
|
|
|
+ this.multi = { exec: sinon.stub() }
|
|
|
this.rclient = { multi: () => this.multi }
|
|
|
tk.freeze(new Date())
|
|
|
this.RedisManager = SandboxedModule.require(modulePath, {
|
|
|
@@ -63,9 +63,6 @@ describe('RedisManager', function () {
|
|
|
lastUpdatedAt({ doc_id: docId }) {
|
|
|
return `lastUpdatedAt:${docId}`
|
|
|
},
|
|
|
- historyRangesSupport() {
|
|
|
- return 'HistoryRangesSupport'
|
|
|
- },
|
|
|
},
|
|
|
},
|
|
|
},
|
|
|
@@ -762,20 +759,16 @@ describe('RedisManager', function () {
|
|
|
|
|
|
describe('putDocInMemory', function () {
|
|
|
beforeEach(function () {
|
|
|
- this.multi.mset = sinon.stub()
|
|
|
- this.multi.sadd = sinon.stub()
|
|
|
+ this.rclient.mset = sinon.stub().yields(null)
|
|
|
this.rclient.sadd = sinon.stub().yields()
|
|
|
- this.doc = {
|
|
|
- lines: ['one', 'two', 'three', 'これは'],
|
|
|
- version: 42,
|
|
|
- ranges: { comments: 'mock', entries: 'mock' },
|
|
|
- pathname: '/a/b/c.tex',
|
|
|
- projectHistoryId: this.projectHistoryId,
|
|
|
- }
|
|
|
+ this.lines = ['one', 'two', 'three', 'これは']
|
|
|
+ this.version = 42
|
|
|
this.hash = crypto
|
|
|
.createHash('sha1')
|
|
|
- .update(JSON.stringify(this.doc.lines), 'utf8')
|
|
|
+ .update(JSON.stringify(this.lines), 'utf8')
|
|
|
.digest('hex')
|
|
|
+ this.ranges = { comments: 'mock', entries: 'mock' }
|
|
|
+ this.pathname = '/a/b/c.tex'
|
|
|
})
|
|
|
|
|
|
describe('with non-empty ranges', function () {
|
|
|
@@ -783,21 +776,25 @@ describe('RedisManager', function () {
|
|
|
this.RedisManager.putDocInMemory(
|
|
|
this.project_id,
|
|
|
this.docId,
|
|
|
- this.doc,
|
|
|
+ this.lines,
|
|
|
+ this.version,
|
|
|
+ this.ranges,
|
|
|
+ this.pathname,
|
|
|
+ this.projectHistoryId,
|
|
|
done
|
|
|
)
|
|
|
})
|
|
|
|
|
|
it('should set all the details in a single MSET call', function () {
|
|
|
- this.multi.mset
|
|
|
+ this.rclient.mset
|
|
|
.calledWith({
|
|
|
- [`doclines:${this.docId}`]: JSON.stringify(this.doc.lines),
|
|
|
+ [`doclines:${this.docId}`]: JSON.stringify(this.lines),
|
|
|
[`ProjectId:${this.docId}`]: this.project_id,
|
|
|
- [`DocVersion:${this.docId}`]: this.doc.version,
|
|
|
+ [`DocVersion:${this.docId}`]: this.version,
|
|
|
[`DocHash:${this.docId}`]: this.hash,
|
|
|
- [`Ranges:${this.docId}`]: JSON.stringify(this.doc.ranges),
|
|
|
- [`Pathname:${this.docId}`]: this.doc.pathname,
|
|
|
- [`ProjectHistoryId:${this.docId}`]: this.doc.projectHistoryId,
|
|
|
+ [`Ranges:${this.docId}`]: JSON.stringify(this.ranges),
|
|
|
+ [`Pathname:${this.docId}`]: this.pathname,
|
|
|
+ [`ProjectHistoryId:${this.docId}`]: this.projectHistoryId,
|
|
|
})
|
|
|
.should.equal(true)
|
|
|
})
|
|
|
@@ -811,33 +808,32 @@ describe('RedisManager', function () {
|
|
|
it('should not log any errors', function () {
|
|
|
this.logger.error.calledWith().should.equal(false)
|
|
|
})
|
|
|
-
|
|
|
- it('should not add the document to the HistoryRangesSupport set in Redis', function () {
|
|
|
- this.multi.sadd.should.not.have.been.calledWith('HistoryRangesSupport')
|
|
|
- })
|
|
|
})
|
|
|
|
|
|
describe('with empty ranges', function () {
|
|
|
beforeEach(function (done) {
|
|
|
- this.doc.ranges = {}
|
|
|
this.RedisManager.putDocInMemory(
|
|
|
this.project_id,
|
|
|
this.docId,
|
|
|
- this.doc,
|
|
|
+ this.lines,
|
|
|
+ this.version,
|
|
|
+ {},
|
|
|
+ this.pathname,
|
|
|
+ this.projectHistoryId,
|
|
|
done
|
|
|
)
|
|
|
})
|
|
|
|
|
|
it('should unset ranges', function () {
|
|
|
- this.multi.mset
|
|
|
+ this.rclient.mset
|
|
|
.calledWith({
|
|
|
- [`doclines:${this.docId}`]: JSON.stringify(this.doc.lines),
|
|
|
+ [`doclines:${this.docId}`]: JSON.stringify(this.lines),
|
|
|
[`ProjectId:${this.docId}`]: this.project_id,
|
|
|
- [`DocVersion:${this.docId}`]: this.doc.version,
|
|
|
+ [`DocVersion:${this.docId}`]: this.version,
|
|
|
[`DocHash:${this.docId}`]: this.hash,
|
|
|
[`Ranges:${this.docId}`]: null,
|
|
|
- [`Pathname:${this.docId}`]: this.doc.pathname,
|
|
|
- [`ProjectHistoryId:${this.docId}`]: this.doc.projectHistoryId,
|
|
|
+ [`Pathname:${this.docId}`]: this.pathname,
|
|
|
+ [`ProjectHistoryId:${this.docId}`]: this.projectHistoryId,
|
|
|
})
|
|
|
.should.equal(true)
|
|
|
})
|
|
|
@@ -851,7 +847,11 @@ describe('RedisManager', function () {
|
|
|
this.RedisManager.putDocInMemory(
|
|
|
this.project_id,
|
|
|
this.docId,
|
|
|
- this.doc,
|
|
|
+ this.lines,
|
|
|
+ this.version,
|
|
|
+ this.ranges,
|
|
|
+ this.pathname,
|
|
|
+ this.projectHistoryId,
|
|
|
this.callback
|
|
|
)
|
|
|
})
|
|
|
@@ -879,7 +879,11 @@ describe('RedisManager', function () {
|
|
|
this.RedisManager.putDocInMemory(
|
|
|
this.project_id,
|
|
|
this.docId,
|
|
|
- this.doc,
|
|
|
+ this.lines,
|
|
|
+ this.version,
|
|
|
+ this.ranges,
|
|
|
+ this.pathname,
|
|
|
+ this.projectHistoryId,
|
|
|
this.callback
|
|
|
)
|
|
|
})
|
|
|
@@ -894,25 +898,6 @@ describe('RedisManager', function () {
|
|
|
.should.equal(true)
|
|
|
})
|
|
|
})
|
|
|
-
|
|
|
- describe('with history ranges support', function () {
|
|
|
- beforeEach(function () {
|
|
|
- this.doc.historyRangesSupport = true
|
|
|
- this.RedisManager.putDocInMemory(
|
|
|
- this.project_id,
|
|
|
- this.docId,
|
|
|
- this.doc,
|
|
|
- this.callback
|
|
|
- )
|
|
|
- })
|
|
|
-
|
|
|
- it('should add the document to the HistoryRangesSupport set in Redis', function () {
|
|
|
- this.multi.sadd.should.have.been.calledWith(
|
|
|
- 'HistoryRangesSupport',
|
|
|
- this.docId
|
|
|
- )
|
|
|
- })
|
|
|
- })
|
|
|
})
|
|
|
|
|
|
describe('removeDocFromMemory', function () {
|
|
|
@@ -920,6 +905,7 @@ describe('RedisManager', function () {
|
|
|
this.multi.strlen = sinon.stub()
|
|
|
this.multi.del = sinon.stub()
|
|
|
this.multi.srem = sinon.stub()
|
|
|
+ this.multi.exec.yields()
|
|
|
this.RedisManager.removeDocFromMemory(this.project_id, this.docId, done)
|
|
|
})
|
|
|
|
|
|
@@ -949,13 +935,6 @@ describe('RedisManager', function () {
|
|
|
.calledWith(`DocsIn:${this.project_id}`, this.docId)
|
|
|
.should.equal(true)
|
|
|
})
|
|
|
-
|
|
|
- it('should remove the docId from the HistoryRangesSupport set', function () {
|
|
|
- this.multi.srem.should.have.been.calledWith(
|
|
|
- 'HistoryRangesSupport',
|
|
|
- this.docId
|
|
|
- )
|
|
|
- })
|
|
|
})
|
|
|
|
|
|
describe('clearProjectState', function () {
|