|
1 | 1 | import { expect } from 'chai'; |
2 | 2 | import * as sinon from 'sinon'; |
3 | 3 |
|
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'; |
5 | 12 | import { Connection } from '../../../src/cmap/connection'; |
6 | 13 | import { getFAASEnv, isDriverInfoEqual } from '../../../src/cmap/handshake/client_metadata'; |
7 | 14 | import { LEGACY_HELLO_COMMAND } from '../../../src/constants'; |
@@ -939,3 +946,38 @@ describe('Client Metadata Update Prose Tests', function () { |
939 | 946 | } |
940 | 947 | }); |
941 | 948 | }); |
| 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