Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check that MongoDB server is responding #917

Merged
merged 2 commits into from
Dec 9, 2024
Merged

Conversation

ellert
Copy link
Contributor

@ellert ellert commented Dec 9, 2024

If the MongoDB client is installed, but there is no MongoDB server running the MongoDB test fails:

==================================== ERRORS ====================================
___________ ERROR at teardown of TestMongoBackend.test_update_record ___________
>   request.addfinalizer(lambda: c.drop_database('iptestdb'))
ipyparallel/tests/test_mongodb.py:38: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/usr/lib64/python3.13/site-packages/pymongo/_csot.py:105: in csot_wrapper
    return func(self, *args, **kwargs)
/usr/lib64/python3.13/site-packages/pymongo/mongo_client.py:1884: in drop_database
    with self._socket_for_writes(session) as sock_info:
/usr/lib64/python3.13/site-packages/pymongo/mongo_client.py:1239: in _socket_for_writes
    server = self._select_server(writable_server_selector, session)
/usr/lib64/python3.13/site-packages/pymongo/mongo_client.py:1229: in _select_server
    server = topology.select_server(server_selector)
/usr/lib64/python3.13/site-packages/pymongo/topology.py:272: in select_server
    server = self._select_server(selector, server_selection_timeout, address)
/usr/lib64/python3.13/site-packages/pymongo/topology.py:261: in _select_server
    servers = self.select_servers(selector, server_selection_timeout, address)
/usr/lib64/python3.13/site-packages/pymongo/topology.py:223: in select_servers
    server_descriptions = self._select_servers_loop(selector, server_timeout, address)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
self = <Topology <TopologyDescription id: 675036ab775bd5b119588481, topology_type: Unknown, servers: [<ServerDescription ('lo...st', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('localhost:27017: [Errno 111] Connection refused')>]>>
selector = <function writable_server_selector at 0x7f6f2e96f740>, timeout = 30
address = None
    def _select_servers_loop(self, selector, timeout, address):
        """select_servers() guts. Hold the lock when calling this."""
        now = time.monotonic()
        end_time = now + timeout
        server_descriptions = self._description.apply_selector(
            selector, address, custom_selector=self._settings.server_selector
        )
    
        while not server_descriptions:
            # No suitable servers.
            if timeout == 0 or now > end_time:
>               raise ServerSelectionTimeoutError(
                    "%s, Timeout: %ss, Topology Description: %r"
                    % (self._error_message(selector), timeout, self.description)
                )
E               pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection refused, Timeout: 30s, Topology Description: <TopologyDescription id: 675036ab775bd5b119588481, topology_type: Unknown, servers: [<ServerDescription ('localhost', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('localhost:27017: [Errno 111] Connection refused')>]>
/usr/lib64/python3.13/site-packages/pymongo/topology.py:238: ServerSelectionTimeoutError

This commit adds a check that the MongoDB server is responding before trying to run the MongoDB tests.

ellert and others added 2 commits December 9, 2024 12:39
If the MongoDB client is installed, but there is no MongoDB server
running the MongoDB test fails:

==================================== ERRORS ====================================
___________ ERROR at teardown of TestMongoBackend.test_update_record ___________
>   request.addfinalizer(lambda: c.drop_database('iptestdb'))
ipyparallel/tests/test_mongodb.py:38:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/usr/lib64/python3.13/site-packages/pymongo/_csot.py:105: in csot_wrapper
    return func(self, *args, **kwargs)
/usr/lib64/python3.13/site-packages/pymongo/mongo_client.py:1884: in drop_database
    with self._socket_for_writes(session) as sock_info:
/usr/lib64/python3.13/site-packages/pymongo/mongo_client.py:1239: in _socket_for_writes
    server = self._select_server(writable_server_selector, session)
/usr/lib64/python3.13/site-packages/pymongo/mongo_client.py:1229: in _select_server
    server = topology.select_server(server_selector)
/usr/lib64/python3.13/site-packages/pymongo/topology.py:272: in select_server
    server = self._select_server(selector, server_selection_timeout, address)
/usr/lib64/python3.13/site-packages/pymongo/topology.py:261: in _select_server
    servers = self.select_servers(selector, server_selection_timeout, address)
/usr/lib64/python3.13/site-packages/pymongo/topology.py:223: in select_servers
    server_descriptions = self._select_servers_loop(selector, server_timeout, address)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Topology <TopologyDescription id: 675036ab775bd5b119588481, topology_type: Unknown, servers: [<ServerDescription ('lo...st', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('localhost:27017: [Errno 111] Connection refused')>]>>
selector = <function writable_server_selector at 0x7f6f2e96f740>, timeout = 30
address = None
    def _select_servers_loop(self, selector, timeout, address):
        """select_servers() guts. Hold the lock when calling this."""
        now = time.monotonic()
        end_time = now + timeout
        server_descriptions = self._description.apply_selector(
            selector, address, custom_selector=self._settings.server_selector
        )

        while not server_descriptions:
            # No suitable servers.
            if timeout == 0 or now > end_time:
>               raise ServerSelectionTimeoutError(
                    "%s, Timeout: %ss, Topology Description: %r"
                    % (self._error_message(selector), timeout, self.description)
                )
E               pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection refused, Timeout: 30s, Topology Description: <TopologyDescription id: 675036ab775bd5b119588481, topology_type: Unknown, servers: [<ServerDescription ('localhost', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('localhost:27017: [Errno 111] Connection refused')>]>
/usr/lib64/python3.13/site-packages/pymongo/topology.py:238: ServerSelectionTimeoutError

This commit adds a check that the MongoDB server is responding before
trying to run the MongoDB tests.
@minrk minrk merged commit 8d170cb into ipython:main Dec 9, 2024
15 checks passed
@minrk
Copy link
Member

minrk commented Dec 9, 2024

Thanks!

@ellert ellert deleted the mongodb-check branch December 9, 2024 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants