Skip to content

Commit e18737f

Browse files
committed
move test to correct folder
1 parent b1899d6 commit e18737f

File tree

3 files changed

+15
-182
lines changed

3 files changed

+15
-182
lines changed

test/asynchronous/test_client_metadata.py

Lines changed: 0 additions & 161 deletions
This file was deleted.

test/test_client_metadata.py renamed to test/mockupdb/test_client_metadata.py

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,25 @@
1313
# limitations under the License.
1414
from __future__ import annotations
1515

16-
import asyncio
1716
import time
1817
import unittest
1918
from test.utils_shared import CMAPListener
2019
from typing import Optional
2120

2221
import pytest
23-
from mockupdb import MockupDB, OpMsgReply
2422

2523
from pymongo import MongoClient
2624
from pymongo.driver_info import DriverInfo
2725
from pymongo.monitoring import ConnectionClosedEvent
2826

29-
pytestmark = pytest.mark.mockupdb
27+
try:
28+
from mockupdb import MockupDB, OpMsgReply
29+
30+
_HAVE_MOCKUPDB = True
31+
except ImportError:
32+
_HAVE_MOCKUPDB = False
3033

31-
_IS_SYNC = True
34+
pytestmark = pytest.mark.mockupdb
3235

3336

3437
def _get_handshake_driver_info(request):
@@ -39,12 +42,17 @@ def _get_handshake_driver_info(request):
3942
class TestClientMetadataProse(unittest.TestCase):
4043
def setUp(self):
4144
self.server = MockupDB()
45+
# there are two handshake requests, i believe one is from the monitor, and the other is from the client
46+
self.monitor_handshake = False
4247
self.handshake_req = None
4348

4449
def respond(r):
4550
# Only save the very first request from the driver.
4651
if self.handshake_req is None:
47-
self.handshake_req = r
52+
if not self.monitor_handshake:
53+
self.monitor_handshake = True
54+
else:
55+
self.handshake_req = r
4856
return r.reply(OpMsgReply(minWireVersion=0, maxWireVersion=13))
4957

5058
self.server.autoresponds(respond)
@@ -73,11 +81,11 @@ def check_metadata_added(
7381

7482
# add data
7583
client._append_metadata(DriverInfo(add_name, add_version, add_platform))
76-
# reset
84+
# make sure new metadata is being sent
7785
self.handshake_req = None
7886
client.admin.command("ping")
7987
new_metadata = _get_handshake_driver_info(self.handshake_req)
80-
# compare
88+
8189
self.assertEqual(
8290
new_metadata["driver"]["name"], f"{name}|{add_name}" if add_name is not None else name
8391
)
@@ -128,7 +136,6 @@ def test_doesnt_update_established_connections(self):
128136
driver_metadata["version"],
129137
metadata["platform"],
130138
)
131-
# feels like i should do something to check that it is initially sent
132139
self.assertIsNotNone(name)
133140
self.assertIsNotNone(version)
134141
self.assertIsNotNone(platform)
@@ -139,23 +146,11 @@ def test_doesnt_update_established_connections(self):
139146
# check new data isn't sent
140147
self.handshake_req = None
141148
client.admin.command("ping")
142-
# if it was an actual handshake request, client data would be in the ping request which would start the handshake i think
143149
self.assertNotIn("client", self.handshake_req)
144150
self.assertEqual(listener.event_count(ConnectionClosedEvent), 0)
145151

146152
client.close()
147153

148154

149-
# THESE ARE MY NOTES TO SELF, PLAESE IGNORE
150-
# two options
151-
# emit events with a flag, so when testing (like now), we can emit more stuff
152-
# or we can mock it? but not sure if that ruins the spirit of the test -> this would be easier tho..
153-
# we'd send, mock server would receive and send back to us?
154-
# use mockup DB!
155-
# usually, create mockupDB instance and then tell it to automatically respond to automatic responses, i'll need to change that for this but i also don't want to mess up SDAM stuff?
156-
# i can get logs from server (in mongo orchestration) if mockup DB is too annoying (maybe get log?)
157-
# ask the team generally but jib thinks we should emit events with a flag
158-
# make sure to state pros and cons for each ticket
159-
160155
if __name__ == "__main__":
161156
unittest.main()

tools/synchro.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,6 @@ def async_only_test(f: str) -> bool:
209209
"test_client.py",
210210
"test_client_bulk_write.py",
211211
"test_client_context.py",
212-
"test_client_metadata.py",
213212
"test_collation.py",
214213
"test_collection.py",
215214
"test_collection_management.py",

0 commit comments

Comments
 (0)