[test] Refactor ZMQ test to use one address per notification type #11439

pull promag wants to merge 1 commits into bitcoin:master from promag:2017-10-clean-zmq-test changing 1 files +54 −78
  1. promag commented at 9:29 PM on October 2, 2017: member

    With this change it is possible to test the notifications independently, regardless of the publishing order, since each notification type is published to a different address.

    Took the opportunity to do some cleanup with the help of:

    • Subscriber class to keep the subscriber metadata and sequence state;
    • ZMQTest.subscribe which creates and registers the new subscriber and setups the socket;
    • ZMQTest.receive which does the normal asserts upon reading from the socket;

    Also changed 10 to 5 blocks to speed up the test.

  2. promag commented at 9:30 PM on October 2, 2017: member

    In #10286 the commit Fix zmq tests now that txn/blocks are unordered (04feed) can be removed after this is merged. cc @TheBlueMatt

  3. [test] Refactor ZMQ test to use one address per notification type
    With this change it is possible to test the notifications independently,
    regardless of the publishing order, since each notification type is published
    to a different address.
    7e0ee167dc
  4. promag force-pushed on Oct 2, 2017
  5. TheBlueMatt commented at 9:35 PM on October 2, 2017: member

    Hmm, I removed the commit in question from #10286 (replaced with https://github.com/bitcoin/bitcoin/pull/10286/commits/fdfd31355bfd1401c60e1ff3ec581d8f3ff29291). Its really unclear to me what the ZMQ API is, even - its not defined anywhere if clients should or should not rely on the ordering here. The fact that it was possible for our test to implies to me that we should maybe keep the ordering consistent, but I'm open to someone doing the work to document an stable API with or without a consistent ordering.

  6. promag commented at 9:40 PM on October 2, 2017: member

    There is no order guarantee and as such the clients can't and shouldn't rely on that - that's why the type is the first piece in each message. IMO we should avoid the ordering in the test because it is a bad example on how to subscribe and process the notifications.

  7. fanquake added the label Tests on Oct 2, 2017
  8. promag commented at 10:06 PM on October 2, 2017: member

    After some discussion with @TheBlueMatt on IRC we came to the conclusion that there should be an improvement to the ZMQ interface documentation regarding all notifications, respective payloads and guarantees.

  9. in test/functional/zmq_test.py:16 in 7e0ee167dc
      12 | @@ -13,14 +13,39 @@
      13 |                                   hash256,
      14 |                                  )
      15 |  
      16 | -class ZMQTest (BitcoinTestFramework):
      17 | +class Subscriber():
    


    jnewbery commented at 4:02 PM on October 3, 2017:

    nit: prefer ZMQSubscriber


    promag commented at 5:37 PM on October 3, 2017:

    Ok.


    ryanofsky commented at 2:17 PM on October 4, 2017:

    Unnecessary parentheses.

  10. in test/functional/zmq_test.py:28 in 7e0ee167dc
      24 |      def set_test_params(self):
      25 |          self.num_nodes = 2
      26 | +        self.subscribers = {}
      27 | +
      28 | +    def subscribe(self, type):
      29 | +        import zmq
    


    jnewbery commented at 4:30 PM on October 3, 2017:

    Why not move this logic into ZMQSubscriber.__init__()? Then you'd just need to pass in self.zmqContext. Port could be taken from a class variable to ensure uniqueness.


    promag commented at 5:39 PM on October 3, 2017:

    ZMQSubscriber is like a C++ POD, did't want to have logic there. Is this a strong suggestion?


    jnewbery commented at 5:53 PM on October 3, 2017:

    It makes more sense to me to have ZMQSubscriber handle the initialization logic (and also preferably the receive logic). That makes it more portable if for some reason we want to use the interface in another test.

    Conceptually it doesn't make sense to me to have a TestFramework object subscribing to a zmq interface. Owning ZMQ subscribers makes more sense to me.

  11. jnewbery commented at 4:38 PM on October 3, 2017: member

    Concept ACK. I like the refactor and placing the repeated checking logic into its own method. A couple of nits inline.

    However, this doesn't actually do what I was expecting, which is remove the assumptions about ordering. I was expecting the ZMQ subscribers to be able to receive the notifications asynchronously (perhaps using something like https://github.com/bitcoin/bitcoin/blob/master/contrib/zmq/zmq_sub.py) so that ordering of notifications doesn't matter.

  12. promag commented at 5:40 PM on October 3, 2017: member
  13. jonasschnelli assigned MarcoFalke on Oct 4, 2017
  14. ryanofsky commented at 2:21 PM on October 4, 2017: member

    I like the Subscriber class and subscribe/receive methods here which eliminate so much boilerplate in the test. But I unless I'm missing something I think you need to go back to receiving the messages over a single channel instead of 4 channels if your actual goal is to make it "possible to test the notifications independently, regardless of the publishing order."

    Otherwise it seems like this change is does the exact opposite of what you are claiming. If you are using a single channel, it's easy to read n messages, sort them, and make sure you've gotten the information you expected regardless of ordering. But if you have 4 channels, you either need to (1) create threads or coroutines or asynchronous callbacks to check incoming messages on each channel or (2) demultiplex 4 channels back into a single channel so you can take the sorting approach. Simplicity can be a matter of perspective, but I don't either of these approaches is simpler than just using a single channel.

  15. jnewbery commented at 2:25 PM on October 4, 2017: member

    Useful discussion of zmq notification ordering here: https://botbot.me/freenode/bitcoin-core-dev/2017-10-03/?msg=91859584&page=1

    I still think this PR could be a useful simplification in the test code.

  16. promag commented at 2:50 PM on October 4, 2017: member

    This is controversial and unneeded at the moment, as @TheBlueMatt said, the current order (although not documented) will not change and this test (as it is in master) helps to verify it.

    Therefore I'm closing this and I'll submit another with the cleanup and another with improved ZMQ interface documentation.

  17. promag closed this on Oct 4, 2017

  18. laanwj referenced this in commit 02ac8c892b on Oct 18, 2017
  19. PastaPastaPasta referenced this in commit fa9ecedb3a on Dec 22, 2019
  20. PastaPastaPasta referenced this in commit 2a633bdf83 on Jan 2, 2020
  21. PastaPastaPasta referenced this in commit d9a22ee1ff on Jan 4, 2020
  22. PastaPastaPasta referenced this in commit 1c0ce972af on Jan 12, 2020
  23. PastaPastaPasta referenced this in commit 7bd96317f5 on Jan 12, 2020
  24. PastaPastaPasta referenced this in commit 97ef3db0bf on Jan 12, 2020
  25. PastaPastaPasta referenced this in commit 245cbbbc21 on Jan 12, 2020
  26. PastaPastaPasta referenced this in commit 258bf99f73 on Jan 12, 2020
  27. PastaPastaPasta referenced this in commit 8ce540d588 on Jan 12, 2020
  28. PastaPastaPasta referenced this in commit 81ebfb7f76 on Jan 16, 2020
  29. ckti referenced this in commit 1270e2888b on Mar 28, 2021
  30. DrahtBot locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-22 00:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me