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

bnet-server-tcp: split socket creation from listening for unittests #1649

Merged

Conversation

sebsura
Copy link
Contributor

@sebsura sebsura commented Jan 4, 2024

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

  • Short description and the purpose of this PR is present above this paragraph
  • Your name is present in the AUTHORS file (optional)

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-tool to have some simple automated checks run and a proper changelog record added.

General
  • Is the PR title usable as CHANGELOG entry?
  • Purpose of the PR is understood
  • Commit descriptions are understandable and well formatted
Source code quality
  • Source code changes are understandable
  • Variable and function names are meaningful
  • Code comments are correct (logically and spelling)
  • Required documentation changes are present and part of the PR
Tests
  • Decision taken that a test is required (if not, then remove this paragraph)
  • The choice of the type of test (unit test or systemtest) is reasonable
  • Testname matches exactly what is being tested
  • On a fail, output of the test leads quickly to the origin of the fault

@sebsura sebsura force-pushed the dev/ssura/master/refactor-bnet-server branch from 06c8bb1 to f314a1d Compare January 11, 2024 09:51
@pstorz pstorz self-requested a review January 11, 2024 10:50
@pstorz pstorz self-assigned this Jan 11, 2024
@pstorz pstorz changed the title bnet-server-tcp: split up logic bnet-server-tcp: split socket creation from listening Feb 2, 2024
@pstorz pstorz changed the title bnet-server-tcp: split socket creation from listening bnet-server-tcp: split socket creation from listening for unittests Feb 2, 2024
sebsura and others added 5 commits February 5, 2024 13:49
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.
@BareosBot BareosBot force-pushed the dev/ssura/master/refactor-bnet-server branch from f424043 to 01a48b0 Compare February 5, 2024 13:49
@BareosBot BareosBot merged commit 8621585 into bareos:master Feb 5, 2024
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

Successfully merging this pull request may close these issues.

None yet

3 participants