Replies: 1 comment
-
WIP (suggestions on what to address/take note of are encouraged)
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
As a spinoff from my efforts working on the bootstrap server, I explored mocking frameworks, and have come to point where I can share my learnings.
Current framework: An analogy of a company with multiple office-buildings
Architecture overview
A major aspect of our architecture is based on message passing, with what I describe as a "return enclosed" pattern. To draw an analogy:
So far so good? each "building" is actually a module: One could be the consensus-worker, another could be the bootstrap system, and so on. For the purpose of this analogy, let's consider just two building, building A and building B.
In normal operations, the bootstrap server will "use the postal services" to "send a letter" to the
network-worker
"building". This analogy in code form, for the purpose of fetching bootstrap peers, can be found here: https://github.com/massalabs/massa/blob/main/massa-network-exports/src/network_controller.rs#L165-L176...and in the context of bootstrapping, is used here: https://github.com/massalabs/massa/blob/main/massa-bootstrap/src/server.rs#L825
But we just want hardcoded-results!
This is all well and good, but when testing, we don't actually care about knowing whether or not the
network-worker
building is doing it's job properly, so we want to hard-code what we would get from our "return envelope" contents (i.e. in the bootstrap code linked, we hard-code whatnetwork_command_sender.get_bootstrap_peers().await?
returns)...and so we mock building B. To illustrate-by-analogy: (be warned: this gets convoluted, but it's the best I can do. I'm not even 100% sure it's an accurate analogy...)
And this illustrates how we hardcode what bootstrap peers are "in the network" when a bootstrap being tested. Bear in mind, I've tried my best to simplify things in the analogy.
A simplified approach
in short: Just like a normal function call, but the function result is hard-coded, and the context in which it's called is validated:
In code form:
The intercepted messages
Here we will use the bootstrap server as an example, specifically, the need to get bootstrap peers:
using mockall
(Note: We are not validating the functions call-arguments, which is one of the many features of
mockall
Important observations: If
mockall
was used when I started my bootstrap projectThe vast majority of pain points working on the bootstrap system (and still to this day), is likely to me resolved by this approach.
/* snip */
s that makes this test a challenge to reason about.mockall
removing this pain-pointIn my follow-up comment, I'll hypothesise about benefits, drawbacks, and observations that might apply in the general case.
Beta Was this translation helpful? Give feedback.
All reactions