Skip to content

Commit 00d3f2a

Browse files
authored
HELP-21340: Adding Tests For Max BSON Size Batching (#2693)
test: Adding tests for max byte size batching
1 parent 62717a1 commit 00d3f2a

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

test/functional/bulk.test.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ const {
99
const test = require('./shared').assert;
1010
const { MongoError } = require('../../src/error');
1111
const { Long } = require('../../src');
12+
const crypto = require('crypto');
1213
const chai = require('chai');
1314
const expect = chai.expect;
1415
chai.use(require('chai-subset'));
1516

17+
const MAX_BSON_SIZE = 16777216;
18+
1619
describe('Bulk', function () {
1720
before(function () {
1821
return setupDatabase(this.configuration);
@@ -1627,6 +1630,54 @@ describe('Bulk', function () {
16271630
});
16281631
});
16291632

1633+
it('properly accounts for bson size in bytes in bulk ordered inserts', function () {
1634+
const client = this.configuration.newClient();
1635+
const size = MAX_BSON_SIZE / 2;
1636+
const largeString = crypto.randomBytes(size - 100).toString('hex');
1637+
const documents = [{ s: largeString }, { s: largeString }];
1638+
1639+
let db;
1640+
1641+
return client
1642+
.connect()
1643+
.then(() => {
1644+
db = client.db(this.configuration.db);
1645+
return db.dropCollection('doesnt_matter').catch(() => {});
1646+
})
1647+
.then(() => {
1648+
return db.createCollection('doesnt_matter');
1649+
})
1650+
.then(() => {
1651+
const coll = db.collection('doesnt_matter');
1652+
coll.insertMany(documents, { ordered: true });
1653+
})
1654+
.finally(() => client.close());
1655+
});
1656+
1657+
it('properly accounts for bson size in bytes in bulk unordered inserts', function () {
1658+
const client = this.configuration.newClient();
1659+
const size = MAX_BSON_SIZE / 2;
1660+
const largeString = crypto.randomBytes(size - 100).toString('hex');
1661+
const documents = [{ s: largeString }, { s: largeString }];
1662+
1663+
let db;
1664+
1665+
return client
1666+
.connect()
1667+
.then(() => {
1668+
db = client.db(this.configuration.db);
1669+
return db.dropCollection('doesnt_matter').catch(() => {});
1670+
})
1671+
.then(() => {
1672+
return db.createCollection('doesnt_matter');
1673+
})
1674+
.then(() => {
1675+
const coll = db.collection('doesnt_matter');
1676+
coll.insertMany(documents, { ordered: false });
1677+
})
1678+
.finally(() => client.close());
1679+
});
1680+
16301681
function testPropagationOfBulkWriteError(bulk) {
16311682
return bulk.execute().then(
16321683
err => {

0 commit comments

Comments
 (0)