-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(bulk): make sure that any error in bulk write is propagated
* fix(bulk): make sure that any error in bulk write is propagaged Previously, errors that were not the last returned during a bulk write would be swallowed. Now, we return them. Fixes NODE-1702 * updating test name * fixing typo
- Loading branch information
1 parent
78e4c02
commit bedc2d2
Showing
2 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
'use strict'; | ||
|
||
const expect = require('chai').expect; | ||
const mock = require('mongodb-mock-server'); | ||
|
||
describe('Bulk Writes', function() { | ||
const test = {}; | ||
|
||
let documents; | ||
before(() => { | ||
documents = new Array(20000).fill('').map(() => ({ | ||
arr: new Array(19).fill('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa') | ||
})); | ||
}); | ||
|
||
beforeEach(() => { | ||
return mock.createServer().then(server => { | ||
test.server = server; | ||
}); | ||
}); | ||
afterEach(() => mock.cleanup()); | ||
|
||
it('should propagate errors', function(done) { | ||
const client = this.configuration.newClient(`mongodb://${test.server.uri()}/test`); | ||
|
||
let close = e => { | ||
close = () => {}; | ||
client.close(() => done(e)); | ||
}; | ||
|
||
let hasErrored = false; | ||
|
||
test.server.setMessageHandler(request => { | ||
const doc = request.document; | ||
if (doc.ismaster) { | ||
request.reply(Object.assign({}, mock.DEFAULT_ISMASTER)); | ||
} else if (doc.endSessions) { | ||
request.reply({ ok: 1 }); | ||
} else if (doc.insert) { | ||
if (hasErrored) { | ||
return request.reply({ ok: 1 }); | ||
} | ||
hasErrored = true; | ||
return request.reply({ ok: 0 }); | ||
} else { | ||
close(`Received unknown command ${doc}`); | ||
} | ||
}); | ||
|
||
client.connect(function(err) { | ||
expect(err).to.be.null; | ||
|
||
const coll = client.db('foo').collection('bar'); | ||
|
||
coll.insert(documents, { ordered: false }, function(err) { | ||
try { | ||
expect(err).to.be.an.instanceOf(Error); | ||
done(); | ||
} catch (e) { | ||
done(e); | ||
} | ||
}); | ||
}); | ||
}); | ||
}); |