Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as fs from 'fs';
import * as path from 'path';
import { promisify } from 'util';

import { HostAddress, MongoClient } from '../../mongodb';
import { HostAddress, MongoClient, resolveSRVRecord } from '../../mongodb';

function makeTest(test, topology) {
let client;
Expand All @@ -17,25 +17,30 @@ function makeTest(test, topology) {
});

it(test.comment, async function () {
this.test.skipReason =
'TODO(NODE-3757): These tests require specific environment setups, also the error cases need better assertions';
return this.skip();
if (topology === 'replica-set' && this.configuration.topologyType !== 'ReplicaSetWithPrimary') {
return this.skip();
this.skip();
}

if (topology === 'sharded' && this.configuration.topologyType !== 'sharded') {
return this.skip();
if (topology === 'sharded' && this.configuration.topologyType !== 'Sharded') {
this.skip();
}

if (topology === 'load-balanced' && this.configuration.topologyType !== 'load-balanced') {
return this.skip();
if (topology === 'load-balanced' && this.configuration.topologyType !== 'LoadBalanced') {
this.skip();
}

let thrownError;
let resolvedSeeds: string[] | undefined;
try {
client = new MongoClient(test.uri, { serverSelectionTimeoutMS: 2000, tls: false });
await client.connect();
if (test.ping === false) {
// The spec forbids running a "ping" for these tests, and the resolved hosts may not be
// reachable, so only resolve (and validate) the SRV record without connecting.
const resolved = await resolveSRVRecord(client.options);
resolvedSeeds = resolved.map(h => h.toString());
} else {
await client.connect();
}
} catch (error) {
thrownError = error;
}
Expand All @@ -45,6 +50,14 @@ function makeTest(test, topology) {
return; // Nothing more to test...
}

if (test.ping === false) {
expect(thrownError).to.not.exist;
if (Array.isArray(test.seeds)) {
expect(resolvedSeeds).to.have.members(test.seeds);
}
return; // Nothing more to test, there is no topology to inspect
}

const options = client.options;
const hosts = Array.from(client.topology.s.description.servers.keys());

Expand Down Expand Up @@ -79,7 +92,7 @@ function makeTest(test, topology) {
// srvMaxHost limiting happens in the topology constructor
if (options.srvHost && test.comment.includes('srvMaxHosts')) {
const initialSeedlist = hosts.map(h => h.toString());
const selectedHosts = Array.from(topology.s.description.servers.keys());
const selectedHosts = Array.from<string>(client.topology.s.description.servers.keys());

if (typeof test.numSeeds === 'number') {
// numSeeds: the expected number of initial seeds discovered from the SRV record.
Expand Down
5 changes: 5 additions & 0 deletions test/spec/initial-dns-seedlist-discovery/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ _mongodb._tcp.test21.test.build.10gen.cc. 86400 IN SRV 27017 localhost.test
_customname._tcp.test22.test.build.10gen.cc 86400 IN SRV 27017 localhost.test.build.10gen.cc.
_mongodb._tcp.test23.test.build.10gen.cc. 86400 IN SRV 8000 localhost.test.build.10gen.cc.
_mongodb._tcp.test24.test.build.10gen.cc. 86400 IN SRV 8000 localhost.test.build.10gen.cc.
_mongodb._tcp.build.10gen.cc. 86400 IN SRV 27017 build.10gen.cc.
_mongodb._tcp.test.build.10gen.cc. 86400 IN SRV 27017 test.build.10gen.cc.

Record TTL Class Text
test5.test.build.10gen.cc. 86400 IN TXT "replicaSet=repl0&authSource=thisDB"
Expand All @@ -211,6 +213,9 @@ Notes:
- The missing `test.` sub-domain in the SRV record target for `test12` is deliberate.
- `test22` is used to test a custom service name (`customname`).
- `test23` and `test24` point to port 8000 (HAProxy) and are used for load-balanced tests.
- The `build.10gen.cc` and `test.build.10gen.cc` SRV records resolve to hostnames identical to the SRV hostname and are
used to verify that no error is thrown when the resolver and resolved hostnames are identical and the SRV hostname
has three or more `.` separated parts.

In our tests we have used `localhost.test.build.10gen.cc` as the domain, and then configured
`localhost.test.build.10gen.cc` to resolve to 127.0.0.1.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"uri": "mongodb+srv://test.build.10gen.cc/",
"seeds": [
"test.build.10gen.cc:27017"
],
"ping": false,
"comment": "Should not throw when SRV hostname and resolved hostname are identical and SRV hostname has four dot-separated parts."
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
uri: "mongodb+srv://test.build.10gen.cc/"
seeds:
- test.build.10gen.cc:27017
ping: false
comment: Should not throw when SRV hostname and resolved hostname are identical and SRV hostname has four dot-separated parts.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"uri": "mongodb+srv://build.10gen.cc/",
"seeds": [
"build.10gen.cc:27017"
],
"ping": false,
"comment": "Should not throw when SRV hostname and resolved hostname are identical and SRV hostname has three dot-separated parts."
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
uri: "mongodb+srv://build.10gen.cc/"
seeds:
- build.10gen.cc:27017
ping: false
comment: Should not throw when SRV hostname and resolved hostname are identical and SRV hostname has three dot-separated parts.
Loading