Repository navigation
Start the TLS test emulators on ports the OS picks at bind time - #132
Merged
Merged
Conversation
test_s7_tls.py picked four free ports when the module was imported and bound them minutes later. In between, the OS could hand one of them to another socket (they come from the ephemeral range clients also use), and every test of that fixture failed with "Address already in use"; this happened on the #102 CI run. The fixtures now start the emulator on port 0 and the tests connect to the new S7CommPlusServer.port, the port it actually bound, so there is no window left.
4 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
tests/test_s7_tls.pypicked four free ports when the module was imported and bound them much later, when each fixture started its emulator. In between, the OS can hand one of those ports to another socket:get_free_tcp_ports()draws them from the ephemeral range, which outgoing client connections also use. When that happens, every test of the fixture fails withOSError: [Errno 98] Address already in use. It happened on the #102 CI run (TestAsyncClientV2WithTLS, 9 errors, ubuntu-22.04 / Python 3.10), and a re-run passed.The emulator can now report the port it actually bound.
S7CommPlusServer.portis the port while it runs (0 otherwise), andstart(port=0)lets the OS pick one at bind time. The TLS fixtures start on port 0, and the tests connect tosrv.port, so there is no window between choosing and binding.Other test modules still pick ports in advance with
get_free_tcp_ports(). They hold the port for much less time and haven't been seen failing. Moving them over can follow, now that the server supports it.Sources
None; no protocol values change.
Tests
tests/test_s7_tls.pypasses 35/35, run three times.tests/test_no_fixed_test_ports.pyandtests/test_s7_server.pypass.mypy s7commplus,ruff check,ruff format --checkandpre-commit run --all-filesare clean.Changelog
Under New features:
Server.portis the TCP port the emulator listens on while it runs, andServer.start(port=0)lets the OS pick a free one, so tests can runemulators side by side without choosing ports in advance.
Checklist
pytest,mypy s7commplus,ruff checkandruff format --checkpassCHANGES.mdis unchangedREADME.md,__all__and the docs are updated for public API changes🤖 Generated with Claude Code