Skip to content

Commit 9cf88cf

Browse files
authored
PYTHON-2773 Mockupdb test failures (#796)
1 parent 12a6af7 commit 9cf88cf

17 files changed

+62
-524
lines changed

test/mockupdb/operations.py

+8-37
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from collections import namedtuple
1616

1717
from mockupdb import *
18+
from mockupdb import OpMsgReply
1819
from pymongo import ReadPreference
1920

2021
__all__ = ['operations', 'upgrades']
@@ -51,11 +52,11 @@
5152
sharded cluster (PYTHON-868).
5253
"""
5354

54-
not_master_reply_to_query = OpReply(
55+
not_master_reply_to_query = OpMsgReply(
5556
{'$err': 'not master'},
5657
flags=REPLY_FLAGS['QueryFailure'])
5758

58-
not_master_reply_to_command = OpReply(ok=0, errmsg='not master')
59+
not_master_reply_to_command = OpMsgReply(ok=0, errmsg='not master')
5960

6061
operations = [
6162
Operation(
@@ -76,20 +77,6 @@
7677
reply={'cursor': {'id': 0, 'firstBatch': []}},
7778
op_type='may-use-secondary',
7879
not_master=not_master_reply_to_command),
79-
Operation(
80-
'mapreduce',
81-
lambda client: client.db.collection.map_reduce(
82-
'function() {}', 'function() {}'),
83-
reply={'result': {'db': 'db', 'collection': 'out_collection'}},
84-
op_type='must-use-primary',
85-
not_master=not_master_reply_to_command),
86-
Operation(
87-
'inline_mapreduce',
88-
lambda client: client.db.collection.inline_map_reduce(
89-
'function() {}', 'function() {}', {'out': {'inline': 1}}),
90-
reply={'results': []},
91-
op_type='may-use-secondary',
92-
not_master=not_master_reply_to_command),
9380
Operation(
9481
'options',
9582
lambda client: client.db.collection.options(),
@@ -109,12 +96,6 @@
10996
reply={'ok': 1},
11097
op_type='always-use-secondary',
11198
not_master=OpReply(ok=0, errmsg='node is recovering')),
112-
Operation(
113-
'listCollections',
114-
lambda client: client.db.collection_names(),
115-
reply={'cursor': {'id': 0, 'firstBatch': []}},
116-
op_type='must-use-primary',
117-
not_master=not_master_reply_to_command),
11899
Operation(
119100
'listIndexes',
120101
lambda client: client.db.collection.index_information(),
@@ -130,19 +111,9 @@
130111
['name', 'function', 'old', 'new', 'wire_version'])
131112

132113
upgrades = [
133-
Upgrade('index_information',
134-
lambda client: client.db.collection.index_information(),
135-
old=OpQuery(namespace='db.system.indexes'),
136-
new=Command('listIndexes', 'collection', namespace='db'),
137-
wire_version=3),
138-
Upgrade('collection_names',
139-
lambda client: client.db.collection_names(),
140-
old=Command('aggregate', 'system.namespaces', namespace='db'),
141-
new=Command('listCollections', namespace='db'),
142-
wire_version=3),
143-
Upgrade('options',
144-
lambda client: client.db.collection.options(),
145-
old=Command('aggregate', 'system.namespaces', namespace='db'),
146-
new=Command('listCollections', namespace='db'),
147-
wire_version=3),
114+
Upgrade('estimated_document_count',
115+
lambda client: client.db.collection.estimated_document_count(),
116+
old=OpMsg('count', 'collection', namespace='db'),
117+
new=OpMsg('aggregate', 'collection', namespace='db'),
118+
wire_version=12),
148119
]

test/mockupdb/test_auth_recovering_member.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def test_auth_recovering_member(self):
4444
# error. If it raises AutoReconnect we know it actually tried the
4545
# server, and that's wrong.
4646
with self.assertRaises(ServerSelectionTimeoutError):
47-
client.db.authenticate('user', 'password')
47+
client.db.command("ping")
4848

4949
if __name__ == '__main__':
5050
unittest.main()

test/mockupdb/test_cluster_time.py

+11-40
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
from pymongo import (MongoClient,
2020
InsertOne,
2121
UpdateOne,
22-
DeleteMany,
23-
version_tuple)
22+
DeleteMany)
2423

2524
import unittest
2625

@@ -54,23 +53,6 @@ def cluster_time_conversation(self, callback, replies):
5453
reply['$clusterTime'] = {'clusterTime': cluster_time}
5554
request.reply(reply)
5655

57-
# Now test that no commands include $clusterTime with wire version 5,
58-
# even though the isMaster reply still has $clusterTime.
59-
server.cancel_responder(responder)
60-
server.autoresponds('ismaster',
61-
{'minWireVersion': 0,
62-
'maxWireVersion': 5,
63-
'$clusterTime': {'clusterTime': cluster_time}})
64-
65-
client = MongoClient(server.uri)
66-
self.addCleanup(client.close)
67-
68-
with going(callback, client):
69-
for reply in replies:
70-
request = server.receives()
71-
self.assertNotIn('$clusterTime', request)
72-
request.reply(reply)
73-
7456
def test_command(self):
7557
def callback(client):
7658
client.db.command('ping')
@@ -158,27 +140,16 @@ def test_monitor(self):
158140
request.reply(error)
159141

160142
# PyMongo 3.11+ closes the monitoring connection on command errors.
161-
if version_tuple >= (3, 11, -1):
162-
# Fourth exchange: the Monitor closes the connection and runs the
163-
# handshake on a new connection.
164-
request = server.receives('ismaster')
165-
# No $clusterTime in first ismaster, only in subsequent ones
166-
self.assertNotIn('$clusterTime', request)
167-
168-
# Reply without $clusterTime.
169-
reply.pop('$clusterTime')
170-
request.reply(reply)
171-
else:
172-
# Fourth exchange: the Monitor retry attempt uses the clusterTime
173-
# from the previous isMaster error.
174-
request = server.receives('ismaster')
175-
self.assertEqual(request['$clusterTime']['clusterTime'],
176-
cluster_time)
177-
178-
cluster_time = Timestamp(cluster_time.time,
179-
cluster_time.inc + 1)
180-
error['$clusterTime'] = {'clusterTime': cluster_time}
181-
request.reply(error)
143+
144+
# Fourth exchange: the Monitor closes the connection and runs the
145+
# handshake on a new connection.
146+
request = server.receives('ismaster')
147+
# No $clusterTime in first ismaster, only in subsequent ones
148+
self.assertNotIn('$clusterTime', request)
149+
150+
# Reply without $clusterTime.
151+
reply.pop('$clusterTime')
152+
request.reply(reply)
182153

183154
# Fifth exchange: the Monitor attempt uses the clusterTime from
184155
# the previous isMaster error.

test/mockupdb/test_cursor_namespace.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"""Test list_indexes with more than one batch."""
1616

1717
from mockupdb import going, MockupDB
18-
from pymongo import MongoClient, version_tuple
18+
from pymongo import MongoClient
1919

2020
import unittest
2121

@@ -57,7 +57,6 @@ def op():
5757
return list(self.client.test.collection.aggregate([]))
5858
self._test_cursor_namespace(op, 'aggregate')
5959

60-
@unittest.skipUnless(version_tuple >= (3, 11, -1), 'Fixed in pymongo 3.11')
6160
def test_find_cursor(self):
6261
def op():
6362
return list(self.client.test.collection.find())
@@ -71,7 +70,6 @@ def op():
7170

7271
class TestKillCursorsNamespace(unittest.TestCase):
7372
@classmethod
74-
@unittest.skipUnless(version_tuple >= (3, 12, -1), 'Fixed in pymongo 3.12')
7573
def setUpClass(cls):
7674
cls.server = MockupDB(auto_ismaster={'maxWireVersion': 6})
7775
cls.server.run()

test/mockupdb/test_handshake.py

+10-21
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515

1616
from mockupdb import MockupDB, OpReply, OpMsg, absent, Command, go
17-
from pymongo import MongoClient, version as pymongo_version, version_tuple
17+
from pymongo import MongoClient, version as pymongo_version
1818
from pymongo.errors import OperationFailure
1919

2020
import unittest
@@ -33,7 +33,6 @@ def _check_handshake_data(request):
3333

3434

3535
class TestHandshake(unittest.TestCase):
36-
@unittest.skipUnless(version_tuple >= (3, 4), "requires PyMongo 3.4")
3736
def test_client_handshake_data(self):
3837
primary, secondary = MockupDB(), MockupDB()
3938
for server in primary, secondary:
@@ -72,20 +71,14 @@ def test_client_handshake_data(self):
7271
primary.receives('ismaster', 1, client=absent).ok(error_response)
7372
secondary.receives('ismaster', 1, client=absent).ok(error_response)
7473

75-
# PyMongo 3.11+ closes the monitoring connection on command errors.
76-
if version_tuple >= (3, 11, -1):
77-
# The heartbeat retry (on a new connection) does have client data.
78-
heartbeat = primary.receives('ismaster')
79-
_check_handshake_data(heartbeat)
80-
heartbeat.ok(primary_response)
81-
82-
heartbeat = secondary.receives('ismaster')
83-
_check_handshake_data(heartbeat)
84-
heartbeat.ok(secondary_response)
85-
else:
86-
# The heartbeat retry has no client data after a command failure.
87-
primary.receives('ismaster', 1, client=absent).ok(error_response)
88-
secondary.receives('ismaster', 1, client=absent).ok(error_response)
74+
# The heartbeat retry (on a new connection) does have client data.
75+
heartbeat = primary.receives('ismaster')
76+
_check_handshake_data(heartbeat)
77+
heartbeat.ok(primary_response)
78+
79+
heartbeat = secondary.receives('ismaster')
80+
_check_handshake_data(heartbeat)
81+
heartbeat.ok(secondary_response)
8982

9083
# Still no client data.
9184
primary.receives('ismaster', 1, client=absent).ok(primary_response)
@@ -113,15 +106,11 @@ def test_client_handshake_data(self):
113106
request.ok(primary_response)
114107
else:
115108
# Command succeeds.
116-
if version_tuple >= (3, 7):
117-
request.assert_matches(OpMsg('whatever'))
118-
else:
119-
request.assert_matches(Command('whatever'))
109+
request.assert_matches(OpMsg('whatever'))
120110
request.ok()
121111
assert future()
122112
return
123113

124-
@unittest.skipUnless(version_tuple >= (3, 11, -1), "requires PyMongo 3.11")
125114
def test_client_handshake_saslSupportedMechs(self):
126115
server = MockupDB()
127116
server.run()

test/mockupdb/test_legacy_crud.py

-126
This file was deleted.

0 commit comments

Comments
 (0)