From 22e554d6eff3c46787d6ceac3b54e091774a8498 Mon Sep 17 00:00:00 2001 From: Alec Gibson <12036746+alecgibson@users.noreply.github.com> Date: Wed, 22 May 2024 13:51:50 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20Add=20`OP=5FALREADY=5FSUBMITTED`=20?= =?UTF-8?q?test=20for=20create=20ops?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We have [logic][1] that tries to differentiate between: - a create op that is incorrectly trying to create a `Doc` that already exists - a create op that has already been committed, and has been resubmitted (possibly because the connection closed before the ack was received) The latter case is [not currently covered by tests][2]. This change adds a test to cover this branch, and a second similar test which explains why https://github.com/share/sharedb/pull/657 was not a viable change (and correctly fails for that case). [1]: https://github.com/share/sharedb/blob/7b20313ded4c302b9416cc6c7821694a7fa491b8/lib/submit-request.js#L105-L121 [2]: https://coveralls.io/builds/67552613/source?filename=lib%2Fsubmit-request.js#L117 --- test/client/submit.js | 49 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/test/client/submit.js b/test/client/submit.js index f02d7aaf2..88cef7864 100644 --- a/test/client/submit.js +++ b/test/client/submit.js @@ -246,6 +246,55 @@ module.exports = function() { }); }); + it('does not fail when resubmitting a create op', function(done) { + var backend = this.backend; + var connection = backend.connect(); + var submitted = false; + backend.use('submit', function(request, next) { + if (!submitted) { + submitted = true; + connection.close(); + backend.connect(connection); + } + next(); + }); + + var doc = connection.get('dogs', 'fido'); + doc.create({age: 3}, function(error) { + expect(doc.version).to.equal(1); + done(error); + }); + }); + + it('does not fail when resubmitting a create op on a doc that was deleted', function(done) { + var backend = this.backend; + var connection1 = backend.connect(); + var connection2 = backend.connect(); + var doc1 = connection1.get('dogs', 'fido'); + var doc2 = connection2.get('dogs', 'fido'); + + async.series([ + doc1.create.bind(doc1, {age: 3}), + doc1.del.bind(doc1), + function(next) { + var submitted = false; + backend.use('submit', function(request, next) { + if (!submitted) { + submitted = true; + connection2.close(); + backend.connect(connection2); + } + next(); + }); + + doc2.create({name: 'Fido'}, function(error) { + expect(doc2.version).to.equal(3); + next(error); + }); + } + ], done); + }); + it('server fetches and transforms by already committed op', function(done) { var doc = this.backend.connect().get('dogs', 'fido'); var doc2 = this.backend.connect().get('dogs', 'fido');