Skip to content

Commit

Permalink
POC
Browse files Browse the repository at this point in the history
  • Loading branch information
baileympearson committed Oct 29, 2024
1 parent 5c4355a commit 94a7090
Show file tree
Hide file tree
Showing 15 changed files with 1,132 additions and 250 deletions.
19 changes: 18 additions & 1 deletion src/cmap/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ export async function performInitialHandshake(
}

const start = new Date().getTime();
const response = await conn.command(ns('admin.$cmd'), handshakeDoc, handshakeOptions);

const response = await executeHandshake(handshakeDoc, handshakeOptions);

if (!('isWritablePrimary' in response)) {
// Provide hello-style response document.
Expand Down Expand Up @@ -175,6 +176,22 @@ export async function performInitialHandshake(
// Connection establishment is socket creation (tcp handshake, tls handshake, MongoDB handshake (saslStart, saslContinue))
// Once connection is established, command logging can log events (if enabled)
conn.established = true;

async function executeHandshake(handshakeDoc: Document, handshakeOptions: CommandOptions) {
try {
const handshakeResponse = await conn.command(
ns('admin.$cmd'),
handshakeDoc,
handshakeOptions
);
return handshakeResponse;
} catch (error) {
if (error instanceof MongoError) {
error.addErrorLabel(MongoErrorLabel.HandshakeError);
}
throw error;
}
}
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/cmap/connection_pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,7 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
},
error => {
this[kPending]--;
this[kServer].handleError(error);
this.emitAndLog(
ConnectionPool.CONNECTION_CLOSED,
new ConnectionClosedEvent(
Expand Down Expand Up @@ -715,9 +716,6 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
// connection permits because that potentially delays the availability of
// the connection to a checkout request
this.createConnection((err, connection) => {
if (err) {
this[kServer].handleError(err);
}
if (!err && connection) {
this[kConnections].push(connection);
process.nextTick(() => this.processWaitQueue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ describe('Connection Monitoring and Pooling Spec Tests (Integration) - logging',
) {
return 'not applicable: waitQueueSize not supported';
}
if (test.description === 'Connection checkout fails due to error establishing connection') {
return 'TODO(NODE-5230): unskip this once event ordering issue is resolved';
}
return false;
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { loadSpecTests } from '../../spec';
import { type CmapTest, runCmapTestSuite } from '../../tools/cmap_spec_runner';
import { runUnifiedSuite } from '../../tools/unified-spec-runner/runner';

describe('Connection Monitoring and Pooling (Node Driver)', function () {
const cmapTests: CmapTest[] = loadSpecTests(
Expand All @@ -17,10 +16,4 @@ describe('Connection Monitoring and Pooling (Node Driver)', function () {
}
]
});

// TODO(NODE-5230): Remove this once the actual unified tests (test/spec/connection-monitoring-and-pooling/logging) are passing
const unifiedTests = loadSpecTests(
'../integration/connection-monitoring-and-pooling/unified-cmap-node-specs'
);
runUnifiedSuite(unifiedTests);
});

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const skipTable: { pattern: string; reason: string }[] = [
}
];

describe('SDAM Unified Tests (Spec)', function () {
describe.only('SDAM Unified Tests (Spec)', function () {
const specTests = loadSpecTests(path.join('server-discovery-and-monitoring', 'unified'));
runUnifiedSuite(specTests, test => {
for (const { pattern, reason } of skipTable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@
"type": "ConnectionCreated",
"address": 42
},
{
"type": "ConnectionPoolCleared",
"address": 42
},
{
"type": "ConnectionClosed",
"address": 42,
"connectionId": 42,
"reason": "error"
},
{
"type": "ConnectionPoolCleared",
"address": 42
}
],
"ignore": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ events:
address: 42
- type: ConnectionCreated
address: 42
- type: ConnectionPoolCleared
address: 42
- type: ConnectionClosed
address: 42
connectionId: 42
reason: error
- type: ConnectionPoolCleared
address: 42
ignore:
- ConnectionPoolCreated
Loading

0 comments on commit 94a7090

Please sign in to comment.