Skip to content

tests: test more reliably if port 25 is reachable #580

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

missytake
Copy link
Contributor

Follow-up for #552
The test failed with this error:

________________________________________________________________________________________________ test_reject_missing_dkim[[email protected]] _________________________________________________________________________________________________
[gw3] linux -- Python 3.12.3 /home/user/code/pyinfra-sysadmin/servers/nine.testrun.org/chatmail/venv/bin/python3

cmsetup = <cmdeploy.tests.plugin.CMSetup object at 0x76ef7f480200>, maildata = <function maildata.<locals>.maildata at 0x76ef7f677600>, from_addr = '[email protected]'

    @pytest.mark.parametrize("from_addr", ["[email protected]", "[email protected]"])
    def test_reject_missing_dkim(cmsetup, maildata, from_addr):
        recipient = cmsetup.gen_users(1)[0]
        msg = maildata(
            "encrypted.eml", from_addr=from_addr, to_addr=recipient.addr
        ).as_string()
        try:
>           conn = smtplib.SMTP(cmsetup.maildomain, 25, timeout=10)

cmdeploy/src/cmdeploy/tests/online/test_1_basic.py:126: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/usr/lib/python3.12/smtplib.py:255: in __init__
    (code, msg) = self.connect(host, port)
/usr/lib/python3.12/smtplib.py:341: in connect
    self.sock = self._get_socket(host, port, self.timeout)
/usr/lib/python3.12/smtplib.py:312: in _get_socket
    return socket.create_connection((host, port), timeout,
/usr/lib/python3.12/socket.py:852: in create_connection
    raise exceptions[0]
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

address = ('ten.testrun.org', 25), timeout = 10, source_address = None

    def create_connection(address, timeout=_GLOBAL_DEFAULT_TIMEOUT,
                          source_address=None, *, all_errors=False):
        """Connect to *address* and return the socket object.
    
        Convenience function.  Connect to *address* (a 2-tuple ``(host,
        port)``) and return the socket object.  Passing the optional
        *timeout* parameter will set the timeout on the socket instance
        before attempting to connect.  If no *timeout* is supplied, the
        global default timeout setting returned by :func:`getdefaulttimeout`
        is used.  If *source_address* is set it must be a tuple of (host, port)
        for the socket to bind as a source address before making the connection.
        A host of '' or port 0 tells the OS to use the default. When a connection
        cannot be created, raises the last error if *all_errors* is False,
        and an ExceptionGroup of all errors if *all_errors* is True.
        """
    
        host, port = address
        exceptions = []
        for res in getaddrinfo(host, port, 0, SOCK_STREAM):
            af, socktype, proto, canonname, sa = res
            sock = None
            try:
                sock = socket(af, socktype, proto)
                if timeout is not _GLOBAL_DEFAULT_TIMEOUT:
                    sock.settimeout(timeout)
                if source_address:
                    sock.bind(source_address)
>               sock.connect(sa)
E               OSError: [Errno 101] Network is unreachable

/usr/lib/python3.12/socket.py:837: OSError
----------------------------------------------------------------------------------------------------------- Captured stdout call ------------------------------------------------------------------------------------------------------------
Creating 1 online users
smtp-connect ten.testrun.org
smtp-login '[email protected]' 'vcj9jm31bh6hzbj1jptm'

Port 25 is blocked on my network, it's not hard to see why it failed. cmdeploy/src/cmdeploy/tests/online/test_0_login.py::test_no_vrfy was skipped correctly in the same cmdeploy test run, so I took that method of testing whether port 25 is available, seems more reliable.

@missytake missytake requested a review from link2xt June 3, 2025 07:53
@hpk42
Copy link
Contributor

hpk42 commented Jun 3, 2025

a bit unsure about the CI failures which are about "undeployed changes".

@missytake
Copy link
Contributor Author

missytake commented Jun 3, 2025

a bit unsure about the CI failures which are about "undeployed changes".

hm, this test needs some more love I think... or it should fail with a warning instead of a fail.

@missytake missytake force-pushed the dkim-tests-port-25 branch from 95231fc to 12b2b57 Compare June 12, 2025 13:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants