Skip to content
This repository was archived by the owner on Feb 4, 2022. It is now read-only.

Commit ef58dc4

Browse files
daprahamianmbroadst
authored andcommitted
test(OP_MSG): adding tests for checking moreToCome flag
1 parent d379edc commit ef58dc4

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

lib/connection/msg.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ const opcodes = require('../wireprotocol/shared').opcodes;
3232
// Incrementing request id
3333
let _requestId = 0;
3434

35-
// Msg Flags
36-
const OPTS_CHECKSUM_PRESENT = 1;
37-
const OPTS_MORE_TO_COME = 2;
38-
const OPTS_EXHAUST_ALLOWED = 1 >> 16;
39-
4035
class Msg {
4136
constructor(bson, query, options) {
4237
// Basic options needed to be passed in
@@ -71,15 +66,15 @@ class Msg {
7166
let flags = 0;
7267

7368
if (this.checksumPresent) {
74-
flags |= OPTS_CHECKSUM_PRESENT;
69+
flags |= Msg.flags.CHECKSUM_PRESENT;
7570
}
7671

7772
if (this.moreToCome) {
78-
flags |= OPTS_MORE_TO_COME;
73+
flags |= Msg.flags.MORE_TO_COME;
7974
}
8075

8176
if (this.exhaustAllowed) {
82-
flags |= OPTS_EXHAUST_ALLOWED;
77+
flags |= Msg.flags.EXHAUST_ALLOWED;
8378
}
8479

8580
const header = new Buffer(
@@ -169,6 +164,12 @@ Msg.getRequestId = function() {
169164
return ++_requestId;
170165
};
171166

167+
Msg.flags = {
168+
CHECKSUM_PRESENT: 1,
169+
MORE_TO_COME: 2,
170+
EXHAUST_ALLOWED: 1 << 16
171+
};
172+
172173
function writeInt32ListToUint8Buffer(buffer, int32List, start) {
173174
let index = start || 0;
174175

test/tests/unit/wireprotocol/3_6/msg_test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,5 +156,13 @@ describe('OP_MSG', function() {
156156
});
157157
});
158158

159+
it('should properly reflect getMore flag in BSON', function() {
160+
const msg = new Msg(bson, {}, { moreToCome: true });
161+
const buffers = msg.toBin();
162+
const parsedMessage = parseOpMsg(buffers);
163+
164+
expect(parsedMessage).to.have.property('flags', Msg.flags.MORE_TO_COME);
165+
});
166+
159167
it.skip('should properly serialize multiple commands');
160168
});

0 commit comments

Comments
 (0)