|
@@ -42,15 +42,15 @@ describe "Archiving updates", ->
|
|
|
sinon.spy MockDocStoreApi, "getAllDoc"
|
|
sinon.spy MockDocStoreApi, "getAllDoc"
|
|
|
|
|
|
|
|
@updates = []
|
|
@updates = []
|
|
|
- for i in [0..9]
|
|
|
|
|
|
|
+ for i in [0..1024+9]
|
|
|
@updates.push {
|
|
@updates.push {
|
|
|
op: [{ i: "a", p: 0 }]
|
|
op: [{ i: "a", p: 0 }]
|
|
|
- meta: { ts: @now - (9 - i) * @hours - 2 * @minutes, user_id: @user_id }
|
|
|
|
|
|
|
+ meta: { ts: @now - i * @hours, user_id: @user_id }
|
|
|
v: 2 * i + 1
|
|
v: 2 * i + 1
|
|
|
}
|
|
}
|
|
|
@updates.push {
|
|
@updates.push {
|
|
|
op: [{ i: "b", p: 0 }]
|
|
op: [{ i: "b", p: 0 }]
|
|
|
- meta: { ts: @now - (9 - i) * @hours, user_id: @user_id }
|
|
|
|
|
|
|
+ meta: { ts: @now - i * @hours + 10*@minutes, user_id: @user_id }
|
|
|
v: 2 * i + 2
|
|
v: 2 * i + 2
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -67,49 +67,53 @@ describe "Archiving updates", ->
|
|
|
|
|
|
|
|
describe "archiving a doc's updates", ->
|
|
describe "archiving a doc's updates", ->
|
|
|
before (done) ->
|
|
before (done) ->
|
|
|
- TrackChangesClient.archiveProject @project_id, (error) ->
|
|
|
|
|
|
|
+ TrackChangesClient.pushDocHistory @project_id, @doc_id, (error) ->
|
|
|
throw error if error?
|
|
throw error if error?
|
|
|
done()
|
|
done()
|
|
|
|
|
|
|
|
- it "should remain zero doc change", (done) ->
|
|
|
|
|
- db.docHistory.count { doc_id: ObjectId(@doc_id) }, (error, count) ->
|
|
|
|
|
|
|
+ it "should have one cached pack", (done) ->
|
|
|
|
|
+ db.docHistory.count { doc_id: ObjectId(@doc_id), expiresAt:{$exists:true}}, (error, count) ->
|
|
|
throw error if error?
|
|
throw error if error?
|
|
|
- count.should.equal 0
|
|
|
|
|
|
|
+ count.should.equal 1
|
|
|
done()
|
|
done()
|
|
|
|
|
|
|
|
- it "should have docHistoryStats marked as inS3", (done) ->
|
|
|
|
|
- db.docHistoryStats.findOne { doc_id: ObjectId(@doc_id) }, (error, doc) ->
|
|
|
|
|
|
|
+ it "should have one remaining pack after cache is expired", (done) ->
|
|
|
|
|
+ db.docHistory.remove {
|
|
|
|
|
+ doc_id: ObjectId(@doc_id),
|
|
|
|
|
+ expiresAt:{$exists:true}
|
|
|
|
|
+ }, (err, result) =>
|
|
|
throw error if error?
|
|
throw error if error?
|
|
|
- doc.inS3.should.equal true
|
|
|
|
|
- done()
|
|
|
|
|
|
|
+ db.docHistory.count { doc_id: ObjectId(@doc_id)}, (error, count) ->
|
|
|
|
|
+ throw error if error?
|
|
|
|
|
+ count.should.equal 1
|
|
|
|
|
+ done()
|
|
|
|
|
|
|
|
- it "should have docHistoryStats with the last version", (done) ->
|
|
|
|
|
- db.docHistoryStats.findOne { doc_id: ObjectId(@doc_id) }, (error, doc) ->
|
|
|
|
|
|
|
+ it "should have a docHistoryIndex entry marked as inS3", (done) ->
|
|
|
|
|
+ db.docHistoryIndex.findOne { _id: ObjectId(@doc_id) }, (error, index) ->
|
|
|
throw error if error?
|
|
throw error if error?
|
|
|
- doc.lastVersion.should.equal 20
|
|
|
|
|
|
|
+ index.packs[0].inS3.should.equal true
|
|
|
done()
|
|
done()
|
|
|
|
|
|
|
|
- it "should store twenty doc changes in S3 in one pack", (done) ->
|
|
|
|
|
- TrackChangesClient.getS3Doc @project_id, @doc_id, (error, res, doc) =>
|
|
|
|
|
- doc.length.should.equal 1
|
|
|
|
|
- doc[0].pack.length.should.equal 20
|
|
|
|
|
|
|
+ it "should have a docHistoryIndex entry with the last version", (done) ->
|
|
|
|
|
+ db.docHistoryIndex.findOne { _id: ObjectId(@doc_id) }, (error, index) ->
|
|
|
|
|
+ throw error if error?
|
|
|
|
|
+ index.packs[0].v_end.should.equal 100
|
|
|
done()
|
|
done()
|
|
|
|
|
|
|
|
|
|
+ # it "should store twenty doc changes in S3 in one pack", (done) ->
|
|
|
|
|
+ # TrackChangesClient.getS3Doc @project_id, @doc_id, (error, res, doc) =>
|
|
|
|
|
+ # doc.length.should.equal 1
|
|
|
|
|
+ # doc[0].pack.length.should.equal 20
|
|
|
|
|
+ # done()
|
|
|
|
|
+
|
|
|
describe "unarchiving a doc's updates", ->
|
|
describe "unarchiving a doc's updates", ->
|
|
|
before (done) ->
|
|
before (done) ->
|
|
|
- TrackChangesClient.unarchiveProject @project_id, (error) ->
|
|
|
|
|
|
|
+ TrackChangesClient.pullDocHistory @project_id, @doc_id, (error) ->
|
|
|
throw error if error?
|
|
throw error if error?
|
|
|
done()
|
|
done()
|
|
|
|
|
|
|
|
- it "should restore doc changes", (done) ->
|
|
|
|
|
|
|
+ it "should restore both packs", (done) ->
|
|
|
db.docHistory.count { doc_id: ObjectId(@doc_id) }, (error, count) ->
|
|
db.docHistory.count { doc_id: ObjectId(@doc_id) }, (error, count) ->
|
|
|
throw error if error?
|
|
throw error if error?
|
|
|
- count.should.equal 1
|
|
|
|
|
- done()
|
|
|
|
|
-
|
|
|
|
|
- it "should remove doc marked as inS3", (done) ->
|
|
|
|
|
- db.docHistoryStats.findOne {doc_id: ObjectId(@doc_id)}, (error, doc) ->
|
|
|
|
|
- throw error if error?
|
|
|
|
|
- doc.should.not.contain.key('inS3')
|
|
|
|
|
- doc.should.not.contain.key('lastVersion')
|
|
|
|
|
|
|
+ count.should.equal 2
|
|
|
done()
|
|
done()
|