Skip to content

Commit

Permalink
test(model): repro #9327
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Aug 26, 2020
1 parent 1e76f70 commit 1b416bb
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions test/model.test.js
Expand Up @@ -6900,6 +6900,50 @@ describe('Model', function() {
assert.equal(called, 0);
});

it('retains atomics after failed `save()` (gh-9327)', function() {
const schema = new Schema({ arr: [String] });
const Test = db.model('Test', schema);

return co(function*() {
const doc = yield Test.create({ arr: [] });

yield Test.deleteMany({});

doc.arr.push('test');
const err = yield doc.save().then(() => null, err => err);
assert.ok(err);

const delta = doc.getChanges();
assert.ok(delta.$push);
assert.ok(delta.$push.arr);
});
});

it('doesnt wipe out changes made while `save()` is in flight (gh-9327)', function() {
const schema = new Schema({ num1: Number, num2: Number });
const Test = db.model('Test', schema);

return co(function*() {
const doc = yield Test.create({});

doc.num1 = 1;
doc.num2 = 1;
const p = doc.save();

yield cb => setTimeout(cb, 0);

doc.num1 = 2;
doc.num2 = 2;
yield p;

yield doc.save();

const fromDb = yield Test.findById(doc._id);
assert.equal(fromDb.num1, 2);
assert.equal(fromDb.num2, 2);
});
});

describe('returnOriginal (gh-9183)', function() {
const originalValue = mongoose.get('returnOriginal');
beforeEach(() => {
Expand Down

0 comments on commit 1b416bb

Please sign in to comment.