Skip to content

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

Merged
missytake merged 3 commits into
mainfrom
dkim-tests-port-25
Jun 29, 2025
Merged

missytake merged 3 commits into
mainfrom
dkim-tests-port-25

Conversation

@missytake

Copy link
Copy Markdown
Contributor

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

________________________________________________________________________________________________ test_reject_missing_dkim[fake@example.org] _________________________________________________________________________________________________
[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 = 'fake@example.org'

    @pytest.mark.parametrize("from_addr", ["fake@example.org", "fake@testrun.org"])
    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 'ac1_ad912n@ten.testrun.org' '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

hpk42 commented Jun 3, 2025

Copy link
Copy Markdown
Contributor

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

@missytake

missytake commented Jun 3, 2025 •

Copy link
Copy Markdown
Contributor Author

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
@missytake
missytake changed the base branch from main to ruff-ignore-PLC0415 June 29, 2025 16:11
@missytake
missytake force-pushed the dkim-tests-port-25 branch from 12b2b57 to 0944920 Compare June 29, 2025 16:11
@missytake

Copy link
Copy Markdown
Contributor Author

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

the test regularly fails if there was a lint issue. I'm trying to tackle it in #592

@missytake

Copy link
Copy Markdown
Contributor Author

Should be merged after #591

Base automatically changed from ruff-ignore-PLC0415 to main June 29, 2025 17:49
@missytake
missytake merged commit b4122be into main Jun 29, 2025
@missytake
missytake deleted the dkim-tests-port-25 branch June 29, 2025 17:49
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