Skip to content

Commit 13e2715

Browse files
authored
PYTHON-3312 Convert SDAM integration tests to unified (#1028)
1 parent 5b85ad2 commit 13e2715

File tree

46 files changed

+4881
-3010
lines changed

Some content is hidden

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

46 files changed

+4881
-3010
lines changed

.evergreen/resync-specs.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ do
132132
discovery_and_monitoring/sharded
133133
cpjson server-discovery-and-monitoring/tests/single \
134134
discovery_and_monitoring/single
135-
cpjson server-discovery-and-monitoring/tests/integration \
136-
discovery_and_monitoring_integration
135+
cpjson server-discovery-and-monitoring/tests/unified \
136+
discovery_and_monitoring/unified
137137
cpjson server-discovery-and-monitoring/tests/load-balanced \
138138
discovery_and_monitoring/load-balanced
139139
;;

pymongo/monitoring.py

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -914,13 +914,12 @@ class ConnectionCheckOutFailedReason(object):
914914

915915

916916
class _ConnectionEvent(object):
917-
"""Private base class for some connection events."""
917+
"""Private base class for connection events."""
918918

919-
__slots__ = ("__address", "__connection_id")
919+
__slots__ = ("__address",)
920920

921-
def __init__(self, address: _Address, connection_id: int) -> None:
921+
def __init__(self, address: _Address) -> None:
922922
self.__address = address
923-
self.__connection_id = connection_id
924923

925924
@property
926925
def address(self) -> _Address:
@@ -929,16 +928,29 @@ def address(self) -> _Address:
929928
"""
930929
return self.__address
931930

931+
def __repr__(self):
932+
return "%s(%r)" % (self.__class__.__name__, self.__address)
933+
934+
935+
class _ConnectionIdEvent(_ConnectionEvent):
936+
"""Private base class for connection events with an id."""
937+
938+
__slots__ = ("__connection_id",)
939+
940+
def __init__(self, address: _Address, connection_id: int) -> None:
941+
super().__init__(address)
942+
self.__connection_id = connection_id
943+
932944
@property
933945
def connection_id(self) -> int:
934946
"""The ID of the Connection."""
935947
return self.__connection_id
936948

937949
def __repr__(self):
938-
return "%s(%r, %r)" % (self.__class__.__name__, self.__address, self.__connection_id)
950+
return "%s(%r, %r)" % (self.__class__.__name__, self.address, self.__connection_id)
939951

940952

941-
class ConnectionCreatedEvent(_ConnectionEvent):
953+
class ConnectionCreatedEvent(_ConnectionIdEvent):
942954
"""Published when a Connection Pool creates a Connection object.
943955
944956
NOTE: This connection is not ready for use until the
@@ -955,7 +967,7 @@ class ConnectionCreatedEvent(_ConnectionEvent):
955967
__slots__ = ()
956968

957969

958-
class ConnectionReadyEvent(_ConnectionEvent):
970+
class ConnectionReadyEvent(_ConnectionIdEvent):
959971
"""Published when a Connection has finished its setup, and is ready to use.
960972
961973
:Parameters:
@@ -969,7 +981,7 @@ class ConnectionReadyEvent(_ConnectionEvent):
969981
__slots__ = ()
970982

971983

972-
class ConnectionClosedEvent(_ConnectionEvent):
984+
class ConnectionClosedEvent(_ConnectionIdEvent):
973985
"""Published when a Connection is closed.
974986
975987
:Parameters:
@@ -1005,7 +1017,7 @@ def __repr__(self):
10051017
)
10061018

10071019

1008-
class ConnectionCheckOutStartedEvent(object):
1020+
class ConnectionCheckOutStartedEvent(_ConnectionEvent):
10091021
"""Published when the driver starts attempting to check out a connection.
10101022
10111023
:Parameters:
@@ -1015,23 +1027,10 @@ class ConnectionCheckOutStartedEvent(object):
10151027
.. versionadded:: 3.9
10161028
"""
10171029

1018-
__slots__ = ("__address",)
1019-
1020-
def __init__(self, address):
1021-
self.__address = address
1022-
1023-
@property
1024-
def address(self):
1025-
"""The address (host, port) pair of the server this connection is
1026-
attempting to connect to.
1027-
"""
1028-
return self.__address
1029-
1030-
def __repr__(self):
1031-
return "%s(%r)" % (self.__class__.__name__, self.__address)
1030+
__slots__ = ()
10321031

10331032

1034-
class ConnectionCheckOutFailedEvent(object):
1033+
class ConnectionCheckOutFailedEvent(_ConnectionEvent):
10351034
"""Published when the driver's attempt to check out a connection fails.
10361035
10371036
:Parameters:
@@ -1042,19 +1041,12 @@ class ConnectionCheckOutFailedEvent(object):
10421041
.. versionadded:: 3.9
10431042
"""
10441043

1045-
__slots__ = ("__address", "__reason")
1044+
__slots__ = ("__reason",)
10461045

10471046
def __init__(self, address: _Address, reason: str) -> None:
1048-
self.__address = address
1047+
super().__init__(address)
10491048
self.__reason = reason
10501049

1051-
@property
1052-
def address(self) -> _Address:
1053-
"""The address (host, port) pair of the server this connection is
1054-
attempting to connect to.
1055-
"""
1056-
return self.__address
1057-
10581050
@property
10591051
def reason(self) -> str:
10601052
"""A reason explaining why connection check out failed.
@@ -1065,10 +1057,10 @@ def reason(self) -> str:
10651057
return self.__reason
10661058

10671059
def __repr__(self):
1068-
return "%s(%r, %r)" % (self.__class__.__name__, self.__address, self.__reason)
1060+
return "%s(%r, %r)" % (self.__class__.__name__, self.address, self.__reason)
10691061

10701062

1071-
class ConnectionCheckedOutEvent(_ConnectionEvent):
1063+
class ConnectionCheckedOutEvent(_ConnectionIdEvent):
10721064
"""Published when the driver successfully checks out a Connection.
10731065
10741066
:Parameters:
@@ -1082,7 +1074,7 @@ class ConnectionCheckedOutEvent(_ConnectionEvent):
10821074
__slots__ = ()
10831075

10841076

1085-
class ConnectionCheckedInEvent(_ConnectionEvent):
1077+
class ConnectionCheckedInEvent(_ConnectionIdEvent):
10861078
"""Published when the driver checks in a Connection into the Pool.
10871079
10881080
:Parameters:
Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
{
2+
"description": "auth-error",
3+
"schemaVersion": "1.10",
4+
"runOnRequirements": [
5+
{
6+
"minServerVersion": "4.4",
7+
"auth": true,
8+
"serverless": "forbid",
9+
"topologies": [
10+
"single",
11+
"replicaset",
12+
"sharded"
13+
]
14+
}
15+
],
16+
"createEntities": [
17+
{
18+
"client": {
19+
"id": "setupClient",
20+
"useMultipleMongoses": false
21+
}
22+
}
23+
],
24+
"initialData": [
25+
{
26+
"collectionName": "auth-error",
27+
"databaseName": "sdam-tests",
28+
"documents": [
29+
{
30+
"_id": 1
31+
},
32+
{
33+
"_id": 2
34+
}
35+
]
36+
}
37+
],
38+
"tests": [
39+
{
40+
"description": "Reset server and pool after AuthenticationFailure error",
41+
"operations": [
42+
{
43+
"name": "failPoint",
44+
"object": "testRunner",
45+
"arguments": {
46+
"client": "setupClient",
47+
"failPoint": {
48+
"configureFailPoint": "failCommand",
49+
"mode": {
50+
"times": 1
51+
},
52+
"data": {
53+
"failCommands": [
54+
"saslContinue"
55+
],
56+
"appName": "authErrorTest",
57+
"errorCode": 18
58+
}
59+
}
60+
}
61+
},
62+
{
63+
"name": "createEntities",
64+
"object": "testRunner",
65+
"arguments": {
66+
"entities": [
67+
{
68+
"client": {
69+
"id": "client",
70+
"useMultipleMongoses": false,
71+
"observeEvents": [
72+
"commandStartedEvent",
73+
"serverDescriptionChangedEvent",
74+
"poolClearedEvent"
75+
],
76+
"uriOptions": {
77+
"retryWrites": false,
78+
"appname": "authErrorTest"
79+
}
80+
}
81+
},
82+
{
83+
"database": {
84+
"id": "database",
85+
"client": "client",
86+
"databaseName": "sdam-tests"
87+
}
88+
},
89+
{
90+
"collection": {
91+
"id": "collection",
92+
"database": "database",
93+
"collectionName": "auth-error"
94+
}
95+
}
96+
]
97+
}
98+
},
99+
{
100+
"name": "insertMany",
101+
"object": "collection",
102+
"arguments": {
103+
"documents": [
104+
{
105+
"_id": 3
106+
},
107+
{
108+
"_id": 4
109+
}
110+
]
111+
},
112+
"expectError": {
113+
"isError": true
114+
}
115+
},
116+
{
117+
"name": "waitForEvent",
118+
"object": "testRunner",
119+
"arguments": {
120+
"client": "client",
121+
"event": {
122+
"serverDescriptionChangedEvent": {
123+
"newDescription": {
124+
"type": "Unknown"
125+
}
126+
}
127+
},
128+
"count": 1
129+
}
130+
},
131+
{
132+
"name": "waitForEvent",
133+
"object": "testRunner",
134+
"arguments": {
135+
"client": "client",
136+
"event": {
137+
"poolClearedEvent": {}
138+
},
139+
"count": 1
140+
}
141+
},
142+
{
143+
"name": "insertMany",
144+
"object": "collection",
145+
"arguments": {
146+
"documents": [
147+
{
148+
"_id": 5
149+
},
150+
{
151+
"_id": 6
152+
}
153+
]
154+
}
155+
},
156+
{
157+
"name": "assertEventCount",
158+
"object": "testRunner",
159+
"arguments": {
160+
"client": "client",
161+
"event": {
162+
"serverDescriptionChangedEvent": {
163+
"newDescription": {
164+
"type": "Unknown"
165+
}
166+
}
167+
},
168+
"count": 1
169+
}
170+
},
171+
{
172+
"name": "assertEventCount",
173+
"object": "testRunner",
174+
"arguments": {
175+
"client": "client",
176+
"event": {
177+
"poolClearedEvent": {}
178+
},
179+
"count": 1
180+
}
181+
}
182+
],
183+
"expectEvents": [
184+
{
185+
"client": "client",
186+
"eventType": "command",
187+
"events": [
188+
{
189+
"commandStartedEvent": {
190+
"command": {
191+
"insert": "auth-error",
192+
"documents": [
193+
{
194+
"_id": 5
195+
},
196+
{
197+
"_id": 6
198+
}
199+
]
200+
},
201+
"commandName": "insert",
202+
"databaseName": "sdam-tests"
203+
}
204+
}
205+
]
206+
}
207+
],
208+
"outcome": [
209+
{
210+
"collectionName": "auth-error",
211+
"databaseName": "sdam-tests",
212+
"documents": [
213+
{
214+
"_id": 1
215+
},
216+
{
217+
"_id": 2
218+
},
219+
{
220+
"_id": 5
221+
},
222+
{
223+
"_id": 6
224+
}
225+
]
226+
}
227+
]
228+
}
229+
]
230+
}

0 commit comments

Comments
 (0)