Skip to content

Commit 48a86c5

Browse files
committed
CSHARP-1816: Resync SDAM and SDAM monitoring tests from specs repo.
1 parent 4badd8d commit 48a86c5

File tree

43 files changed

+1379
-1153
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1379
-1153
lines changed

tests/MongoDB.Driver.Core.Tests.Dotnet/Specifications/server-discovery-and-monitoring/tests/README.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,39 @@ current TopologyDescription. It has the following keys:
8383
Use as unittests
8484
----------------
8585

86+
Mocking
87+
~~~~~~~
88+
8689
Drivers should be able to test their server discovery and monitoring logic
8790
without any network I/O, by parsing ismaster responses from the test file
8891
and passing them into the driver code. Parts of the client and monitoring
8992
code may need to be mocked or subclassed to achieve this. `A reference
9093
implementation for PyMongo 3.x is available here
9194
<https://github.com/mongodb/mongo-python-driver/blob/3.0-dev/test/test_discovery_and_monitoring.py>`_.
9295

96+
Initialization
97+
~~~~~~~~~~~~~~
98+
9399
For each file, create a fresh client object initialized with the file's "uri".
94100

101+
All files in the "single" directory include a connection string with one host
102+
and no "replicaSet" option.
103+
Set the client's initial TopologyType to Single, however that is achieved using the client's API.
104+
(The spec says "The user MUST be able to set the initial TopologyType to Single"
105+
without specifying how.)
106+
107+
All files in the "sharded" directory include a connection string with multiple hosts
108+
and no "replicaSet" option.
109+
Set the client's initial TopologyType to Unknown or Sharded, depending on the client's API.
110+
111+
All files in the "rs" directory include a connection string with a "replicaSet" option.
112+
Set the client's initial TopologyType to ReplicaSetNoPrimary.
113+
(For most clients, parsing a connection string with a "replicaSet" option
114+
automatically sets the TopologyType to ReplicaSetNoPrimary.)
115+
116+
Test Phases
117+
~~~~~~~~~~~
118+
95119
For each phase in the file, parse the "responses" array.
96120
Pass in the responses in order to the driver code.
97121
If a response is the empty object `{}`, simulate a network error.

tests/MongoDB.Driver.Core.Tests.Dotnet/Specifications/server-discovery-and-monitoring/tests/monitoring/replica_set_with_no_primary.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@
134134
"arbiters": [],
135135
"hosts": [],
136136
"passives": [],
137-
"type": "Unknown"
137+
"type": "PossiblePrimary"
138138
}
139139
]
140140
}

tests/MongoDB.Driver.Core.Tests.Dotnet/Specifications/server-discovery-and-monitoring/tests/monitoring/replica_set_with_no_primary.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,5 @@ phases:
108108
arbiters: []
109109
hosts: []
110110
passives: []
111-
type: "Unknown"
111+
type: "PossiblePrimary"
112112

tests/MongoDB.Driver.Core.Tests.Dotnet/Specifications/server-discovery-and-monitoring/tests/monitoring/replica_set_with_primary.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
"address": "a:27017",
122122
"arbiters": [],
123123
"hosts": [
124-
"a:27017"
124+
"a:27017", "b:27017"
125125
],
126126
"passives": [],
127127
"primary": "a:27017",

tests/MongoDB.Driver.Core.Tests.Dotnet/Specifications/server-discovery-and-monitoring/tests/monitoring/replica_set_with_primary.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ phases:
9797
arbiters: []
9898
hosts:
9999
- "a:27017"
100+
- "b:27017"
100101
passives: []
101102
primary: "a:27017"
102103
setName: "rs"
Original file line numberDiff line numberDiff line change
@@ -1,123 +1,123 @@
11
{
2-
"description": "New primary with greater setVersion",
2+
"description": "New primary with greater setVersion",
3+
"uri": "mongodb://a/?replicaSet=rs",
34
"phases": [
45
{
6+
"responses": [
7+
[
8+
"a:27017",
9+
{
10+
"ok": 1,
11+
"ismaster": true,
12+
"hosts": [
13+
"a:27017",
14+
"b:27017"
15+
],
16+
"setName": "rs",
17+
"setVersion": 1,
18+
"electionId": {
19+
"$oid": "000000000000000000000001"
20+
}
21+
}
22+
]
23+
],
524
"outcome": {
625
"servers": {
726
"a:27017": {
27+
"type": "RSPrimary",
28+
"setName": "rs",
29+
"setVersion": 1,
830
"electionId": {
931
"$oid": "000000000000000000000001"
10-
},
11-
"setName": "rs",
12-
"setVersion": 1,
13-
"type": "RSPrimary"
14-
},
32+
}
33+
},
1534
"b:27017": {
16-
"electionId": null,
17-
"setName": null,
18-
"type": "Unknown"
35+
"type": "Unknown",
36+
"setName": null,
37+
"electionId": null
1938
}
20-
},
21-
"setName": "rs",
22-
"topologyType": "ReplicaSetWithPrimary"
23-
},
39+
},
40+
"topologyType": "ReplicaSetWithPrimary",
41+
"setName": "rs"
42+
}
43+
},
44+
{
2445
"responses": [
2546
[
26-
"a:27017",
47+
"b:27017",
2748
{
28-
"electionId": {
29-
"$oid": "000000000000000000000001"
30-
},
49+
"ok": 1,
50+
"ismaster": true,
3151
"hosts": [
32-
"a:27017",
52+
"a:27017",
3353
"b:27017"
34-
],
35-
"ismaster": true,
36-
"ok": 1,
37-
"setName": "rs",
38-
"setVersion": 1
54+
],
55+
"setName": "rs",
56+
"setVersion": 2,
57+
"electionId": {
58+
"$oid": "000000000000000000000001"
59+
}
3960
}
4061
]
41-
]
42-
},
43-
{
62+
],
4463
"outcome": {
4564
"servers": {
4665
"a:27017": {
47-
"electionId": null,
48-
"setName": null,
49-
"type": "Unknown"
50-
},
66+
"type": "Unknown",
67+
"setName": null,
68+
"electionId": null
69+
},
5170
"b:27017": {
71+
"type": "RSPrimary",
72+
"setName": "rs",
73+
"setVersion": 2,
5274
"electionId": {
5375
"$oid": "000000000000000000000001"
54-
},
55-
"setName": "rs",
56-
"setVersion": 2,
57-
"type": "RSPrimary"
76+
}
5877
}
59-
},
60-
"setName": "rs",
61-
"topologyType": "ReplicaSetWithPrimary"
62-
},
78+
},
79+
"topologyType": "ReplicaSetWithPrimary",
80+
"setName": "rs"
81+
}
82+
},
83+
{
6384
"responses": [
6485
[
65-
"b:27017",
86+
"a:27017",
6687
{
67-
"electionId": {
68-
"$oid": "000000000000000000000001"
69-
},
88+
"ok": 1,
89+
"ismaster": true,
7090
"hosts": [
71-
"a:27017",
91+
"a:27017",
7292
"b:27017"
73-
],
74-
"ismaster": true,
75-
"ok": 1,
76-
"setName": "rs",
77-
"setVersion": 2
93+
],
94+
"setName": "rs",
95+
"setVersion": 1,
96+
"electionId": {
97+
"$oid": "000000000000000000000001"
98+
}
7899
}
79100
]
80-
]
81-
},
82-
{
101+
],
83102
"outcome": {
84103
"servers": {
85104
"a:27017": {
86-
"electionId": null,
87-
"setName": null,
88-
"type": "Unknown"
89-
},
105+
"type": "Unknown",
106+
"setName": null,
107+
"electionId": null
108+
},
90109
"b:27017": {
91-
"electionId": {
92-
"$oid": "000000000000000000000002"
93-
},
94-
"setName": "rs",
95-
"setVersion": 2,
96-
"type": "RSPrimary"
97-
}
98-
},
99-
"setName": "rs",
100-
"topologyType": "ReplicaSetWithPrimary"
101-
},
102-
"responses": [
103-
[
104-
"a:27017",
105-
{
110+
"type": "RSPrimary",
111+
"setName": "rs",
112+
"setVersion": 2,
106113
"electionId": {
107114
"$oid": "000000000000000000000001"
108-
},
109-
"hosts": [
110-
"a:27017",
111-
"b:27017"
112-
],
113-
"ismaster": true,
114-
"ok": 1,
115-
"setName": "rs",
116-
"setVersion": 1
115+
}
117116
}
118-
]
119-
]
117+
},
118+
"topologyType": "ReplicaSetWithPrimary",
119+
"setName": "rs"
120+
}
120121
}
121-
],
122-
"uri": "mongodb://a/?replicaSet=rs"
123-
}
122+
]
123+
}

tests/MongoDB.Driver.Core.Tests.Dotnet/Specifications/server-discovery-and-monitoring/tests/rs/new_primary_new_setversion.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ phases: [
9191
type: "RSPrimary",
9292
setName: "rs",
9393
setVersion: 2,
94-
electionId: {"$oid": "000000000000000000000002"}
94+
electionId: {"$oid": "000000000000000000000001"}
9595
}
9696
},
9797
topologyType: "ReplicaSetWithPrimary",

0 commit comments

Comments
 (0)