Skip to content

Maybe test SAMP and other networking code with mock sockets? #2126

@embray

Description

@embray

A lot of the "random" test failures on Travis of late are mostly, I think, due to interactions with OS sockets over which we don't have full control, and which can lead to unpredictable behavior.

I wonder if it wouldn't be better to just mock the entire socket module for these purposes, using a lightweight Python replacement for sockets without touching real OS level sockets. For the most part I don't think we require any advanced socket features so this should be reasonably straightforward.

There is one project already called "mocket" which provides this: https://github.com/mocketize/python-mocket, though it doesn't seem to have had much active development in the last year. It still looks okay though. There's also a mock_socket.py hanging out in Python itself: http://hg.python.org/cpython/file/718cddfa0292/Lib/test/mock_socket.py

This is not a normally installed module, but it could just be copied verbatim with the proper attribution. Or, depending on what we determine our actual needs to be, it may be straightforward enough to roll our own.

This isn't something I'd want to put a lot of effort into if it winds up being troublesome. But I think it could really improve the reliability of our tests without implicitly also testing sockets, which really doesn't help us in general.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions