Skip to content

Commit c534ae9

Browse files
authored
SWIFT-1308 Run initial DNS seedlist discovery load balancer tests (#671)
1 parent 74a86f1 commit c534ae9

38 files changed

+106
-13
lines changed

Sources/TestsCommon/CommonTestUtils.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ open class MongoSwiftTestCase: XCTestCase {
5858
return try! ConnectionString(uri)
5959
case (.loadBalanced, false):
6060
guard let uri = Self.multipleMongosLoadBalancedURI else {
61-
fatalError("Missing MULTIPLE_MONGOS_LB_URI environment variable")
61+
fatalError("Missing MULTI_MONGOS_LB_URI environment variable")
6262
}
6363
return try! ConnectionString(uri)
6464
default:

Tests/LinuxMain.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ extension CrudTests {
9292

9393
extension DNSSeedlistTests {
9494
static var allTests = [
95-
("testInitialDNSSeedlistDiscovery", testInitialDNSSeedlistDiscovery),
95+
("testInitialDNSSeedlistDiscoveryReplicaSet", testInitialDNSSeedlistDiscoveryReplicaSet),
96+
("testInitialDNSSeedlistDiscoveryLoadBalanced", testInitialDNSSeedlistDiscoveryLoadBalanced),
9697
]
9798
}
9899

Tests/MongoSwiftTests/DNSSeedlistTests.swift

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,26 +46,46 @@ final class DNSSeedlistTests: MongoSwiftTestCase {
4646

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

5555
let tests = try retrieveSpecTestFiles(
5656
specName: "initial-dns-seedlist-discovery",
57+
subdirectory: "replica-set",
5758
asType: DNSSeedlistTestCase.self
5859
)
59-
for (fileName, testCase) in tests {
60-
// TODO: SWIFT-910: unskip this test
61-
guard fileName != "txt-record-with-overridden-uri-option.json" else {
62-
print("Skipping test file \(fileName); see SWIFT-910")
63-
continue
64-
}
6560

61+
try runDNSSeedlistTests(tests)
62+
}
63+
64+
func testInitialDNSSeedlistDiscoveryLoadBalanced() throws {
65+
guard MongoSwiftTestCase.topologyType == .loadBalanced else {
66+
print("Skipping test because of unsupported topology type \(MongoSwiftTestCase.topologyType)")
67+
return
68+
}
69+
70+
let tests = try retrieveSpecTestFiles(
71+
specName: "initial-dns-seedlist-discovery",
72+
subdirectory: "load-balanced",
73+
asType: DNSSeedlistTestCase.self
74+
)
75+
76+
try runDNSSeedlistTests(tests)
77+
}
78+
79+
func runDNSSeedlistTests(_ tests: [(String, DNSSeedlistTestCase)]) throws {
80+
for (fileName, testCase) in tests {
6681
// this particular test case requires SSL is disabled. see DRIVERS-1324.
6782
let requiresTLS = fileName != "txt-record-with-overridden-ssl-option.json"
6883

84+
// skipping due to a libmongoc bug. TODO: SWIFT-1343 unskip.
85+
guard fileName != "loadBalanced-replicaSet-errors.json" else {
86+
continue
87+
}
88+
6989
// TLS requirement for this test case is not met.
7090
guard (requiresTLS && MongoSwiftTestCase.ssl) || (!requiresTLS && !MongoSwiftTestCase.ssl) else {
7191
print("Skipping test file \(fileName); TLS requirement not met")

Tests/Specs/initial-dns-seedlist-discovery/tests/README.rst

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@ to prove their conformance to the Initial DNS Seedlist Discovery spec.
88
Test Setup
99
----------
1010

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

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

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

5462
Note that ``test4`` is omitted deliberately to test what happens with no SRV
5563
record. ``test9`` is missing because it was deleted during the development of
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"uri": "mongodb+srv://test20.test.build.10gen.cc/?directConnection=false",
3+
"seeds": [
4+
"localhost.test.build.10gen.cc:27017"
5+
],
6+
"hosts": [
7+
"localhost.test.build.10gen.cc:27017"
8+
],
9+
"options": {
10+
"loadBalanced": true,
11+
"ssl": true,
12+
"directConnection": false
13+
}
14+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"uri": "mongodb+srv://test4.test.build.10gen.cc/?loadBalanced=true",
3+
"seeds": [],
4+
"hosts": [],
5+
"error": true,
6+
"comment": "Should fail because no SRV records are present for this URI."
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"uri": "mongodb+srv://test20.test.build.10gen.cc/?replicaSet=replset",
3+
"seeds": [],
4+
"hosts": [],
5+
"error": true,
6+
"comment": "Should fail because loadBalanced=true is incompatible with replicaSet"
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"uri": "mongodb+srv://test1.test.build.10gen.cc/?loadBalanced=true",
3+
"seeds": [],
4+
"hosts": [],
5+
"error": true,
6+
"comment": "Should fail because loadBalanced is true but the SRV record resolves to multiple hosts"
7+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"uri": "mongodb+srv://test20.test.build.10gen.cc/",
3+
"seeds": [
4+
"localhost.test.build.10gen.cc:27017"
5+
],
6+
"hosts": [
7+
"localhost.test.build.10gen.cc:27017"
8+
],
9+
"options": {
10+
"loadBalanced": true,
11+
"ssl": true
12+
}
13+
}

Tests/Specs/initial-dns-seedlist-discovery/tests/direct-connection-false.json renamed to Tests/Specs/initial-dns-seedlist-discovery/tests/replica-set/direct-connection-false.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"localhost:27019"
1010
],
1111
"options": {
12-
"ssl": true
12+
"ssl": true,
13+
"directConnection": false
1314
}
1415
}

0 commit comments

Comments
 (0)