(self)
| 159 | |
| 160 | @no_type_check |
| 161 | def test_try_next(self): |
| 162 | # ChangeStreams only read majority committed data so use w:majority. |
| 163 | coll = self.watched_collection().with_options(write_concern=WriteConcern("majority")) |
| 164 | coll.drop() |
| 165 | coll.insert_one({}) |
| 166 | self.addCleanup(coll.drop) |
| 167 | with self.change_stream(max_await_time_ms=250) as stream: |
| 168 | self.assertIsNone(stream.try_next()) # No changes initially. |
| 169 | coll.insert_one({}) # Generate a change. |
| 170 | |
| 171 | # On sharded clusters, even majority-committed changes only show |
| 172 | # up once an event that sorts after it shows up on the other |
| 173 | # shard. So, we wait on try_next to eventually return changes. |
| 174 | def _wait_until(): |
| 175 | return stream.try_next() is not None |
| 176 | |
| 177 | wait_until(_wait_until, "get change from try_next") |
| 178 | |
| 179 | @no_type_check |
| 180 | def test_try_next_runs_one_getmore(self): |
nothing calls this directly
no test coverage detected