Skip to content

Commit 8f6c860

Browse files
pr requested changes again
1 parent 1181991 commit 8f6c860

File tree

3 files changed

+91
-94
lines changed

3 files changed

+91
-94
lines changed

src/cmap/connect.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ async function performInitialHandshake(
187187
}
188188
}
189189

190-
// Connection establishment is socket creatio (tcp handshake, tls handshake, MongoDB handshake (saslStart, saslContinue))
191-
// Once connection is established, command logging and monitoring can emit and/or log events (if either are enabled)
190+
// Connection establishment is socket creation (tcp handshake, tls handshake, MongoDB handshake (saslStart, saslContinue))
191+
// Once connection is established, command logging can log events (if enabled)
192192
conn.established = true;
193193
}
194194

src/cmap/connection.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,14 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
168168
public delayedTimeoutId: NodeJS.Timeout | null = null;
169169
public generation: number;
170170
public readonly description: Readonly<StreamDescription>;
171+
/**
172+
* @public
173+
* Represents if the connection has been established:
174+
* - TCP handshake
175+
* - TLS negotiated
176+
* - mongodb handshake (saslStart, saslContinue), includes authentication
177+
* Once connection is established, command logging can log events (if enabled)
178+
*/
171179
public established: boolean;
172180

173181
private lastUseTime: number;

test/integration/command-logging-and-monitoring/command_logging_and_monitoring.prose.test.ts

Lines changed: 81 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,30 @@ import { expect } from 'chai';
22

33
import { DEFAULT_MAX_DOCUMENT_LENGTH, type Document } from '../../mongodb';
44

5-
describe.only('Command Logging and Monitoring Prose Tests', function () {
5+
describe('Command Logging and Monitoring Prose Tests', function () {
66
const loggerFeatureFlag = Symbol.for('@@mdb.enableMongoLogger');
77
const ELLIPSES_LENGTH = 3;
88
let client;
99
let writable;
1010

1111
context('When no custom truncation limit is provided', function () {
1212
/*
13-
1. Configure logging with a minimum severity level of "debug" for the "command" component.
13+
1. Configure logging with a minimum severity level of "debug" for the "command" component.
1414
Do not explicitly configure the max document length.
1515
1616
2. Construct an array docs containing the document {"x" : "y"} repeated 100 times.
1717
1818
3. Insert docs to a collection via insertMany.
1919
20-
4. Inspect the resulting "command started" log message and assert that
20+
4. Inspect the resulting "command started" log message and assert that
2121
the "command" value is a string of length 1000 + (length of trailing ellipsis).
2222
23-
5. Inspect the resulting "command succeeded" log message and assert that
23+
5. Inspect the resulting "command succeeded" log message and assert that
2424
the "reply" value is a string of length <= 1000 + (length of trailing ellipsis).
2525
2626
6. Run find() on the collection where the document was inserted.
2727
28-
7. Inspect the resulting "command succeeded" log message and assert that
28+
7. Inspect the resulting "command succeeded" log message and assert that
2929
the reply is a string of length 1000 + (length of trailing ellipsis).
3030
*/
3131

@@ -53,67 +53,64 @@ describe.only('Command Logging and Monitoring Prose Tests', function () {
5353
await client.close();
5454
});
5555

56-
it('should follow default truncation limit of 1000', {
57-
metadata: {},
58-
test: async function () {
59-
// 2.
60-
const docs: Array<Document> = [];
61-
for (let i = 0; i < 100; i++) {
62-
docs.push({ x: 'y' });
63-
}
64-
65-
// 3.
66-
await client.db('admin').collection('test').insertMany(docs);
67-
68-
// 4.
69-
const insertManyCommandStarted = writable.buffer[0];
70-
expect(insertManyCommandStarted?.message).to.equal('Command started');
71-
expect(insertManyCommandStarted?.command).to.be.a('string');
72-
expect(insertManyCommandStarted?.command?.length).to.equal(
73-
DEFAULT_MAX_DOCUMENT_LENGTH + ELLIPSES_LENGTH
74-
);
75-
76-
// 5.
77-
const insertManyCommandSucceeded = writable.buffer[1];
78-
expect(insertManyCommandSucceeded?.message).to.equal('Command succeeded');
79-
expect(insertManyCommandSucceeded?.reply).to.be.a('string');
80-
expect(insertManyCommandSucceeded?.reply?.length).to.be.at.most(
81-
DEFAULT_MAX_DOCUMENT_LENGTH + ELLIPSES_LENGTH
82-
);
83-
84-
// 6.
85-
await client.db('admin').collection('test').find().toArray();
86-
87-
// 7.
88-
const findCommandSucceeded = writable.buffer[3];
89-
expect(findCommandSucceeded?.message).to.equal('Command succeeded');
90-
expect(findCommandSucceeded?.reply).to.be.a('string');
91-
expect(findCommandSucceeded?.reply?.length).to.equal(
92-
DEFAULT_MAX_DOCUMENT_LENGTH + ELLIPSES_LENGTH
93-
);
56+
it('should follow default truncation limit of 1000', async function () {
57+
// 2.
58+
const docs: Array<Document> = [];
59+
for (let i = 0; i < 100; i++) {
60+
docs.push({ x: 'y' });
9461
}
62+
63+
// 3.
64+
await client.db('admin').collection('test').insertMany(docs);
65+
66+
// 4.
67+
const insertManyCommandStarted = writable.buffer[0];
68+
expect(insertManyCommandStarted?.message).to.equal('Command started');
69+
expect(insertManyCommandStarted?.command).to.be.a('string');
70+
expect(insertManyCommandStarted?.command?.length).to.equal(
71+
DEFAULT_MAX_DOCUMENT_LENGTH + ELLIPSES_LENGTH
72+
);
73+
74+
// 5.
75+
const insertManyCommandSucceeded = writable.buffer[1];
76+
expect(insertManyCommandSucceeded?.message).to.equal('Command succeeded');
77+
expect(insertManyCommandSucceeded?.reply).to.be.a('string');
78+
expect(insertManyCommandSucceeded?.reply?.length).to.be.at.most(
79+
DEFAULT_MAX_DOCUMENT_LENGTH + ELLIPSES_LENGTH
80+
);
81+
82+
// 6.
83+
await client.db('admin').collection('test').find().toArray();
84+
85+
// 7.
86+
const findCommandSucceeded = writable.buffer[3];
87+
expect(findCommandSucceeded?.message).to.equal('Command succeeded');
88+
expect(findCommandSucceeded?.reply).to.be.a('string');
89+
expect(findCommandSucceeded?.reply?.length).to.equal(
90+
DEFAULT_MAX_DOCUMENT_LENGTH + ELLIPSES_LENGTH
91+
);
9592
});
9693
});
9794

9895
context('When custom truncation limit is provided', function () {
9996
/*
100-
1. Configure logging with a minimum severity level of "debug" for the "command" component.
97+
1. Configure logging with a minimum severity level of "debug" for the "command" component.
10198
Set the max document length to 5.
10299
103100
2. Run the command {"hello": true}.
104101
105-
3. Inspect the resulting "command started" log message and assert that
102+
3. Inspect the resulting "command started" log message and assert that
106103
the "command" value is a string of length 5 + (length of trailing ellipsis).
107104
108105
4. Inspect the resulting "command succeeded" log message and assert that
109106
the "reply" value is a string of length 5 + (length of trailing ellipsis).
110-
107+
111108
5. (Optional)
112109
If the driver attaches raw server responses to failures
113-
and can access these via log messages to assert on,
114-
run the command {"notARealCommand": true}.
110+
and can access these via log messages to assert on,
111+
run the command {"notARealCommand": true}.
115112
116-
Inspect the resulting "command failed" log message
113+
Inspect the resulting "command failed" log message
117114
and confirm that the server error is a string of length 5 + (length of trailing ellipsis).
118115
*/
119116
beforeEach(async function () {
@@ -141,38 +138,33 @@ describe.only('Command Logging and Monitoring Prose Tests', function () {
141138
await client.close();
142139
});
143140

144-
it('should follow custom truncation limit', {
145-
metadata: {},
146-
test: async function () {
147-
// 2.
148-
await client.db('admin').command({ hello: 'true' });
149-
150-
// 3.
151-
const insertManyCommandStarted = writable.buffer[0];
152-
expect(insertManyCommandStarted?.message).to.equal('Command started');
153-
expect(insertManyCommandStarted?.command).to.be.a('string');
154-
expect(insertManyCommandStarted?.command?.length).to.equal(5 + ELLIPSES_LENGTH);
155-
156-
// 4.
157-
const insertManyCommandSucceeded = writable.buffer[1];
158-
expect(insertManyCommandSucceeded?.message).to.equal('Command succeeded');
159-
expect(insertManyCommandSucceeded?.reply).to.be.a('string');
160-
expect(insertManyCommandSucceeded?.reply?.length).to.be.at.most(5 + ELLIPSES_LENGTH);
161-
162-
await client.close();
163-
}
141+
it('should follow custom truncation limit', async function () {
142+
// 2.
143+
await client.db('admin').command({ hello: 'true' });
144+
145+
// 3.
146+
const insertManyCommandStarted = writable.buffer[0];
147+
expect(insertManyCommandStarted?.message).to.equal('Command started');
148+
expect(insertManyCommandStarted?.command).to.be.a('string');
149+
expect(insertManyCommandStarted?.command?.length).to.equal(5 + ELLIPSES_LENGTH);
150+
151+
// 4.
152+
const insertManyCommandSucceeded = writable.buffer[1];
153+
expect(insertManyCommandSucceeded?.message).to.equal('Command succeeded');
154+
expect(insertManyCommandSucceeded?.reply).to.be.a('string');
155+
expect(insertManyCommandSucceeded?.reply?.length).to.be.at.most(5 + ELLIPSES_LENGTH);
164156
});
165157
});
166158

167159
context('Truncation with multi-byte codepoints', function () {
168160
/*
169161
A specific test case is not provided here due to the allowed variations in truncation logic
170-
as well as varying extended JSON whitespace usage.
171-
Drivers MUST write language-specific tests that confirm truncation of commands, replies,
172-
and (if applicable) server responses included in error messages
162+
as well as varying extended JSON whitespace usage.
163+
Drivers MUST write language-specific tests that confirm truncation of commands, replies,
164+
and (if applicable) server responses included in error messages
173165
work as expected when the data being truncated includes multi-byte Unicode codepoints.
174-
175-
If the driver uses anything other than Unicode codepoints as the unit for max document length,
166+
167+
If the driver uses anything other than Unicode codepoints as the unit for max document length,
176168
there also MUST be tests confirming that cases
177169
where the max length falls in the middle of a multi-byte codepoint are handled gracefully.
178170
*/
@@ -202,27 +194,24 @@ describe.only('Command Logging and Monitoring Prose Tests', function () {
202194
await client.close();
203195
});
204196

205-
it('should handle unicode codepoints in middle and end of truncation gracefully', {
206-
metadata: {},
207-
test: async function () {
208-
const docs: Array<Document> = [
209-
{
210-
x: '\u2603\u2603\u2603\u2603'
211-
}
212-
];
197+
it('should handle unicode codepoints in middle and end of truncation gracefully', async function () {
198+
const docs: Array<Document> = [
199+
{
200+
x: '\u2603\u2603\u2603\u2603'
201+
}
202+
];
213203

214-
await client.db('admin').collection('test').insertMany(docs);
204+
await client.db('admin').collection('test').insertMany(docs);
215205

216-
const insertManyCommandStarted = writable.buffer[0];
217-
expect(insertManyCommandStarted?.message).to.equal('Command started');
218-
expect(insertManyCommandStarted?.command).to.be.a('string');
219-
expect(insertManyCommandStarted?.command?.length).to.equal(50 + ELLIPSES_LENGTH);
206+
const insertManyCommandStarted = writable.buffer[0];
207+
expect(insertManyCommandStarted?.message).to.equal('Command started');
208+
expect(insertManyCommandStarted?.command).to.be.a('string');
209+
expect(insertManyCommandStarted?.command?.length).to.equal(50 + ELLIPSES_LENGTH);
220210

221-
const insertManyCommandSucceeded = writable.buffer[1];
222-
expect(insertManyCommandSucceeded?.message).to.equal('Command succeeded');
223-
expect(insertManyCommandSucceeded?.reply).to.be.a('string');
224-
expect(insertManyCommandSucceeded?.reply?.length).to.be.at.most(50 + ELLIPSES_LENGTH);
225-
}
211+
const insertManyCommandSucceeded = writable.buffer[1];
212+
expect(insertManyCommandSucceeded?.message).to.equal('Command succeeded');
213+
expect(insertManyCommandSucceeded?.reply).to.be.a('string');
214+
expect(insertManyCommandSucceeded?.reply?.length).to.be.at.most(50 + ELLIPSES_LENGTH);
226215
});
227216
});
228217
});

0 commit comments

Comments
 (0)