@@ -139,6 +139,34 @@ def test_try_next_runs_one_getmore(self):
139139 self .assertEqual (listener .started_command_names (), ["getMore" ])
140140 self .assertIsNone (stream .try_next ())
141141
142+ def test_batch_size_is_honored (self ):
143+ listener = EventListener ()
144+ client = rs_or_single_client (event_listeners = [listener ])
145+ # Connect to the cluster.
146+ client .admin .command ('ping' )
147+ listener .results .clear ()
148+ # ChangeStreams only read majority committed data so use w:majority.
149+ coll = self .watched_collection ().with_options (
150+ write_concern = WriteConcern ("majority" ))
151+ coll .drop ()
152+ # Create the watched collection before starting the change stream to
153+ # skip any "create" events.
154+ coll .insert_one ({'_id' : 1 })
155+ self .addCleanup (coll .drop )
156+ # Expected batchSize.
157+ expected = {'batchSize' : 23 }
158+ with self .change_stream_with_client (
159+ client , max_await_time_ms = 250 , batch_size = 23 ) as stream :
160+ # Confirm that batchSize is honored for initial batch.
161+ cmd = listener .results ['started' ][0 ].command
162+ self .assertEqual (cmd ['cursor' ], expected )
163+ listener .results .clear ()
164+ # Confirm that batchSize is honored by getMores.
165+ self .assertIsNone (stream .try_next ())
166+ cmd = listener .results ['started' ][0 ].command
167+ key = next (iter (expected ))
168+ self .assertEqual (expected [key ], cmd [key ])
169+
142170
143171class TestClusterChangeStream (IntegrationTest , ChangeStreamTryNextMixin ):
144172
0 commit comments