diff --git a/lib/submit-request.js b/lib/submit-request.js index 5c33fb9b1..2334f38a7 100644 --- a/lib/submit-request.js +++ b/lib/submit-request.js @@ -91,17 +91,21 @@ SubmitRequest.prototype.submit = function(callback) { // Send a special projection so that getSnapshot knows to return all fields. // With a null projection, it strips document metadata var fields = {$submit: true}; + console.log('submit', collection, id, op); var snapshotOptions = {}; snapshotOptions.agentCustom = request.agent.custom; backend.db.getSnapshot(collection, id, fields, snapshotOptions, function(err, snapshot) { if (err) return callback(err); + console.log('get snapshot', collection, id, snapshot); request.snapshot = snapshot; request._addSnapshotMeta(); if (op.v == null) { + console.log('null version'); if (op.create && snapshot.type && op.src) { + console.log('check create collision'); // If the document was already created by another op, we will return a // 'Document already exists' error in response and fail to submit this // op. However, this could also happen in the case that the op was @@ -110,7 +114,8 @@ SubmitRequest.prototype.submit = function(callback) { // must get the past ops and check their src and seq values to // differentiate. request._fetchCreateOpVersion(function(error, version) { - if (err) return callback(err); + console.log('fetch create op version returned', error, version); + if (error) return callback(error); if (version == null) { callback(request.alreadyCreatedError()); } else { @@ -301,6 +306,7 @@ SubmitRequest.prototype._shouldSaveMilestoneSnapshot = function(snapshot) { SubmitRequest.prototype._fetchCreateOpVersion = function(callback) { var create = this.snapshot.m._create; + console.log('got create meta', create); if (create) { var version = (create.src === this.op.src && create.seq === this.op.seq) ? create.v : null; return callback(null, version); @@ -310,6 +316,7 @@ SubmitRequest.prototype._fetchCreateOpVersion = function(callback) { // This can happen if a client tries to re-create or resubmit a create op to // a "legacy" snapshot that existed before we started adding the meta (should // be uncommon) or when using a driver that doesn't support metadata (eg Postgres). + console.log('get committed op version...'); this.backend.db.getCommittedOpVersion(this.collection, this.id, this.snapshot, this.op, null, callback); }; diff --git a/test/client/submit.js b/test/client/submit.js index c74058499..80262228e 100644 --- a/test/client/submit.js +++ b/test/client/submit.js @@ -6,7 +6,6 @@ var deserializedType = require('./deserialized-type'); var numberType = require('./number-type'); var errorHandler = require('../util').errorHandler; var richText = require('rich-text'); -var MemoryDB = require('../../lib/db/memory'); types.register(deserializedType.type); types.register(deserializedType.type2); types.register(numberType.type); @@ -215,8 +214,8 @@ module.exports = function() { describe('no snapshot metadata available', function() { beforeEach(function() { - var getSnapshot = MemoryDB.prototype.getSnapshot; - sinon.stub(MemoryDB.prototype, 'getSnapshot') + var getSnapshot = this.backend.db.getSnapshot; + sinon.stub(this.backend.db, 'getSnapshot') .callsFake(function() { var args = Array.from(arguments); var callback = args.pop(); @@ -297,6 +296,7 @@ module.exports = function() { }); it('does not fail when resubmitting a create op on a doc that was deleted', function(done) { + console.log('AKG'); var backend = this.backend; var connection1 = backend.connect(); var connection2 = backend.connect();