Add assertions for the results of CHANGESET_REQ

fails nearly all the time :/
The assertions are most likely not broken, so I think the code is.

Conflicts:
	src/node/handler/PadMessageHandler.js
test/changeset_req-assertions
Marcel Klehr 2013-12-30 17:42:47 +01:00
parent 1e0456c7ed
commit c03c6beb73
1 changed files with 43 additions and 0 deletions

View File

@ -1256,6 +1256,49 @@ function handleChangesetRequest(client, message)
getChangesetInfo(padIds.padId, start, end, granularity, function(err, changesetInfo)
{
if(err) return console.error('Error while handling a changeset request for '+padIds.padId, err, message.data);
// Assert that the paths are correct
var assert = require('assert')
padManager.getPad(message.padId, function(err, pad) {
if(err) return
var headRev = pad.getHeadRevisionNumber()
, fend = start-(granularity*changesetInfo.forwardsChangesets.length)
, bend = start+(granularity*changesetInfo.backwardsChangesets.length)
if(start > headRev || fend > headRev || bend > headRev) return console.log('Cannot vet from ', start, 'to', end)
pad.getInternalRevisionAText(start, function(err, atextStart) {
ERR(err)
pad.getInternalRevisionAText(fend, function(err, atextFend) {
ERR(err)
pad.getInternalRevisionAText(bend, function(err, atextBend) {
ERR(err)
console.log(changesetInfo)
// check forward
console.log('Vetting revision path from ', fend, 'to', start)
var atext = atextFend
changesetInfo.forwardsChangesets.forEach(function(cs) {
atext = Changeset.applyToAText(cs, atext)
})
assert(atext.text == atextStart.text)
assert(atext.attribs == atextStart.attribs)
console.log('OK')
// check backward /*/
console.log('Vetting revision path from ', bend, 'to', start)
atext = atextBend
changesetInfo.backwardsChangesets.forEach(function(cs) {
atext = Changeset.applyToAText(cs, atext)
})
assert(atext.text == atextStart.text)
assert(atext.attribs == atextStart.attribs)
console.log('OK')
})
})
})
})
var data = changesetInfo;
data.requestID = message.data.requestID;