Update logger, metrics, and redis

Also fix acceptance tests, broken by a change in the redis driver
behaviour. It now returns promises from most operations, which confuses mocha.
This commit is contained in:
Shane Kilkelly
2019-06-19 10:25:54 +01:00
parent e8dd1aae9c
commit 080b482e51
10 changed files with 288 additions and 193 deletions
@@ -38,6 +38,7 @@ describe "Applying updates to a doc", ->
DocUpdaterClient.sendUpdate @project_id, @doc_id, @update, (error) ->
throw error if error?
setTimeout done, 200
return null
after ->
MockWebApi.getDocument.restore()
@@ -51,6 +52,7 @@ describe "Applying updates to a doc", ->
DocUpdaterClient.getDoc @project_id, @doc_id, (error, res, doc) =>
doc.lines.should.deep.equal @result
done()
return null
it "should push the applied updates to the track changes api", (done) ->
rclient_history.lrange HistoryKeys.uncompressedHistoryOps({@doc_id}), 0, -1, (error, updates) =>
@@ -60,12 +62,14 @@ describe "Applying updates to a doc", ->
throw error if error?
result.should.equal 1
done()
return null
it "should push the applied updates to the project history changes api", (done) ->
rclient_history.lrange ProjectHistoryKeys.projectHistoryOps({@project_id}), 0, -1, (error, updates) =>
throw error if error?
JSON.parse(updates[0]).op.should.deep.equal @update.op
done()
return null
it "should set the first op timestamp", (done) ->
rclient_history.get ProjectHistoryKeys.projectHistoryFirstOpTimestamp({@project_id}), (error, result) =>
@@ -73,6 +77,7 @@ describe "Applying updates to a doc", ->
result.should.be.within(@startTime, Date.now())
@firstOpTimestamp = result
done()
return null
describe "when sending another update", ->
before (done) ->
@@ -81,12 +86,14 @@ describe "Applying updates to a doc", ->
DocUpdaterClient.sendUpdate @project_id, @doc_id, @second_update, (error) ->
throw error if error?
setTimeout done, 200
return null
it "should not change the first op timestamp", (done) ->
rclient_history.get ProjectHistoryKeys.projectHistoryFirstOpTimestamp({@project_id}), (error, result) =>
throw error if error?
result.should.equal @firstOpTimestamp
done()
return null
describe "when the document is loaded", ->
before (done) ->
@@ -99,6 +106,7 @@ describe "Applying updates to a doc", ->
DocUpdaterClient.sendUpdate @project_id, @doc_id, @update, (error) ->
throw error if error?
setTimeout done, 200
return null
after ->
MockWebApi.getDocument.restore()
@@ -110,6 +118,7 @@ describe "Applying updates to a doc", ->
DocUpdaterClient.getDoc @project_id, @doc_id, (error, res, doc) =>
doc.lines.should.deep.equal @result
done()
return null
it "should push the applied updates to the track changes api", (done) ->
rclient_history.lrange HistoryKeys.uncompressedHistoryOps({@doc_id}), 0, -1, (error, updates) =>
@@ -117,11 +126,13 @@ describe "Applying updates to a doc", ->
rclient_history.sismember HistoryKeys.docsWithHistoryOps({@project_id}), @doc_id, (error, result) =>
result.should.equal 1
done()
return null
it "should push the applied updates to the project history changes api", (done) ->
rclient_history.lrange ProjectHistoryKeys.projectHistoryOps({@project_id}), 0, -1, (error, updates) =>
JSON.parse(updates[0]).op.should.deep.equal @update.op
done()
return null
describe "when the document has been deleted", ->
@@ -161,6 +172,7 @@ describe "Applying updates to a doc", ->
DocUpdaterClient.getDoc @project_id, @doc_id, (error, res, doc) =>
doc.lines.should.deep.equal @my_result
done()
return null
it "should push the applied updates to the track changes api", (done) ->
rclient_history.lrange HistoryKeys.uncompressedHistoryOps({@doc_id}), 0, -1, (error, updates) =>
@@ -171,6 +183,7 @@ describe "Applying updates to a doc", ->
rclient_history.sismember HistoryKeys.docsWithHistoryOps({@project_id}), @doc_id, (error, result) =>
result.should.equal 1
done()
return null
it "should store the doc ops in the correct order", (done) ->
rclient_du.lrange Keys.docOps({doc_id: @doc_id}), 0, -1, (error, updates) =>
@@ -178,6 +191,7 @@ describe "Applying updates to a doc", ->
for appliedUpdate, i in @updates
appliedUpdate.op.should.deep.equal updates[i].op
done()
return null
describe "when older ops come in after the delete", ->
before (done) ->
@@ -210,6 +224,7 @@ describe "Applying updates to a doc", ->
DocUpdaterClient.getDoc @project_id, @doc_id, (error, res, doc) =>
doc.lines.should.deep.equal @my_result
done()
return null
describe "with a broken update", ->
before (done) ->
@@ -222,11 +237,13 @@ describe "Applying updates to a doc", ->
DocUpdaterClient.sendUpdate @project_id, @doc_id, @broken_update, (error) ->
throw error if error?
setTimeout done, 200
return null
it "should not update the doc", (done) ->
DocUpdaterClient.getDoc @project_id, @doc_id, (error, res, doc) =>
doc.lines.should.deep.equal @lines
done()
return null
it "should send a message with an error", ->
@messageCallback.called.should.equal true
@@ -261,6 +278,7 @@ describe "Applying updates to a doc", ->
async.series actions, (error) =>
throw error if error?
setTimeout done, 2000
return null
after ->
MockTrackChangesApi.flushDoc.restore()
@@ -282,11 +300,13 @@ describe "Applying updates to a doc", ->
DocUpdaterClient.sendUpdate @project_id, @doc_id, update, (error) ->
throw error if error?
setTimeout done, 200
return null
it "should update the doc (using version = 0)", (done) ->
DocUpdaterClient.getDoc @project_id, @doc_id, (error, res, doc) =>
doc.lines.should.deep.equal @result
done()
return null
describe "when the sending duplicate ops", ->
before (done) ->
@@ -322,11 +342,13 @@ describe "Applying updates to a doc", ->
throw error if error?
setTimeout done, 200
, 200
return null
it "should update the doc", (done) ->
DocUpdaterClient.getDoc @project_id, @doc_id, (error, res, doc) =>
doc.lines.should.deep.equal @result
done()
return null
it "should return a message about duplicate ops", ->
@messageCallback.calledTwice.should.equal true
@@ -42,6 +42,7 @@ describe "Applying updates to a project's structure", ->
update.version.should.equal "#{@version}.0"
done()
return null
describe "renaming a document", ->
before ->
@@ -57,6 +58,7 @@ describe "Applying updates to a project's structure", ->
DocUpdaterClient.sendProjectUpdate @project_id, @user_id, @docUpdates, [], @version, (error) ->
throw error if error?
setTimeout done, 200
return null
it "should push the applied doc renames to the project history api", (done) ->
rclient_history.lrange ProjectHistoryKeys.projectHistoryOps({@project_id}), 0, -1, (error, updates) =>
@@ -71,6 +73,7 @@ describe "Applying updates to a project's structure", ->
update.version.should.equal "#{@version}.0"
done()
return null
describe "when the document is loaded", ->
before (done) ->
@@ -82,6 +85,7 @@ describe "Applying updates to a project's structure", ->
DocUpdaterClient.sendProjectUpdate @project_id, @user_id, @docUpdates, [], @version, (error) ->
throw error if error?
setTimeout done, 200
return null
after ->
MockWebApi.getDocument.restore()
@@ -90,6 +94,7 @@ describe "Applying updates to a project's structure", ->
DocUpdaterClient.getDoc @project_id, @docUpdate.id, (error, res, doc) =>
doc.pathname.should.equal @docUpdate.newPathname
done()
return null
it "should push the applied doc renames to the project history api", (done) ->
rclient_history.lrange ProjectHistoryKeys.projectHistoryOps({@project_id}), 0, -1, (error, updates) =>
@@ -104,6 +109,7 @@ describe "Applying updates to a project's structure", ->
update.version.should.equal "#{@version}.0"
done()
return null
describe "renaming multiple documents and files", ->
before ->
@@ -132,6 +138,7 @@ describe "Applying updates to a project's structure", ->
DocUpdaterClient.sendProjectUpdate @project_id, @user_id, @docUpdates, @fileUpdates, @version, (error) ->
throw error if error?
setTimeout done, 200
return null
it "should push the applied doc renames to the project history api", (done) ->
rclient_history.lrange ProjectHistoryKeys.projectHistoryOps({@project_id}), 0, -1, (error, updates) =>
@@ -170,6 +177,7 @@ describe "Applying updates to a project's structure", ->
update.version.should.equal "#{@version}.3"
done()
return null
describe "adding a file", ->
@@ -183,6 +191,7 @@ describe "Applying updates to a project's structure", ->
DocUpdaterClient.sendProjectUpdate @project_id, @user_id, [], @fileUpdates, @version, (error) ->
throw error if error?
setTimeout done, 200
return null
it "should push the file addition to the project history api", (done) ->
rclient_history.lrange ProjectHistoryKeys.projectHistoryOps({@project_id}), 0, -1, (error, updates) =>
@@ -197,6 +206,7 @@ describe "Applying updates to a project's structure", ->
update.version.should.equal "#{@version}.0"
done()
return null
describe "adding a doc", ->
before (done) ->
@@ -209,6 +219,7 @@ describe "Applying updates to a project's structure", ->
DocUpdaterClient.sendProjectUpdate @project_id, @user_id, @docUpdates, [], @version, (error) ->
throw error if error?
setTimeout done, 200
return null
it "should push the doc addition to the project history api", (done) ->
rclient_history.lrange ProjectHistoryKeys.projectHistoryOps({@project_id}), 0, -1, (error, updates) =>
@@ -223,6 +234,7 @@ describe "Applying updates to a project's structure", ->
update.version.should.equal "#{@version}.0"
done()
return null
describe "with enough updates to flush to the history service", ->
before (done) ->
@@ -247,6 +259,7 @@ describe "Applying updates to a project's structure", ->
DocUpdaterClient.sendProjectUpdate projectId, userId, updates.slice(250), [], @version1, (error) ->
throw error if error?
setTimeout done, 2000
return null
after ->
MockProjectHistoryApi.flushProject.restore()
@@ -278,6 +291,7 @@ describe "Applying updates to a project's structure", ->
DocUpdaterClient.sendProjectUpdate projectId, userId, updates.slice(10), [], @version1, (error) ->
throw error if error?
setTimeout done, 2000
return null
after ->
MockProjectHistoryApi.flushProject.restore()
@@ -51,6 +51,7 @@ describe "Setting a document", ->
@statusCode = res.statusCode
done()
, 200
return null
it "should return a 204 status code", ->
@statusCode.should.equal 204
@@ -64,17 +65,20 @@ describe "Setting a document", ->
DocUpdaterClient.getDoc @project_id, @doc_id, (error, res, doc) =>
doc.lines.should.deep.equal @newLines
done()
return null
it "should bump the version in the doc updater", (done) ->
DocUpdaterClient.getDoc @project_id, @doc_id, (error, res, doc) =>
doc.version.should.equal @version + 2
done()
return null
it "should leave the document in redis", (done) ->
rclient_du.get Keys.docLines({doc_id: @doc_id}), (error, lines) =>
throw error if error?
expect(JSON.parse(lines)).to.deep.equal @newLines
done()
return null
describe "when the updated doc does not exist in the doc updater", ->
before (done) ->
@@ -83,6 +87,7 @@ describe "Setting a document", ->
DocUpdaterClient.setDocLines @project_id, @doc_id, @newLines, @source, @user_id, false, (error, res, body) =>
@statusCode = res.statusCode
setTimeout done, 200
return null
it "should return a 204 status code", ->
@statusCode.should.equal 204
@@ -103,6 +108,7 @@ describe "Setting a document", ->
throw error if error?
expect(lines).to.not.exist
done()
return null
describe "with track changes", ->
before ->
@@ -131,6 +137,7 @@ describe "Setting a document", ->
DocUpdaterClient.setDocLines @project_id, @doc_id, @lines, @source, @user_id, true, (error, res, body) =>
@statusCode = res.statusCode
setTimeout done, 200
return null
it "should undo the tracked changes", (done) ->
DocUpdaterClient.getDoc @project_id, @doc_id, (error, res, data) =>
@@ -138,6 +145,7 @@ describe "Setting a document", ->
ranges = data.ranges
expect(ranges.changes).to.be.undefined
done()
return null
describe "without the undo flag", ->
before (done) ->
@@ -151,6 +159,7 @@ describe "Setting a document", ->
DocUpdaterClient.setDocLines @project_id, @doc_id, @lines, @source, @user_id, false, (error, res, body) =>
@statusCode = res.statusCode
setTimeout done, 200
return null
it "should not undo the tracked changes", (done) ->
DocUpdaterClient.getDoc @project_id, @doc_id, (error, res, data) =>
@@ -158,5 +167,6 @@ describe "Setting a document", ->
ranges = data.ranges
expect(ranges.changes.length).to.equal 1
done()
return null