You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What did you have in mind here - if there's one thing that has good test coverage its the things that ChannelManager exposes - message handling, its public interface, and block connection, even if its all in functional_tests.rs, instead of channelmanager.rs directly.
Per the description, I was referring to unit tests, which I think compliment functional tests and should be a part of our testing strategy. Unit tests provide more confidence in the code, ease finding the root cause of bugs, help improve system design by identifying complexity, and act to document module behaviors.
As suggested by the issue label, I may use this opportunity to get into initial contact with the code base. If that's okay with you, I'll try to write some tests in the coming days.
Right, I think the "functional_tests" in many ways act as unit tests. You could pull some small bits out, but, for the most part, the functional tests we have call send_payment and then check that the expected messages come back out. I'm really not sure how you'd split them out to be more useful.
It's entirely possible that the tests wouldn't look much different. I don't think that makes "functional_tests" act as unit tests, though. I'd argue that it could be a sign that this module is doing too much. The number of dependencies that it has could also be indicative of that; unit tests shouldn't require an elaborate setup.
Another telltale sign is when something is named with a Manager suffix. It could be simple lack of imagination in naming, but more often than not the module has either too much or an unclear responsibility. Here's a sampling of some references on this topic from a quick Google search:
This is why unit tests are important: they foster better design. So, this issue could potentially be repurposed to refactor ChannelManager into pieces that can be unit tested. I'm not sure exactly what those pieces would look like. But the process of identifying the responsibilities of this module would give a better idea of what those pieces could be.
Its true, it would be nice to move Channels to be pub and let ChannelManager take on more of a message-passing role, tracking HTLCs as Channels accept/forward them. This is essentially all it does now, but with the underlying Channels being hidden from the end-user, but I'd guess that would be a huge overhaul of the API and with a ton of careful work that would have to go into it. Still, while a good unit test target may be Channels (eg setting a Channel state machine to a certain state and then checking that some method mutates it in the correct way), trying to do so in ChannelManager would require more initialization just in terms of setting the state variables than a functional test does.
I agree Manager may be the wrong word here - ultimately its not just that its holding all the Channels, but tracking a bunch of HTLC state, implying more of an HTLCMarshallerWithChannelsInside, but that seems like a mouthful. I'm open to better names :).
Activity
TheBlueMatt commentedon Mar 3, 2020
What did you have in mind here - if there's one thing that has good test coverage its the things that
ChannelManagerexposes - message handling, its public interface, and block connection, even if its all in functional_tests.rs, instead of channelmanager.rs directly.jkczyz commentedon Mar 3, 2020
Per the description, I was referring to unit tests, which I think compliment functional tests and should be a part of our testing strategy. Unit tests provide more confidence in the code, ease finding the root cause of bugs, help improve system design by identifying complexity, and act to document module behaviors.
tnull commentedon Mar 4, 2020
As suggested by the issue label, I may use this opportunity to get into initial contact with the code base. If that's okay with you, I'll try to write some tests in the coming days.
TheBlueMatt commentedon Mar 4, 2020
Right, I think the "functional_tests" in many ways act as unit tests. You could pull some small bits out, but, for the most part, the functional tests we have call send_payment and then check that the expected messages come back out. I'm really not sure how you'd split them out to be more useful.
jkczyz commentedon Mar 4, 2020
It's entirely possible that the tests wouldn't look much different. I don't think that makes "functional_tests" act as unit tests, though. I'd argue that it could be a sign that this module is doing too much. The number of dependencies that it has could also be indicative of that; unit tests shouldn't require an elaborate setup.
Another telltale sign is when something is named with a
Managersuffix. It could be simple lack of imagination in naming, but more often than not the module has either too much or an unclear responsibility. Here's a sampling of some references on this topic from a quick Google search:This is why unit tests are important: they foster better design. So, this issue could potentially be repurposed to refactor ChannelManager into pieces that can be unit tested. I'm not sure exactly what those pieces would look like. But the process of identifying the responsibilities of this module would give a better idea of what those pieces could be.
TheBlueMatt commentedon Mar 4, 2020
Its true, it would be nice to move Channels to be pub and let ChannelManager take on more of a message-passing role, tracking HTLCs as Channels accept/forward them. This is essentially all it does now, but with the underlying Channels being hidden from the end-user, but I'd guess that would be a huge overhaul of the API and with a ton of careful work that would have to go into it. Still, while a good unit test target may be Channels (eg setting a Channel state machine to a certain state and then checking that some method mutates it in the correct way), trying to do so in ChannelManager would require more initialization just in terms of setting the state variables than a functional test does.
I agree Manager may be the wrong word here - ultimately its not just that its holding all the Channels, but tracking a bunch of HTLC state, implying more of an HTLCMarshallerWithChannelsInside, but that seems like a mouthful. I'm open to better names :).