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

Potential improvements to mock_system. #183

Closed
3 tasks done
mszulcz-mitre opened this issue Sep 26, 2022 · 2 comments
Closed
3 tasks done

Potential improvements to mock_system. #183

mszulcz-mitre opened this issue Sep 26, 2022 · 2 comments
Assignees
Labels
fix/bug Fixes errant behavior

Comments

@mszulcz-mitre
Copy link
Contributor

Affected Branch

trunk

Basic Diagnostics

  • I've pulled the latest changes on the affected branch and the issue is still present.

  • The issue is reproducible in docker

Description

The mock_system class “Establishes dummy listeners for each enabled system component” such as a watchtower, atomizer, or sentinel. It’s used in many of the integration tests. I think it’s an extremely useful class, but when using it for the first few times, I got confused about some things. I think the code could modified a little to make the class a little clearer.

Components or modules?

Sometimes the things that are mocked are called components; sometimes they’re called modules. This might be confusing to a new user. For example, when looking at the signature of the expect method, the variables for_module and component_id appear, and it’s not obvious that component_id is an ID of the specified for_module:

template<typename T>
auto expect(mock_system_module for_module,
std::optional<cbdc::buffer>&& reply_with = std::nullopt,
uint64_t component_id = 0) -> std::future<T> {

I can't see any value in using both terms, so it seems reasonable to just use the word “module” since it’s already used more frequently in variable names in the class.

When’s a module disabled?

It’s not always obvious what modules will be mocked. By default, the class mocks all modules in the m_modules set and requires the user to specify what modules not to mock by passing them to the constructor in the disabled_modules set:

mock_system(
const std::unordered_set<mock_system_module>& disabled_modules,
config::options opts);

However, even if a module is enabled, it still won’t get mocked if its endpoints aren’t specified in the options struct. This is understandable, but makes code difficult to debug because it happens without warning. For example, according to the disabled modules set, the coordinator module should be mocked in the following tests, but isn’t because endpoints aren’t given: watchtower_integration_test, sentinel_integration_test , replicated_atomizer_integration_tests , replicated_shard_integration_tests , watchtower_integration_test , atomizer_raft_integration_test . In the sentinel_2pc_integration_test, the sentinel module itself is the only module in the disabled_modules set, but 4 of the remaining 5 possible modules do not get mocked because their endpoints aren’t given.

What does the return value of start_servers mean?

The method start_servers attempts to start a listening server for a given module and returns a boolean:

auto start_servers(mock_system_module for_module,
const std::vector<network::endpoint_t>& endpoints)
-> bool;

As written, it returns true for both of these conditions:

  • A server is started for the given module.
  • A server is not started for the given module because it’s in the disabled_modules set or because no endpoints for the module were given.

Having the method return true even if servers aren’t started is a little confusing.

Code of Conduct

  • I agree to follow this project's Code of Conduct
@mszulcz-mitre mszulcz-mitre added the fix/bug Fixes errant behavior label Sep 26, 2022
mszulcz-mitre added a commit to mszulcz-mitre/opencbdc-tx that referenced this issue Sep 26, 2022
The mock_system_test class has a few parts that could cause confusion.
For example, the words 'module' and 'component' are used interchangeably,
it's not clear when modules will be mocked, and it's not clear what the
return value of start_servers means (see Issue mit-dci#183).  This commit
refactors the code to clarify these issues.

Signed-off-by: Michael L. Szulczewski <[email protected]>
mszulcz-mitre added a commit to mszulcz-mitre/opencbdc-tx that referenced this issue Sep 26, 2022
The mock_system class has a few parts that could cause confusion.
For example, the words 'module' and 'component' are used interchangeably,
it's not clear when modules will be mocked, and it's not clear what the
return value of start_servers means (see Issue mit-dci#183).  This commit
refactors the code to clarify these issues.

Signed-off-by: Michael L. Szulczewski <[email protected]>
@mszulcz-mitre
Copy link
Contributor Author

I opened draft pull request #184 to address these issues.

HalosGhost pushed a commit that referenced this issue Feb 21, 2023
The mock_system class has a few parts that could cause confusion.
For example, the words 'module' and 'component' are used interchangeably,
it's not clear when modules will be mocked, and it's not clear what the
return value of start_servers means (see Issue #183).  This commit
refactors the code to clarify these issues.

Signed-off-by: Michael L. Szulczewski <[email protected]>
@HalosGhost
Copy link
Collaborator

via #184.

HalosGhost pushed a commit to HalosGhost/opencbdc-tx that referenced this issue Jul 6, 2023
The mock_system class has a few parts that could cause confusion.
For example, the words 'module' and 'component' are used interchangeably,
it's not clear when modules will be mocked, and it's not clear what the
return value of start_servers means (see Issue mit-dci#183).  This commit
refactors the code to clarify these issues.

Signed-off-by: Michael L. Szulczewski <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix/bug Fixes errant behavior
Projects
None yet
Development

No branches or pull requests

2 participants