I am developing an application that uses the `sockets` package. I included `unittest` unit tests to test the application.
The complete bitbucket-pipelines.yml:
image: python:3.8
pipelines:
default:
- step:
script:
- pip install --upgrade pip
- pip install --upgrade sockets coverage
- git submodule update --init
- python -m coverage run -m unittest discover
- bash <(curl -s https://codecov.io/bash)
However, the pipeline throws errors when the unit tests are being performed:
+ python -m coverage run -m unittest discover
..........................EException in thread Serial server thread:
Traceback (most recent call last):
File "/usr/local/lib/python3.8/threading.py", line 932, in _bootstrap_inner
self.run()
File "/opt/atlassian/pipelines/agent/build/uart3br/_serial_server.py", line 50, in run
self.socket.bind((self.HOST, self.PORT))
OSError: [Errno 98] Address already in use
# ...
The complete pipe (and source): https://bitbucket.org/ctw-bw/micropython-dummy-modules/addon/pipelines/home#!/results/6
Of course the tests pass without problems on my computer (Windows 10, Python 3.8).
The socket creation looks like:
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Set option to allow instant socket reuse after shutdown
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.socket.bind(('127.0.0.1', 52184))
self.socket.listen()
# ...
The error trace is a little hard to follow, but two different errors are being throws:
OSError: [Errno 98] Address already in use
and
ConnectionRefusedError: [Errno 111] Connection refused
I was wondering if other people have had experience with this and what could be the solution to this problem.
Figured it out.
I tested the pipeline locally with Docker, where I ran into the same errors. Apparently there is something with the Python image / Debian / Docker (or a combination) that does not allow rapid opening and closing of sockets.
Instead I restructured my tests to only open and close the server socket once (using `setUpClass()` instead of `setUp()`).
Working pipeline: https://bitbucket.org/ctw-bw/micropython-dummy-modules/addon/pipelines/home#!/results/9
So there is nothing keeping sockets from working.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.