Skip to content

Commit 70c1333

Browse files
add prose test for handshake construction changes
1 parent 5c8a670 commit 70c1333

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

src/cmap/connect.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ export interface HandshakeDocument extends Document {
222222
compression: string[];
223223
saslSupportedMechs?: string;
224224
loadBalanced?: boolean;
225+
backpressure: true;
225226
}
226227

227228
/**
@@ -239,6 +240,7 @@ export async function prepareHandshakeDocument(
239240

240241
const handshakeDoc: HandshakeDocument = {
241242
[serverApi?.version || options.loadBalanced === true ? 'hello' : LEGACY_HELLO_COMMAND]: 1,
243+
backpressure: true,
242244
helloOk: true,
243245
client: clientMetadata,
244246
compression: compressors

test/integration/mongodb-handshake/mongodb-handshake.prose.test.ts

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import { expect } from 'chai';
22
import * as sinon from 'sinon';
33

4-
import { type ClientMetadata, type DriverInfo, Int32, MongoClient } from '../../../src';
4+
import {
5+
type ClientMetadata,
6+
type Document,
7+
type DriverInfo,
8+
type HandshakeDocument,
9+
Int32,
10+
MongoClient
11+
} from '../../../src';
512
import { Connection } from '../../../src/cmap/connection';
613
import { getFAASEnv, isDriverInfoEqual } from '../../../src/cmap/handshake/client_metadata';
714
import { LEGACY_HELLO_COMMAND } from '../../../src/constants';
@@ -939,3 +946,38 @@ describe('Client Metadata Update Prose Tests', function () {
939946
}
940947
});
941948
});
949+
950+
// TODO: add prose test descriptions here to align the test with the spec.
951+
describe.only('Backpressure Metadata', function () {
952+
let client: MongoClient;
953+
let spy: sinon.SinonSpy<Parameters<typeof Connection.prototype.command>>;
954+
955+
beforeEach(async function () {
956+
client = this.configuration.newClient();
957+
spy = sinon.spy(Connection.prototype, 'command');
958+
await client.connect();
959+
960+
// run an operation to force a connection establishment,
961+
// if we're testing noauth load balanced mode.
962+
await client.db('foo').collection('bar').insertOne({ name: 'bumpy' });
963+
});
964+
965+
afterEach(async function () {
966+
sinon.restore();
967+
await client?.close();
968+
});
969+
970+
it('includes backpressure in the handshake document', function () {
971+
const isHello = (cmd: Document): cmd is HandshakeDocument =>
972+
`hello` in cmd || LEGACY_HELLO_COMMAND in cmd;
973+
974+
const hellos = spy.args.map(([_ns, command, _options]) => command).filter(isHello);
975+
976+
expect(hellos.length).to.be.greaterThan(0);
977+
978+
expect(
979+
hellos.every(hello => hello.backpressure === true),
980+
`some handshake documents did not specify backpressure: true`
981+
);
982+
});
983+
});

0 commit comments

Comments
 (0)