Guest User

Untitled

a guest
Dec 18th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.16 KB | None | 0 0
  1. # Ideas for testing
  2.  
  3. This document outlines some ideas for testing, specifically related to Crust.
  4.  
  5. ## Isolated network simulator library
  6.  
  7. Our current test suites for Crust and p2p are woefully inadequate. For
  8. instance, there isn't (currently) any way to test whether our hole-punching
  9. code actually works at all without having two people manually test it over the
  10. internet. Nor is there any way to automatically test whether Crust can
  11. correctly handle packet loss, packet reordering etc. Routing even has its own
  12. mock version of Crust which it uses for testing, leading to extra code to
  13. maintain and test results that are potentially meaningless. Luckily there's a
  14. solution to all this.
  15.  
  16. It's possible to write a Rust library that allows launching a thread into its
  17. own isolated network environment where it only has access to a virtual network
  18. interface. From outside the thread we can then read/write packets directly
  19. to/from this interface in order to introduce latency, packet loss, or any other
  20. form of communications-mangling. Using iptables we can also set up these
  21. threads with their own NAT rules.
  22.  
  23. To showcase what I'm talking about, we could use this library to write test
  24. cases that look something like this:
  25.  
  26. ```rust
  27. // Example Crust test
  28. #[test]
  29. fn test_connect_to_peers() {
  30. let (tx, rx) = mpsc::oneshot();
  31.  
  32. internet_simulator::run(&[
  33. || {
  34. let service = Service::new();
  35. service.start_listening();
  36. let addr = expect_event!(service, Event::ListenerStarted(addr) => addr);
  37. tx.send(addr);
  38. let peer = expect_event!(service, Event::BootstrapAccept(peer) => peer);
  39.  
  40. // we connected! now exchange data or something.
  41. },
  42. || {
  43. let service = Service::new();
  44. let addr = rx.recv();
  45. service.add_contact(addr);
  46. service.bootstrap();
  47. let peer = expect_event!(service, Event::BootstrapConnect(peer) => peer);
  48.  
  49. // we connected! now exchange data or something.
  50. },
  51. ]);
  52. }
  53. ```
  54.  
  55. In the above code, the two Crust services would each have their own IP address,
  56. be behind their own NAT, and be communicating over a lossy connection with
  57. latency. This would be a *much* more effective test than what we currently do
  58. in Crust (which is just have peers talk to each other over loopback).
  59.  
  60. Once we can run Crust nodes in their own isolated environments like this we
  61. would also be able to do away with mock-crust in routing. Test cases could
  62. simply set up their own virtual networks like this.
  63.  
  64. I have already have a basic proof-of-concept of this working. It's Linux-only
  65. and isn't yet fully developed so you can't spin up a virtual internet with a
  66. single command, but all the essentials are in-place. It just needs man-hours
  67. put into it.
  68.  
  69. ## Router probing tool
  70.  
  71. Routers in the wild exhibit all kind of wierd and wacky behaviours which effect
  72. our ability to hole-punch and reliably maintain a connection. It would be good
  73. if we could catalogue these behaviours and their prevalence. This would help us
  74. know how Crust could be improved and how urgently certain improvements may be
  75. needed.
  76.  
  77. A way to do this cataloguing would be to release a tool to our users which runs
  78. a set of tests while communicating with a set of external servers, then reports
  79. the test results back to us. Eventually, some form of this test could be
  80. integrated into the p2p library in order to avoid the need for the user to
  81. do their own manual configuration.
  82.  
  83. ## Automated soak testing
  84.  
  85. When testing uTP I found bugs that would only start occuring after sending
  86. hundreds of megabytes over a connection. It's not possible to test for these
  87. kinds of bugs in our current automated tests because these tests need to be
  88. fairly fast - we don't want to lock-up Travis for several hours every time we
  89. push a commit. However it would be good if we had *some* way to automatically
  90. run tests like this.
  91.  
  92. My suggestion is to add a different kind of test to our crates, labelled
  93. `#[soak_test]`, which are designed to run forever. We then set-aside a machine
  94. somewhere, presumably in the MaidSAFE office, which automatically stays
  95. up-to-date with master on all our github repositories, finds these tests, and
  96. keeps them running 24/7.
Add Comment
Please, Sign In to add comment