Ensure a ChangeStream can be closed from another thread.
(self)
| 349 | @no_type_check |
| 350 | @client_context.require_sync |
| 351 | def test_concurrent_close(self): |
| 352 | """Ensure a ChangeStream can be closed from another thread.""" |
| 353 | # Use a short wait time to speed up the test. |
| 354 | with self.change_stream(max_await_time_ms=250) as change_stream: |
| 355 | |
| 356 | def iterate_cursor(): |
| 357 | try: |
| 358 | for _ in change_stream: |
| 359 | pass |
| 360 | except OperationFailure as e: |
| 361 | if e.code != 237: # CursorKilled error code |
| 362 | raise |
| 363 | |
| 364 | t = threading.Thread(target=iterate_cursor) |
| 365 | t.start() |
| 366 | self.watched_collection().insert_one({}) |
| 367 | time.sleep(1) |
| 368 | change_stream.close() |
| 369 | t.join(3) |
| 370 | self.assertFalse(t.is_alive()) |
| 371 | |
| 372 | @no_type_check |
| 373 | def test_unknown_full_document(self): |
nothing calls this directly
no test coverage detected