(self)
| 1230 | |
| 1231 | # Sessions prose test: 3) $clusterTime in commands |
| 1232 | def test_cluster_time(self): |
| 1233 | listener = SessionTestListener() |
| 1234 | client = self.rs_or_single_client(event_listeners=[listener]) |
| 1235 | collection = client.pymongo_test.collection |
| 1236 | # Prepare for tests of find() and aggregate(). |
| 1237 | collection.insert_many([{} for _ in range(10)]) |
| 1238 | self.addCleanup(collection.drop) |
| 1239 | self.addCleanup(client.pymongo_test.collection2.drop) |
| 1240 | |
| 1241 | def rename_and_drop(): |
| 1242 | # Ensure collection exists. |
| 1243 | collection.insert_one({}) |
| 1244 | collection.rename("collection2") |
| 1245 | client.pymongo_test.collection2.drop() |
| 1246 | |
| 1247 | def insert_and_find(): |
| 1248 | cursor = collection.find().batch_size(1) |
| 1249 | for _ in range(10): |
| 1250 | # Advance the cluster time. |
| 1251 | collection.insert_one({}) |
| 1252 | next(cursor) |
| 1253 | |
| 1254 | cursor.close() |
| 1255 | |
| 1256 | def insert_and_aggregate(): |
| 1257 | cursor = (collection.aggregate([], batchSize=1)).batch_size(1) |
| 1258 | for _ in range(5): |
| 1259 | # Advance the cluster time. |
| 1260 | collection.insert_one({}) |
| 1261 | next(cursor) |
| 1262 | |
| 1263 | cursor.close() |
| 1264 | |
| 1265 | def aggregate(): |
| 1266 | (collection.aggregate([])).to_list() |
| 1267 | |
| 1268 | ops = [ |
| 1269 | # Tests from Driver Sessions Spec. |
| 1270 | ("ping", lambda: client.admin.command("ping")), |
| 1271 | ("aggregate", lambda: aggregate()), |
| 1272 | ("find", lambda: collection.find().to_list()), |
| 1273 | ("insert_one", lambda: collection.insert_one({})), |
| 1274 | # Additional PyMongo tests. |
| 1275 | ("insert_and_find", insert_and_find), |
| 1276 | ("insert_and_aggregate", insert_and_aggregate), |
| 1277 | ("update_one", lambda: collection.update_one({}, {"$set": {"x": 1}})), |
| 1278 | ("update_many", lambda: collection.update_many({}, {"$set": {"x": 1}})), |
| 1279 | ("delete_one", lambda: collection.delete_one({})), |
| 1280 | ("delete_many", lambda: collection.delete_many({})), |
| 1281 | ("bulk_write", lambda: collection.bulk_write([InsertOne({})])), |
| 1282 | ("rename_and_drop", rename_and_drop), |
| 1283 | ] |
| 1284 | |
| 1285 | for _name, f in ops: |
| 1286 | listener.reset() |
| 1287 | # Call f() twice, insert to advance clusterTime, call f() again. |
| 1288 | f() |
| 1289 | f() |
nothing calls this directly
no test coverage detected