Skip to content

Commit 725f195

Browse files
committed
test(NODE-7203): migrate promote_values
1 parent 13c0508 commit 725f195

1 file changed

Lines changed: 153 additions & 190 deletions

File tree

Lines changed: 153 additions & 190 deletions
Original file line numberDiff line numberDiff line change
@@ -1,209 +1,172 @@
11
import { expect } from 'chai';
22

3-
import { Double, Int32, Long } from '../../../mongodb';
3+
import { Double, Int32, Long } from '../../../../src';
44
import { assert as test, setupDatabase } from '../../shared';
55

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

11-
it('should correctly honor promoteValues when creating an instance using Db', {
12-
// Add a tag that our runner can trigger on
13-
// in this case we are setting that node needs to be higher than 0.10.X to run
14-
metadata: {
15-
requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] }
16-
},
17-
18-
test: async function () {
19-
const configuration = this.configuration;
20-
const client = configuration.newClient(configuration.writeConcernMax(), {
21-
maxPoolSize: 1,
22-
promoteValues: false
23-
});
24-
await client.connect();
25-
const db = client.db(configuration.db);
26-
27-
await db.collection('shouldCorrectlyHonorPromoteValues').insertOne({
28-
doc: Long.fromNumber(10),
29-
int: 10,
30-
double: 2.2222,
31-
array: [[Long.fromNumber(10)]]
32-
});
33-
const doc = await db.collection('shouldCorrectlyHonorPromoteValues').findOne();
34-
expect(Long.fromNumber(10)).deep.equals(doc.doc);
35-
expect(new Int32(10)).deep.equals(doc.int);
36-
expect(new Double(2.2222)).deep.equals(doc.double);
37-
38-
await client.close();
39-
}
40-
});
41-
42-
it('should correctly honor promoteValues when creating an instance using MongoClient', {
43-
// Add a tag that our runner can trigger on
44-
// in this case we are setting that node needs to be higher than 0.10.X to run
45-
metadata: {
46-
requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] }
47-
},
48-
49-
test: async function () {
50-
const configuration = this.configuration;
51-
const client = configuration.newClient({}, { promoteValues: false });
52-
await client.connect();
53-
const db = client.db(configuration.db);
54-
55-
await db.collection('shouldCorrectlyHonorPromoteValues').insertOne({
56-
doc: Long.fromNumber(10),
57-
int: 10,
58-
double: 2.2222,
59-
array: [[Long.fromNumber(10)]]
60-
});
61-
62-
const doc = await db.collection('shouldCorrectlyHonorPromoteValues').findOne();
63-
expect(Long.fromNumber(10)).deep.equals(doc.doc);
64-
expect(new Int32(10)).deep.equals(doc.int);
65-
expect(new Double(2.2222)).deep.equals(doc.double);
66-
67-
await client.close();
68-
}
11+
it('should correctly honor promoteValues when creating an instance using Db', async function () {
12+
const configuration = this.configuration;
13+
const client = configuration.newClient(configuration.writeConcernMax(), {
14+
maxPoolSize: 1,
15+
promoteValues: false
16+
});
17+
await client.connect();
18+
const db = client.db(configuration.db);
19+
20+
await db.collection('shouldCorrectlyHonorPromoteValues').insertOne({
21+
doc: Long.fromNumber(10),
22+
int: 10,
23+
double: 2.2222,
24+
array: [[Long.fromNumber(10)]]
25+
});
26+
const doc = await db.collection('shouldCorrectlyHonorPromoteValues').findOne();
27+
expect(Long.fromNumber(10)).deep.equals(doc.doc);
28+
expect(new Int32(10)).deep.equals(doc.int);
29+
expect(new Double(2.2222)).deep.equals(doc.double);
30+
31+
await client.close();
6932
});
7033

71-
it('should correctly honor promoteValues at cursor level', {
72-
// Add a tag that our runner can trigger on
73-
// in this case we are setting that node needs to be higher than 0.10.X to run
74-
metadata: {
75-
requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] }
76-
},
77-
78-
test: async function () {
79-
const configuration = this.configuration;
80-
const client = configuration.newClient({}, { promoteValues: false });
81-
await client.connect();
82-
const db = client.db(configuration.db);
83-
await db.collection('shouldCorrectlyHonorPromoteValues').insertOne({
84-
doc: Long.fromNumber(10),
85-
int: 10,
86-
double: 2.2222,
87-
array: [[Long.fromNumber(10)]]
88-
});
89-
90-
const doc = await db.collection('shouldCorrectlyHonorPromoteValues').find().next();
91-
expect(doc.doc).to.deep.equal(Long.fromNumber(10));
92-
expect(doc.int).to.deep.equal(new Int32(10));
93-
expect(doc.double).to.deep.equal(new Double(2.2222));
94-
95-
await client.close();
96-
}
34+
// TODO(NODE-7192): remove as it duplicates "should correctly honor promoteValues when creating an instance using Db"
35+
// it('should correctly honor promoteValues when creating an instance using MongoClient', {
36+
// // Add a tag that our runner can trigger on
37+
// // in this case we are setting that node needs to be higher than 0.10.X to run
38+
// metadata: {
39+
// requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] }
40+
// },
41+
//
42+
// test: async function () {
43+
// const configuration = this.configuration;
44+
// const client = configuration.newClient({}, { promoteValues: false });
45+
// await client.connect();
46+
// const db = client.db(configuration.db);
47+
//
48+
// await db.collection('shouldCorrectlyHonorPromoteValues').insertOne({
49+
// doc: Long.fromNumber(10),
50+
// int: 10,
51+
// double: 2.2222,
52+
// array: [[Long.fromNumber(10)]]
53+
// });
54+
//
55+
// const doc = await db.collection('shouldCorrectlyHonorPromoteValues').findOne();
56+
// expect(Long.fromNumber(10)).deep.equals(doc.doc);
57+
// expect(new Int32(10)).deep.equals(doc.int);
58+
// expect(new Double(2.2222)).deep.equals(doc.double);
59+
//
60+
// await client.close();
61+
// }
62+
// });
63+
64+
// TODO(NODE-7192): remove as it duplicates "should correctly honor promoteValues when creating an instance using Db"
65+
// it('should correctly honor promoteValues at cursor level', {
66+
// // Add a tag that our runner can trigger on
67+
// // in this case we are setting that node needs to be higher than 0.10.X to run
68+
// metadata: {
69+
// requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] }
70+
// },
71+
//
72+
// test: async function () {
73+
// const configuration = this.configuration;
74+
// const client = configuration.newClient({}, { promoteValues: false });
75+
// await client.connect();
76+
// const db = client.db(configuration.db);
77+
// await db.collection('shouldCorrectlyHonorPromoteValues').insertOne({
78+
// doc: Long.fromNumber(10),
79+
// int: 10,
80+
// double: 2.2222,
81+
// array: [[Long.fromNumber(10)]]
82+
// });
83+
//
84+
// const doc = await db.collection('shouldCorrectlyHonorPromoteValues').find().next();
85+
// expect(doc.doc).to.deep.equal(Long.fromNumber(10));
86+
// expect(doc.int).to.deep.equal(new Int32(10));
87+
// expect(doc.double).to.deep.equal(new Double(2.2222));
88+
//
89+
// await client.close();
90+
// }
91+
// });
92+
93+
it('should correctly honor promoteValues at cursor find level', async function () {
94+
const configuration = this.configuration;
95+
const client = configuration.newClient();
96+
await client.connect();
97+
const db = client.db(configuration.db);
98+
99+
await db.collection('shouldCorrectlyHonorPromoteValues').insertOne({
100+
doc: Long.fromNumber(10),
101+
int: 10,
102+
double: 2.2222,
103+
array: [[Long.fromNumber(10)]]
104+
});
105+
106+
const doc = await db
107+
.collection('shouldCorrectlyHonorPromoteValues')
108+
.find({}, { promoteValues: false })
109+
.next();
110+
expect(doc.doc).to.deep.equal(Long.fromNumber(10));
111+
expect(doc.int).to.deep.equal(new Int32(10));
112+
expect(doc.double).to.deep.equal(new Double(2.2222));
113+
114+
await client.close();
97115
});
98116

99-
it('should correctly honor promoteValues at cursor find level', {
100-
// Add a tag that our runner can trigger on
101-
// in this case we are setting that node needs to be higher than 0.10.X to run
102-
metadata: {
103-
requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] }
104-
},
105-
106-
test: async function () {
107-
const configuration = this.configuration;
108-
const client = configuration.newClient();
109-
await client.connect();
110-
const db = client.db(configuration.db);
111-
112-
await db.collection('shouldCorrectlyHonorPromoteValues').insertOne({
113-
doc: Long.fromNumber(10),
114-
int: 10,
115-
double: 2.2222,
116-
array: [[Long.fromNumber(10)]]
117-
});
118-
119-
const doc = await db
120-
.collection('shouldCorrectlyHonorPromoteValues')
121-
.find({}, { promoteValues: false })
122-
.next();
123-
expect(doc.doc).to.deep.equal(Long.fromNumber(10));
124-
expect(doc.int).to.deep.equal(new Int32(10));
125-
expect(doc.double).to.deep.equal(new Double(2.2222));
126-
127-
await client.close();
128-
}
117+
it('should correctly honor promoteValues at aggregate level', async function () {
118+
const configuration = this.configuration;
119+
const client = configuration.newClient();
120+
await client.connect();
121+
const db = client.db(configuration.db);
122+
await db.collection('shouldCorrectlyHonorPromoteValues2').insertOne({
123+
doc: Long.fromNumber(10),
124+
int: 10,
125+
double: 2.2222,
126+
array: [[Long.fromNumber(10)]]
127+
});
128+
const doc = await db
129+
.collection('shouldCorrectlyHonorPromoteValues2')
130+
.aggregate([{ $match: {} }], { promoteValues: false })
131+
.next();
132+
expect(doc.doc).to.deep.equal(Long.fromNumber(10));
133+
expect(doc.int).to.deep.equal(new Int32(10));
134+
expect(doc.double).to.deep.equal(new Double(2.2222));
135+
136+
await client.close();
129137
});
130138

131-
it('should correctly honor promoteValues at aggregate level', {
132-
// Add a tag that our runner can trigger on
133-
// in this case we are setting that node needs to be higher than 0.10.X to run
134-
metadata: {
135-
requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] }
136-
},
137-
138-
test: async function () {
139-
const configuration = this.configuration;
140-
const client = configuration.newClient();
141-
await client.connect();
142-
const db = client.db(configuration.db);
143-
await db.collection('shouldCorrectlyHonorPromoteValues2').insertOne({
144-
doc: Long.fromNumber(10),
145-
int: 10,
146-
double: 2.2222,
147-
array: [[Long.fromNumber(10)]]
148-
});
149-
const doc = await db
150-
.collection('shouldCorrectlyHonorPromoteValues2')
151-
.aggregate([{ $match: {} }], { promoteValues: false })
152-
.next();
153-
expect(doc.doc, Long.fromNumber(10));
154-
expect(doc.int, new Int32(10));
155-
expect(doc.double, new Double(2.2222));
156-
157-
await client.close();
139+
it('Should correctly promoteValues when calling getMore on queries', async function () {
140+
const configuration = this.configuration;
141+
const client = configuration.newClient();
142+
const docs = new Array(150).fill(0).map(function (_, i) {
143+
return {
144+
_id: 'needle_' + i,
145+
is_even: i % 2,
146+
long: Long.fromString('1234567890'),
147+
double: 0.23456,
148+
int: 1234
149+
};
150+
});
151+
152+
const db = client.db(configuration.db);
153+
154+
await db.collection<{ _id: string }>('haystack').insertMany(docs);
155+
156+
const stream = db
157+
.collection('haystack')
158+
.find({}, { limit: 102, promoteValues: false })
159+
.stream();
160+
161+
for await (const doc of stream) {
162+
test.equal(typeof doc.int, 'object');
163+
test.equal(doc.int._bsontype, 'Int32');
164+
test.equal(typeof doc.long, 'object');
165+
test.equal(doc.long._bsontype, 'Long');
166+
test.equal(typeof doc.double, 'object');
167+
test.equal(doc.double._bsontype, 'Double');
158168
}
159-
});
160169

161-
it('Should correctly promoteValues when calling getMore on queries', {
162-
metadata: {
163-
requires: {
164-
topology: ['single', 'ssl', 'wiredtiger']
165-
}
166-
},
167-
168-
test: function (done) {
169-
const configuration = this.configuration;
170-
const client = configuration.newClient();
171-
client.connect(function (err, client) {
172-
const docs = new Array(150).fill(0).map(function (_, i) {
173-
return {
174-
_id: 'needle_' + i,
175-
is_even: i % 2,
176-
long: Long.fromString('1234567890'),
177-
double: 0.23456,
178-
int: 1234
179-
};
180-
});
181-
182-
const db = client.db(configuration.db);
183-
184-
db.collection('haystack').insertMany(docs, function (errInsert) {
185-
if (errInsert) throw errInsert;
186-
// change limit from 102 to 101 and this test passes.
187-
// seems to indicate that the promoteValues flag is used for the
188-
// initial find, but not for subsequent getMores
189-
db.collection('haystack')
190-
.find({}, { limit: 102, promoteValues: false })
191-
.stream()
192-
.on('data', function (doc) {
193-
test.equal(typeof doc.int, 'object');
194-
test.equal(doc.int._bsontype, 'Int32');
195-
test.equal(typeof doc.long, 'object');
196-
test.equal(doc.long._bsontype, 'Long');
197-
test.equal(typeof doc.double, 'object');
198-
test.equal(doc.double._bsontype, 'Double');
199-
})
200-
.on('end', function () {
201-
db.dropCollection('haystack', function () {
202-
client.close(done);
203-
});
204-
});
205-
});
206-
});
207-
}
170+
await client.close();
208171
});
209172
});

0 commit comments

Comments
 (0)