Skip to content

Commit 22e554d

Browse files
committed
✅ Add OP_ALREADY_SUBMITTED test for create ops
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 #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
1 parent 7b20313 commit 22e554d

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

test/client/submit.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,55 @@ module.exports = function() {
246246
});
247247
});
248248

249+
it('does not fail when resubmitting a create op', function(done) {
250+
var backend = this.backend;
251+
var connection = backend.connect();
252+
var submitted = false;
253+
backend.use('submit', function(request, next) {
254+
if (!submitted) {
255+
submitted = true;
256+
connection.close();
257+
backend.connect(connection);
258+
}
259+
next();
260+
});
261+
262+
var doc = connection.get('dogs', 'fido');
263+
doc.create({age: 3}, function(error) {
264+
expect(doc.version).to.equal(1);
265+
done(error);
266+
});
267+
});
268+
269+
it('does not fail when resubmitting a create op on a doc that was deleted', function(done) {
270+
var backend = this.backend;
271+
var connection1 = backend.connect();
272+
var connection2 = backend.connect();
273+
var doc1 = connection1.get('dogs', 'fido');
274+
var doc2 = connection2.get('dogs', 'fido');
275+
276+
async.series([
277+
doc1.create.bind(doc1, {age: 3}),
278+
doc1.del.bind(doc1),
279+
function(next) {
280+
var submitted = false;
281+
backend.use('submit', function(request, next) {
282+
if (!submitted) {
283+
submitted = true;
284+
connection2.close();
285+
backend.connect(connection2);
286+
}
287+
next();
288+
});
289+
290+
doc2.create({name: 'Fido'}, function(error) {
291+
expect(doc2.version).to.equal(3);
292+
next(error);
293+
});
294+
}
295+
], done);
296+
});
297+
249298
it('server fetches and transforms by already committed op', function(done) {
250299
var doc = this.backend.connect().get('dogs', 'fido');
251300
var doc2 = this.backend.connect().get('dogs', 'fido');

0 commit comments

Comments
 (0)