Skip to content

Commit 13c0508

Browse files
committed
test(NODE-7203): migrate promote_buffers
1 parent 7857ec9 commit 13c0508

1 file changed

Lines changed: 72 additions & 164 deletions

File tree

Lines changed: 72 additions & 164 deletions
Original file line numberDiff line numberDiff line change
@@ -1,182 +1,90 @@
11
import { expect } from 'chai';
22

3-
import { assert as test, setupDatabase } from '../../shared';
3+
import { setupDatabase } from '../../shared';
44

55
describe('Promote Buffers', function () {
66
before(function () {
77
return setupDatabase(this.configuration);
88
});
99

10-
it('should correctly honor promoteBuffers when creating an instance using Db', {
11-
// Add a tag that our runner can trigger on
12-
// in this case we are setting that node needs to be higher than 0.10.X to run
13-
metadata: {
14-
requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] }
15-
},
16-
17-
test: function (done) {
18-
const configuration = this.configuration;
19-
const client = configuration.newClient(configuration.writeConcernMax(), {
20-
maxPoolSize: 1,
21-
promoteBuffers: true
22-
});
23-
24-
client.connect(function (err, client) {
25-
const db = client.db(configuration.db);
26-
db.collection('shouldCorrectlyHonorPromoteBuffer1').insert(
27-
{
28-
doc: Buffer.alloc(256)
29-
},
30-
function (err) {
31-
expect(err).to.not.exist;
32-
33-
db.collection('shouldCorrectlyHonorPromoteBuffer1').findOne(function (err, doc) {
34-
expect(err).to.not.exist;
35-
test.ok(doc.doc instanceof Buffer);
36-
37-
client.close(done);
38-
});
39-
}
40-
);
41-
});
42-
}
10+
it('should correctly honor promoteBuffers when creating an instance using Db', async function () {
11+
const configuration = this.configuration;
12+
const client = configuration.newClient(configuration.writeConcernMax(), {
13+
maxPoolSize: 1,
14+
promoteBuffers: true
15+
});
16+
17+
const db = client.db(configuration.db);
18+
await db.collection('shouldCorrectlyHonorPromoteBuffer1').insertOne({
19+
doc: Buffer.alloc(256)
20+
});
21+
22+
const doc = await db.collection('shouldCorrectlyHonorPromoteBuffer1').findOne();
23+
expect(doc.doc).to.be.instanceof(Buffer);
24+
await client.close();
4325
});
4426

45-
it('should correctly honor promoteBuffers when creating an instance using MongoClient', {
46-
// Add a tag that our runner can trigger on
47-
// in this case we are setting that node needs to be higher than 0.10.X to run
48-
metadata: {
49-
requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] }
50-
},
51-
52-
test: function (done) {
53-
const configuration = this.configuration;
54-
55-
const client = configuration.newClient({}, { promoteBuffers: true });
56-
client.connect(function (err, client) {
57-
const db = client.db(configuration.db);
58-
59-
db.collection('shouldCorrectlyHonorPromoteBuffer2').insert(
60-
{
61-
doc: Buffer.alloc(256)
62-
},
63-
function (err) {
64-
expect(err).to.not.exist;
65-
66-
db.collection('shouldCorrectlyHonorPromoteBuffer2').findOne(function (err, doc) {
67-
expect(err).to.not.exist;
68-
test.ok(doc.doc instanceof Buffer);
69-
70-
client.close(done);
71-
});
72-
}
73-
);
74-
});
75-
}
27+
it('should correctly honor promoteBuffers when creating an instance using MongoClient', async function () {
28+
const configuration = this.configuration;
29+
30+
const client = configuration.newClient({}, { promoteBuffers: true });
31+
const db = client.db(configuration.db);
32+
33+
await db.collection('shouldCorrectlyHonorPromoteBuffer2').insertOne({
34+
doc: Buffer.alloc(256)
35+
});
36+
37+
const doc = await db.collection('shouldCorrectlyHonorPromoteBuffer2').findOne();
38+
expect(doc.doc).to.be.instanceof(Buffer);
39+
await client.close();
7640
});
7741

78-
it('should correctly honor promoteBuffers at cursor level', {
79-
// Add a tag that our runner can trigger on
80-
// in this case we are setting that node needs to be higher than 0.10.X to run
81-
metadata: {
82-
requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] }
83-
},
84-
85-
test: function (done) {
86-
const configuration = this.configuration;
87-
88-
const client = configuration.newClient({}, { promoteBuffers: true });
89-
client.connect(function (err, client) {
90-
const db = client.db(configuration.db);
91-
92-
db.collection('shouldCorrectlyHonorPromoteBuffer3').insert(
93-
{
94-
doc: Buffer.alloc(256)
95-
},
96-
function (err) {
97-
expect(err).to.not.exist;
98-
99-
db.collection('shouldCorrectlyHonorPromoteBuffer3')
100-
.find()
101-
.next(function (err, doc) {
102-
expect(err).to.not.exist;
103-
test.ok(doc.doc instanceof Buffer);
104-
105-
client.close(done);
106-
});
107-
}
108-
);
109-
});
110-
}
42+
it('should correctly honor promoteBuffers at cursor level', async function () {
43+
const configuration = this.configuration;
44+
45+
const client = configuration.newClient({}, { promoteBuffers: true });
46+
const db = client.db(configuration.db);
47+
48+
await db.collection('shouldCorrectlyHonorPromoteBuffer3').insertOne({
49+
doc: Buffer.alloc(256)
50+
});
51+
52+
const doc = await db.collection('shouldCorrectlyHonorPromoteBuffer3').find().next();
53+
expect(doc.doc).to.be.instanceof(Buffer);
54+
await client.close();
11155
});
11256

113-
it('should correctly honor promoteBuffers at cursor find level', {
114-
// Add a tag that our runner can trigger on
115-
// in this case we are setting that node needs to be higher than 0.10.X to run
116-
metadata: {
117-
requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] }
118-
},
119-
120-
test: function (done) {
121-
const configuration = this.configuration;
122-
123-
const client = configuration.newClient();
124-
client.connect(function (err, client) {
125-
const db = client.db(configuration.db);
126-
db.collection('shouldCorrectlyHonorPromoteBuffer4').insert(
127-
{
128-
doc: Buffer.alloc(256)
129-
},
130-
function (err) {
131-
expect(err).to.not.exist;
132-
133-
db.collection('shouldCorrectlyHonorPromoteBuffer4')
134-
.find({}, { promoteBuffers: true })
135-
.next(function (err, doc) {
136-
expect(err).to.not.exist;
137-
test.ok(doc.doc instanceof Buffer);
138-
139-
client.close(done);
140-
});
141-
}
142-
);
143-
});
144-
}
57+
it('should correctly honor promoteBuffers at cursor find level', async function () {
58+
const configuration = this.configuration;
59+
60+
const client = configuration.newClient();
61+
const db = client.db(configuration.db);
62+
await db.collection('shouldCorrectlyHonorPromoteBuffer4').insertOne({
63+
doc: Buffer.alloc(256)
64+
});
65+
66+
const doc = await db
67+
.collection('shouldCorrectlyHonorPromoteBuffer4')
68+
.find({}, { promoteBuffers: true })
69+
.next();
70+
expect(doc.doc).to.be.instanceof(Buffer);
71+
await client.close();
14572
});
14673

147-
it('should correctly honor promoteBuffers at aggregate level', {
148-
// Add a tag that our runner can trigger on
149-
// in this case we are setting that node needs to be higher than 0.10.X to run
150-
metadata: {
151-
requires: {
152-
topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger']
153-
}
154-
},
155-
156-
test: function (done) {
157-
const configuration = this.configuration;
158-
159-
const client = configuration.newClient();
160-
client.connect(function (err, client) {
161-
const db = client.db(configuration.db);
162-
db.collection('shouldCorrectlyHonorPromoteBuffer5').insert(
163-
{
164-
doc: Buffer.alloc(256)
165-
},
166-
function (err) {
167-
expect(err).to.not.exist;
168-
169-
db.collection('shouldCorrectlyHonorPromoteBuffer5')
170-
.aggregate([{ $match: {} }], { promoteBuffers: true })
171-
.next(function (err, doc) {
172-
expect(err).to.not.exist;
173-
test.ok(doc.doc instanceof Buffer);
174-
175-
client.close(done);
176-
});
177-
}
178-
);
179-
});
180-
}
74+
it('should correctly honor promoteBuffers at aggregate level', async function () {
75+
const configuration = this.configuration;
76+
77+
const client = configuration.newClient();
78+
const db = client.db(configuration.db);
79+
await db.collection('shouldCorrectlyHonorPromoteBuffer5').insertOne({
80+
doc: Buffer.alloc(256)
81+
});
82+
83+
const doc = await db
84+
.collection('shouldCorrectlyHonorPromoteBuffer5')
85+
.aggregate([{ $match: {} }], { promoteBuffers: true })
86+
.next();
87+
expect(doc.doc).to.be.instanceof(Buffer);
88+
await client.close();
18189
});
18290
});

0 commit comments

Comments
 (0)