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

Wrong errors raised in tests? #453

Open
IrSent opened this issue May 24, 2019 · 4 comments
Open

Wrong errors raised in tests? #453

IrSent opened this issue May 24, 2019 · 4 comments

Comments

@IrSent
Copy link
Contributor

IrSent commented May 24, 2019

Please tell if it's intended or just not fixed yet.

_____________________________________________________________________________ test_formatter_with_exception _____________________________________________________________________________

    def test_formatter_with_exception():
        fmt = logs.StructuredFormatter()

        try:
            e = Exception()
            e.errno = 101
            e.strerror = 'some error'
            raise e
        except Exception:
            record = make_record({})
            record.exc_info = sys.exc_info()
            log = fmt.format(record)
        assert '\n' in log
        output = log.splitlines()
        timestamp, level, name, msg, structured = parse_logfmt(output[0])
        assert timestamp == TIMESTAMP
        assert level == 'INFO'
        assert name == 'name'
        assert msg == "msg here"
>       assert structured == {
            'errno': 'ENETUNREACH',
            'strerror': 'some error',
        }
E       AssertionError: assert {u'errno': u'...u'some error'} == {'errno': 'ENE... 'some error'}
E         Common items:
E         {u'strerror': u'some error'}
E         Differing items:
E         {'errno': 'ETIME'} != {'errno': 'ENETUNREACH'}
E         Full diff:
E         - {u'errno': u'ETIME', u'strerror': u'some error'}
E         ?                ^^
E         + {u'errno': u'ENETUNREACH', u'strerror': u'some error'}
E         ?               ++ ^^^ +++

/Users/.../work/.../talisker/tests/test_logging.py:275: AssertionError
_______________________________________________________________________________ test_get_errno_fields_dns _______________________________________________________________________________

    def test_get_errno_fields_dns():
        exc = None
        try:
            import socket
            s = socket.socket()
            s.connect(('some-host-name-that-will-not-resolve.com', 54321))
        except Exception as e:
            exc = e

>       assert util.get_errno_fields(exc) == {
            'errno': 'EAI_NONAME',
            'strerror': 'Name or service not known',
        }
E       AssertionError: assert {'errno': 'EN...or not known'} == {'errno': 'EAI...ce not known'}
E         Differing items:
E         {'errno': 'ENOEXEC'} != {'errno': 'EAI_NONAME'}
E         {'strerror': 'nodename nor servname provided, or not known'} != {'strerror': 'Name or service not known'}
E         Full diff:
E         + {u'errno': u'EAI_NONAME', u'strerror': u'Name or service not known'}
E         - {u'errno': 'ENOEXEC',
E         -  u'strerror': 'nodename nor servname provided, or not known'}

/Users/.../work/.../talisker/tests/test_util.py:110: AssertionError

OS name and version:
PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
NAME="Debian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
ID=debian

Any details about your local setup that might be helpful in troubleshooting:
Docker container with gunicorn, django, python_prometheus, etc...
python2.7.16

Detailed steps to reproduce the bug:

  1. Install deps and run pytest -vv
@bloodearnest
Copy link
Contributor

bloodearnest commented May 24, 2019

Hi Michael, thanks for the bug report!

It looks like you are running the tests on Mac OS X? The kernel error numbers/names generated for these errors are different between Linux and OS X, but the tests check only the Linux numbers/names.

We can't easily run the tests on Mac OS X, but would welcome patches to fix the tests.

Also the tests fail, but the code they are testing actually works as intended, which is good :)

Edit: does docker on Mac OS X using a Linux kernel, or run on Darwin directly? If the former, what kernel version is it? It's possible this could be a Linux change that need accounting for in the tests

@bloodearnest
Copy link
Contributor

It may possible to use the errno module in the stdlib to write these tests in a more cross platform manner

@IrSent
Copy link
Contributor Author

IrSent commented May 24, 2019

My bad, forgot to go inside container. Yes, it is MacOsX.

https://docs.docker.com/v17.09/docker-for-mac/docker-toolbox/#the-docker-for-mac-environment

Docker for Mac does not use VirtualBox, but rather HyperKit, a lightweight macOS virtualization solution built on top of Hypervisor.framework in macOS 10.10 Yosemite and higher.

Then goes tiny linux kernel that supports docker and then everything else as I understood.
Docker info:
...
Kernel Version: 4.9.125-linuxkit
Operating System: Docker for Mac
OSType: linux
Architecture: x86_64
...

@IrSent
Copy link
Contributor Author

IrSent commented May 24, 2019

#454
Just a workaround if and until you really need the system-specific error codes.

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

No branches or pull requests

2 participants