googleapis / python-pubsub

Apache License 2.0
385 stars 200 forks source link

Fix DeprecationWarning: connections() is deprecated and will be removed; use net_connections() instead #1206

Open mukund-ananthu opened 2 months ago

mukund-ananthu commented 2 months ago
___________ test_subscriber_not_leaking_open_sockets[rest-rest-rest] ___________

publisher = 
topic_path_base = 'projects/<REDACTED>/topics/<REDACTED>'
subscription_path_base = 'projects/<REDACTED>/subscriptions/<REDACTED>'
cleanup = [(>, (), {'topic': 'projects/<REDACTED>/topics/<REDACTED>'})]
transport = 'rest'

    @pytest.mark.parametrize("transport", ["grpc", "rest"])
    def test_subscriber_not_leaking_open_sockets(
        publisher, topic_path_base, subscription_path_base, cleanup, transport
    ):
        # Make sure the topic and the supscription get deleted.
        # NOTE: Since subscriber client will be closed in the test, we should not
        # use the shared `subscriber` fixture, but instead construct a new client
        # in this test.
        # Also, since the client will get closed, we need another subscriber client
        # to clean up the subscription. We also need to make sure that auxiliary
        # subscriber releases the sockets, too.
        custom_str = "-not-leaking-open-sockets"
        subscription_path = subscription_path_base + custom_str
        topic_path = topic_path_base + custom_str
        subscriber = pubsub_v1.SubscriberClient(transport="grpc")
        subscriber_2 = pubsub_v1.SubscriberClient(transport="grpc")

        cleanup.append(
            (subscriber_2.delete_subscription, (), {"subscription": subscription_path})
        )
        cleanup.append((subscriber_2.close, (), {}))
        cleanup.append((publisher.delete_topic, (), {"topic": topic_path}))

        # Create topic before starting to track connection count (any sockets opened
        # by the publisher client are not counted by this test).
        publisher.create_topic(name=topic_path)

        current_process = psutil.Process()
>       conn_count_start = len(current_process.connections())

tests/system.py:471: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = psutil.Process(pid=397, name='py.test', status='running', started='16:34:59')
args = (), kwargs = {}

    @functools.wraps(fun)
    def inner(self, *args, **kwargs):
>       warnings.warn(msg, category=DeprecationWarning, stacklevel=2)
E       DeprecationWarning: connections() is deprecated and will be removed; use net_connections() instead