@gen_test
    def test_nested_callbacks(self):
        results = [0]
        future = Future()
        yield self.collection.remove()
        yield self.collection.insert({'_id': 1})

        def callback(result, error):
            if error:
                raise error

            if not result:
                # Done iterating
                return

            results[0] += 1
            if results[0] < 1000:
                self.collection.find({'_id': 1}).each(callback)
            else:
                future.set_result(None)

        self.collection.find({'_id': 1}).each(callback)

        yield future
        self.assertEqual(1000, results[0])
dataset/ETHPy150Open mongodb/motor/test/tornado_tests/test_motor_collection.py/MotorCollectionTest.test_nested_callbacks/original