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

refactor: make setsockopt() and SetSocketNoDelay() mockable/testable #24357

Merged

Conversation

vasild
Copy link
Contributor

@vasild vasild commented Feb 16, 2022

This is a piece of #21878, chopped off to ease review.

Add a virtual (thus mockable) method Sock::SetSockOpt() that wraps the system setsockopt().

Convert the standalone SetSocketNoDelay() function to a virtual (thus mockable) method Sock::SetNoDelay().

This will help avoid syscalls during testing and to mock them to return whatever is suitable for the tests.

@DrahtBot
Copy link
Contributor

DrahtBot commented Feb 17, 2022

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #24185 (refactor: only use explicit reinterpret/const casts, not implicit by PastaPastaPasta)
  • #21878 (Make all networking code mockable by vasild)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@jonatack
Copy link
Member

jonatack commented Mar 9, 2022

Concept ACK

Copy link
Member

@jonatack jonatack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK aaf8d7e

Some style feedback, feel free to ignore.

@vasild vasild force-pushed the mockable_SetSocketNoDelay_and_setsockopt branch from aaf8d7e to 3ee641f Compare March 16, 2022 11:39
@vasild
Copy link
Contributor Author

vasild commented Mar 16, 2022

aaf8d7ed1f...3ee641f452: style changes

Invalidates ACK from @jonatack

@jonatack
Copy link
Member

ACK 3ee641f

vasild added 3 commits April 15, 2022 09:14
This will help to increase `Sock` usage and make more code mockable.
Since the former is mockable, this makes it easier to test higher level
code that sets the TCP_NODELAY flag.
@vasild vasild force-pushed the mockable_SetSocketNoDelay_and_setsockopt branch from 3ee641f to a2c4a7a Compare April 15, 2022 07:47
@vasild
Copy link
Contributor Author

vasild commented Apr 15, 2022

3ee641f452...a2c4a7acd1: rebase due to conflicts and address suggestion.

Invalidates ACK from @jonatack

@laanwj
Copy link
Member

laanwj commented Apr 15, 2022

Code review ACK a2c4a7a

Copy link
Member

@jonatack jonatack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK a2c4a7a change since last review is folding Sock::SetNoDelay() into the callers

@laanwj laanwj merged commit 6300b95 into bitcoin:master Apr 19, 2022
@vasild vasild deleted the mockable_SetSocketNoDelay_and_setsockopt branch April 19, 2022 15:08
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Apr 19, 2022
…() mockable/testable

a2c4a7a net: use Sock::SetSockOpt() instead of standalone SetSocketNoDelay() (Vasil Dimov)
d65b6c3 net: use Sock::SetSockOpt() instead of setsockopt() (Vasil Dimov)
184e56d net: add new method Sock::SetSockOpt() that wraps setsockopt() (Vasil Dimov)

Pull request description:

  _This is a piece of bitcoin#21878, chopped off to ease review._

  Add a `virtual` (thus mockable) method `Sock::SetSockOpt()` that wraps the system `setsockopt()`.

  Convert the standalone `SetSocketNoDelay()` function to a `virtual` (thus mockable) method `Sock::SetNoDelay()`.

  This will help avoid syscalls during testing and to mock them to return whatever is suitable for the tests.

ACKs for top commit:
  laanwj:
    Code review ACK a2c4a7a
  jonatack:
    ACK a2c4a7a change since last review is folding `Sock::SetNoDelay()` into the callers

Tree-SHA512: 3e2b016c1e4128317a28c17dc9b30472949e1ac3b071b2697c6d30cbcc830df1ee4392a4e23b2ea1ab4e3fb0f59ef450e2a4f3c1df3d8c803dd081652b6c7387
@bitcoin bitcoin locked and limited conversation to collaborators Apr 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants