question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Testing networking services is hard

See original GitHub issue

What is wrong?

Testing networking services in isolation is quite difficult right now, as discussed in #688 .

How can it be fixed

I think we should try to separate different layers of the code more so that we can replace them easily. Here’s a concrete proposal:

  • Each BasePeer gets a BasePeerInterface instance. BasePeer calls BasePeerInterface.send_command(command), BasePeerInterface calls BasePeer.process_command(command) (alternatively, both classes have a command_queue on which they put commands on).
  • To allow this, Commands keep parameters as instance variables.
  • StreamPeerInterface (or just PeerInterface) writes commands to the output stream and reads them from the input stream, just like the current BasePeer does.
  • For tests, there’s a MockPeerInterface that passes commands through to a shared Network object that sends them to the receiving MockPeerInterface. That means that nothing goes over a network interface and nothing needs to be encoded or decoded.
  • Add a MockDiscovery which gets a list of peer pools to “discover”.
  • PeerPool makes the handshake function configurable, either by taking it as a constructor argument or by making a BasePeerPool and requiring it to implement it in sub classes. We add a mock_handshake that looks up the remote in Network and creates a new peer with a MockPeerInterface.

I haven’t thought this through completely (especially how it affects PeerPool and Server), but don’t have more time just now and wanted to write it down. Will update this tonight when I’ll hopefully had some more time.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
gsalgadocommented, May 17, 2018

One problem with those big architectural redesigns is that usually nobody will have the time/willpower to implement them, so we end up doing things in a suboptimal way waiting for a redesign that will never come. Instead I very much prefer to make small improvements every time I touch a piece of code. For instance, although testing async code is hard and we’re severely lacking on infrastructure for that, we do have some and with some small improvements the existing sharding tests can be a lot simpler and much less fragile

1reaction
pipermerriamcommented, May 17, 2018

I think that’s a fair point, and probably a good conservative approach. I’d be game to re-visit this when/if someone feels like they have a sufficiently good handle on how to do it and the time to execute on it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Top 5 Networking Challenges and How Network Testing Can ...
Today's solutions offer a variety of end-to-end performance testing (for latency, loss, jitter and path analysis). For example, if a client is ...
Read more >
Network Testing: How to Test Network Performance - Obkio
Learn how to perform network testing using Network Monitoring tools to test network performance, and identify network bugs and issues.
Read more >
Network Testing
One difficult problem for test planning and execution is that only a small number of networks, at best, can actually be tested, even...
Read more >
Why hitting the network is bad for your test, and ... - mokacoding
Having your tests hit the network adds the network speed as a constraint to how fast your tests can run, hence how quick...
Read more >
Why network testing is important | NetBeez
Network testing is important to test and validate your network design. Here's a list of handful of command line tools to do so....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found