Skip to content
Merged
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
2 changes: 1 addition & 1 deletion Sources/TestsCommon/CommonTestUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ open class MongoSwiftTestCase: XCTestCase {
return try! ConnectionString(uri)
case (.loadBalanced, false):
guard let uri = Self.multipleMongosLoadBalancedURI else {
fatalError("Missing MULTIPLE_MONGOS_LB_URI environment variable")
fatalError("Missing MULTI_MONGOS_LB_URI environment variable")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forgot to update this in previous PR changing the env var name

}
return try! ConnectionString(uri)
default:
Expand Down
3 changes: 2 additions & 1 deletion Tests/LinuxMain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ extension CrudTests {

extension DNSSeedlistTests {
static var allTests = [
("testInitialDNSSeedlistDiscovery", testInitialDNSSeedlistDiscovery),
("testInitialDNSSeedlistDiscoveryReplicaSet", testInitialDNSSeedlistDiscoveryReplicaSet),
("testInitialDNSSeedlistDiscoveryLoadBalanced", testInitialDNSSeedlistDiscoveryLoadBalanced),
]
}

Expand Down
34 changes: 27 additions & 7 deletions Tests/MongoSwiftTests/DNSSeedlistTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,46 @@ final class DNSSeedlistTests: MongoSwiftTestCase {

// Note: the file txt-record-with-overridden-uri-option.json causes a mongoc warning. This is expected.
// swiftlint:disable:next cyclomatic_complexity
func testInitialDNSSeedlistDiscovery() throws {
func testInitialDNSSeedlistDiscoveryReplicaSet() throws {
guard MongoSwiftTestCase.topologyType == .replicaSetWithPrimary else {
print("Skipping test because of unsupported topology type \(MongoSwiftTestCase.topologyType)")
return
}

let tests = try retrieveSpecTestFiles(
specName: "initial-dns-seedlist-discovery",
subdirectory: "replica-set",
asType: DNSSeedlistTestCase.self
)
for (fileName, testCase) in tests {
// TODO: SWIFT-910: unskip this test
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CDRIVER released their work for this ticket in 1.19 so we can close out ours now as well

guard fileName != "txt-record-with-overridden-uri-option.json" else {
print("Skipping test file \(fileName); see SWIFT-910")
continue
}

try runDNSSeedlistTests(tests)
}

func testInitialDNSSeedlistDiscoveryLoadBalanced() throws {
guard MongoSwiftTestCase.topologyType == .loadBalanced else {
print("Skipping test because of unsupported topology type \(MongoSwiftTestCase.topologyType)")
return
}

let tests = try retrieveSpecTestFiles(
specName: "initial-dns-seedlist-discovery",
subdirectory: "load-balanced",
asType: DNSSeedlistTestCase.self
)

try runDNSSeedlistTests(tests)
}

func runDNSSeedlistTests(_ tests: [(String, DNSSeedlistTestCase)]) throws {
for (fileName, testCase) in tests {
// this particular test case requires SSL is disabled. see DRIVERS-1324.
let requiresTLS = fileName != "txt-record-with-overridden-ssl-option.json"

// skipping due to a libmongoc bug. TODO: SWIFT-1343 unskip.
guard fileName != "loadBalanced-replicaSet-errors.json" else {
continue
}

// TLS requirement for this test case is not met.
guard (requiresTLS && MongoSwiftTestCase.ssl) || (!requiresTLS && !MongoSwiftTestCase.ssl) else {
print("Skipping test file \(fileName); TLS requirement not met")
Expand Down
14 changes: 11 additions & 3 deletions Tests/Specs/initial-dns-seedlist-discovery/tests/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ to prove their conformance to the Initial DNS Seedlist Discovery spec.
Test Setup
----------

Start a three-node replica set on localhost, on ports 27017, 27018, and 27019,
with replica set name "repl0". The replica set MUST be started with SSL
enabled.
The tests in the ``replica-set`` directory MUST be executed against a
three-node replica set on localhost ports 27017, 27018, and 27019 with
replica set name ``repl0``. The tests in ``load-balanced`` MUST be executed
against a load-balanced sharded cluster with the mongos servers running on
localhost ports 27017 and 27018 and load balancers, shard servers, and config
servers running on any open ports. In both cases, the clusters MUST be
started with SSL enabled.

To run the tests that accompany this spec, you need to configure the SRV and
TXT records with a real name server. The following records are required for
Expand Down Expand Up @@ -41,6 +45,8 @@ these tests::
_mongodb._tcp.test18.test.build.10gen.cc. 86400 IN SRV 27017 localhost.sub.test.build.10gen.cc.
_mongodb._tcp.test19.test.build.10gen.cc. 86400 IN SRV 27017 localhost.evil.build.10gen.cc.
_mongodb._tcp.test19.test.build.10gen.cc. 86400 IN SRV 27017 localhost.test.build.10gen.cc.
_mongodb._tcp.test20.test.build.10gen.cc. 86400 IN SRV 27017 localhost.test.build.10gen.cc.
_mongodb._tcp.test21.test.build.10gen.cc. 86400 IN SRV 27017 localhost.test.build.10gen.cc.

Record TTL Class Text
test5.test.build.10gen.cc. 86400 IN TXT "replicaSet=repl0&authSource=thisDB"
Expand All @@ -50,6 +56,8 @@ these tests::
test8.test.build.10gen.cc. 86400 IN TXT "authSource"
test10.test.build.10gen.cc. 86400 IN TXT "socketTimeoutMS=500"
test11.test.build.10gen.cc. 86400 IN TXT "replicaS" "et=rep" "l0"
test20.test.build.10gen.cc. 86400 IN TXT "loadBalanced=true"
test21.test.build.10gen.cc. 86400 IN TXT "loadBalanced=false"

Note that ``test4`` is omitted deliberately to test what happens with no SRV
record. ``test9`` is missing because it was deleted during the development of
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"uri": "mongodb+srv://test20.test.build.10gen.cc/?directConnection=false",
"seeds": [
"localhost.test.build.10gen.cc:27017"
],
"hosts": [
"localhost.test.build.10gen.cc:27017"
],
"options": {
"loadBalanced": true,
"ssl": true,
"directConnection": false
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"uri": "mongodb+srv://test4.test.build.10gen.cc/?loadBalanced=true",
"seeds": [],
"hosts": [],
"error": true,
"comment": "Should fail because no SRV records are present for this URI."
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"uri": "mongodb+srv://test20.test.build.10gen.cc/?replicaSet=replset",
"seeds": [],
"hosts": [],
"error": true,
"comment": "Should fail because loadBalanced=true is incompatible with replicaSet"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"uri": "mongodb+srv://test1.test.build.10gen.cc/?loadBalanced=true",
"seeds": [],
"hosts": [],
"error": true,
"comment": "Should fail because loadBalanced is true but the SRV record resolves to multiple hosts"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"uri": "mongodb+srv://test20.test.build.10gen.cc/",
"seeds": [
"localhost.test.build.10gen.cc:27017"
],
"hosts": [
"localhost.test.build.10gen.cc:27017"
],
"options": {
"loadBalanced": true,
"ssl": true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"localhost:27019"
],
"options": {
"ssl": true
"ssl": true,
"directConnection": false
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"uri": "mongodb+srv://test21.test.build.10gen.cc/",
"seeds": [
"localhost.test.build.10gen.cc:27017"
],
"hosts": [
"localhost:27017",
"localhost:27018",
"localhost:27019"
],
"options": {
"loadBalanced": false,
"ssl": true
}
}