[qa] assert_start_raises_init_error #9832

pull NicolasDorier wants to merge 1 commits into bitcoin:master from NicolasDorier:assert_start_raises_init_error changing 2 files +29 −2
  1. NicolasDorier commented at 7:23 am on February 23, 2017: contributor

    assert_start_raises_init_error make it possible to test expected error condition when bitcoind is starting.

    ping @MarcoFalke and @jonasschnelli mentioned the need on #9662 and https://github.com/bitcoin/bitcoin/pull/9728

  2. NicolasDorier force-pushed on Feb 23, 2017
  3. NicolasDorier force-pushed on Feb 23, 2017
  4. laanwj added the label Tests on Feb 23, 2017
  5. jonasschnelli commented at 3:32 pm on March 3, 2017: contributor
    Thanks. utACK 5737be099f83dfb367a342c36f7f0ae5ea31bc29. This is also required for #9662.
  6. in qa/rpc-tests/test_framework/util.py: in 5737be099f outdated
    338@@ -338,7 +339,10 @@ def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary=
    339         binary = os.getenv("BITCOIND", "bitcoind")
    340     args = [ binary, "-datadir="+datadir, "-server", "-keypool=1", "-discover=0", "-rest", "-mocktime="+str(get_mocktime()) ]
    341     if extra_args is not None: args.extend(extra_args)
    342-    bitcoind_processes[i] = subprocess.Popen(args)
    343+    if stderr is not None:
    


    jnewbery commented at 8:22 pm on March 3, 2017:
    I don’t think this if/else construction is needed. subprocess.Popen’s stderr argument defaults to None, so you can just call bitcoind_processes[i] = subprocess.Popen(args, stderr=stderr)
  7. in qa/rpc-tests/test_framework/util.py: in 5737be099f outdated
    364+        if expected_msg is None:
    365+            assert_msg = "bitcoind should have exited with an error"
    366+        else:
    367+            assert_msg = "bitcoind should have exited with expected error " + expected_msg
    368+        raise AssertionError(assert_msg)
    369+    except AssertionError as e:
    


    jnewbery commented at 8:25 pm on March 3, 2017:

    yuck! raising an exception in expectation of catching it in the very next line.

    I think try/except/else is a much cleaner construction, as in:

    0try:
    1    thing_we_expect_to_fail()
    2except ExceptionType as e:
    3    do_some_asserts_on_the_exception_raised()
    4else:
    5    # oops, we were expecting an exception
    6    assert False, "we were expecting an exception!"
    
  8. in qa/rpc-tests/test_framework/util.py: in 5737be099f outdated
    355@@ -352,6 +356,28 @@ def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary=
    356 
    357     return proxy
    358 
    359+def assert_start_raises_init_error(i, dirname, extra_args=None, expected_msg=None):
    360+    log_stderr = tempfile.SpooledTemporaryFile(max_size=2**16)
    


    jnewbery commented at 8:29 pm on March 3, 2017:
    Consider opening the file using the with log_stderr as... form. That means the file will be closed automatically (even if an exception is raised on the way), and you won’t have to close it yourself with the finally branch at the bottom.
  9. in qa/rpc-tests/test_framework/util.py: in 5737be099f outdated
    367+            assert_msg = "bitcoind should have exited with expected error " + expected_msg
    368+        raise AssertionError(assert_msg)
    369+    except AssertionError as e:
    370+        raise
    371+    except Exception as e:
    372+        assert('bitcoind exited' in str(e)) #node must have shutdown
    


    jnewbery commented at 8:30 pm on March 3, 2017:

    minor nit: assert is a statement, not a function. This should be:

    assert ‘bitcoind exited’ in str(e)

  10. NicolasDorier force-pushed on Mar 5, 2017
  11. NicolasDorier force-pushed on Mar 5, 2017
  12. NicolasDorier commented at 4:51 pm on March 5, 2017: contributor
    nits of @jnewbery addressed
  13. MarcoFalke commented at 5:24 pm on March 5, 2017: member
    Please squash.
  14. NicolasDorier force-pushed on Mar 6, 2017
  15. [qa] assert_start_raises_init_error 025dec0e5b
  16. NicolasDorier force-pushed on Mar 6, 2017
  17. NicolasDorier commented at 8:22 am on March 6, 2017: contributor
    squashed @MarcoFalke
  18. laanwj merged this on Mar 6, 2017
  19. laanwj closed this on Mar 6, 2017

  20. laanwj referenced this in commit 48c3429c50 on Mar 6, 2017
  21. in qa/rpc-tests/test_framework/util.py: in 025dec0e5b
    352@@ -352,6 +353,25 @@ def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary=
    353 
    354     return proxy
    355 
    356+def assert_start_raises_init_error(i, dirname, extra_args=None, expected_msg=None):
    357+    with tempfile.SpooledTemporaryFile(max_size=2**16) as log_stderr:
    358+        try:
    359+            node = start_node(i, dirname, extra_args, stderr=log_stderr)
    360+            stop_node(node, i)
    


    MarcoFalke commented at 9:44 am on March 6, 2017:
    Nit: No need to stop the node here. This is done by the test framework.

    NicolasDorier commented at 11:20 am on March 6, 2017:

    It does need to be stopped, or this function would not be side effect free.

    EDIT: Ah no it does not, as if it passes here, the test is finished, which would close the node anyway.


    MarcoFalke commented at 11:43 am on March 6, 2017:
    Right this line is only executed in exceptional circumstances, in which case the whole frameworks shuts down.
  22. MarcoFalke commented at 9:44 am on March 6, 2017: member
    Post merge utACK 025dec0e5bf001ba297f7430affe4098627ea5ce
  23. PastaPastaPasta referenced this in commit 5c3060f35c on Dec 30, 2018
  24. PastaPastaPasta referenced this in commit c4f9e83d45 on Dec 31, 2018
  25. PastaPastaPasta referenced this in commit ea1dc5fad7 on Dec 31, 2018
  26. PastaPastaPasta referenced this in commit 1f5103dde2 on Dec 31, 2018
  27. PastaPastaPasta referenced this in commit 5c16a1cda9 on Jan 2, 2019
  28. PastaPastaPasta referenced this in commit 32b78893e6 on Jan 2, 2019
  29. PastaPastaPasta referenced this in commit a4f8477316 on Jan 3, 2019
  30. PastaPastaPasta referenced this in commit 99a0300307 on Jan 21, 2019
  31. PastaPastaPasta referenced this in commit 529a8b80c3 on Jan 25, 2019
  32. PastaPastaPasta referenced this in commit 2c0d397a28 on Jan 29, 2019
  33. PastaPastaPasta referenced this in commit 94f159819b on Jan 29, 2019
  34. PastaPastaPasta referenced this in commit c7cf788833 on Jan 29, 2019
  35. PastaPastaPasta referenced this in commit 296dcf97a4 on Feb 1, 2019
  36. PastaPastaPasta referenced this in commit 0a361ab4df on Feb 1, 2019
  37. PastaPastaPasta referenced this in commit 94dacd825c on Feb 1, 2019
  38. PastaPastaPasta referenced this in commit 47cb318b62 on Feb 1, 2019
  39. PastaPastaPasta referenced this in commit 092b6ed9a1 on Feb 1, 2019
  40. PastaPastaPasta referenced this in commit 56890f98f2 on Feb 1, 2019
  41. zkbot referenced this in commit b2ab91b032 on Mar 24, 2020
  42. zkbot referenced this in commit 38755ebc22 on Mar 24, 2020
  43. zkbot referenced this in commit da12da80c4 on Apr 2, 2020
  44. zkbot referenced this in commit 1be7250db9 on Apr 3, 2020
  45. MarcoFalke 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: 2024-11-22 09:12 UTC

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