MCPcopy Create free account
hub / github.com/mongodb/mongo-python-driver / test_concurrent_close

Method test_concurrent_close

test/test_change_stream.py:351–370  ·  view source on GitHub ↗

Ensure a ChangeStream can be closed from another thread.

(self)

Source from the content-addressed store, hash-verified

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):

Callers

nothing calls this directly

Calls 7

change_streamMethod · 0.45
startMethod · 0.45
insert_oneMethod · 0.45
watched_collectionMethod · 0.45
closeMethod · 0.45
joinMethod · 0.45
is_aliveMethod · 0.45

Tested by

no test coverage detected