bnet-server-tcp: split socket creation from listening for unittests#1649
Merged
BareosBot merged 5 commits intobareos:masterfrom Feb 5, 2024
Merged
Conversation
06c8bb1 to
f314a1d
Compare
pstorz
approved these changes
Feb 2, 2024
Instead of bnetservertcp doing open() + bind() + listen() all on its own, we instead split it up so that you can give the tcp server some already prepared sockets. This can be used for great effect in unit tests, where you can now 1) create the sockets inside the test with port set to 0 2) give those sockets to the tcp server to listen to 3) query the selected (free) port with getsockname This way you do not have to hardcode any ports inside the unit tests. This also another step in disentangling the socket code and the bareos core since you now do not need to read the address/port from the configuration. Hopefully we can in the future unit tests sockets without needing full blown config parsers.
f424043 to
01a48b0
Compare
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.
Thank you for contributing to the Bareos Project!
This PR splits up the socket binding & listening logic from the bnet server into two parts. This way unit tests can bind the sockets themselves without using any configuration file. This allows them to ask the operating system to choose ports for them instead of using hardcoded ports.
The ktls test is enhanced to take advantage of this fact. Now you can run multiple ktls unit-tests in parallel without the tests complaining about the port being already in use.
Please check
If you have any questions or problems, please give a comment in the PR.
Helpful documentation and best practices
Checklist for the reviewer of the PR (will be processed by the Bareos team)
Make sure you check/merge the PR using
devtools/pr-toolto have some simple automated checks run and a proper changelog record added.General
Source code quality
Tests