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

Method _test_next_blocks

test/test_change_stream.py:314–330  ·  view source on GitHub ↗
(self, change_stream)

Source from the content-addressed store, hash-verified

312 @no_type_check
313 @client_context.require_sync
314 def _test_next_blocks(self, change_stream):
315 inserted_doc = {"_id": ObjectId()}
316 changes = []
317 t = threading.Thread(target=lambda: changes.append(change_stream.next()))
318 t.start()
319 # Sleep for a bit to prove that the call to next() blocks.
320 time.sleep(1)
321 self.assertTrue(t.is_alive())
322 self.assertFalse(changes)
323 self.watched_collection().insert_one(inserted_doc)
324 # Join with large timeout to give the server time to return the change,
325 # in particular for shard clusters.
326 t.join(30)
327 self.assertFalse(t.is_alive())
328 self.assertEqual(1, len(changes))
329 self.assertEqual(changes[0]["operationType"], "insert")
330 self.assertEqual(changes[0]["fullDocument"], inserted_doc)
331
332 @no_type_check
333 @client_context.require_sync

Callers 3

test_next_blocksMethod · 0.95

Calls 7

ObjectIdClass · 0.90
nextMethod · 0.45
startMethod · 0.45
is_aliveMethod · 0.45
insert_oneMethod · 0.45
watched_collectionMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected