tests: better combine_logs.py behavior #14683

pull jamesob wants to merge 1 commits into bitcoin:master from jamesob:2018-11-better-cons-log changing 2 files +51 −9
  1. jamesob commented at 5:11 PM on November 7, 2018: member

    Have combine_logs.py default to the most recent test directory if no argument is provided. This allows you to avoid an annoying copy-paste when iterating on a failing test, since you can do something like

    alias testlogs='./test/functional/combine_logs.py -c | less'
    
    ./test/functional/some_test.py  # fails
    testlogs
    
  2. DrahtBot commented at 8:26 PM on November 7, 2018: member

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    No conflicts as of last run.

  3. fanquake added the label Tests on Nov 7, 2018
  4. lucash-dev commented at 7:35 AM on November 9, 2018: contributor

    ACK. very useful!

  5. in test/functional/combine_logs.py:79 in e2d9b2fec8 outdated
      74 | +    testdir_paths = [
      75 | +        join_tmp(name) for name in os.listdir(tmpdir) if
      76 | +        os.path.isdir(join_tmp(name)) and is_test_dir_name(name)
      77 | +    ]
      78 | +
      79 | +    testdir_paths.sort(key=lambda x: os.path.getmtime(x), reverse=True)
    


    practicalswift commented at 8:05 AM on November 9, 2018:

    Isn't the lambda redundant here? Could use os.path.getmtime directly?


    ryanofsky commented at 9:53 PM on November 12, 2018:

    Doesn't hugely matter, but there's no need to build and sort a list if you just want the newest file, e.g.:

    newest = max((os.path.getmtime(f), f) for f in os.listdir("."))[1]
    
  6. laanwj commented at 2:28 PM on November 12, 2018: member

    Concept ACK—I think this functionality is very useful

    Though I'm not sure about security implications of opening everything that looks like a test directory in /tmp, say, on a multi-user system.

    Maybe add a check that the directory is owned by the current user as well?

  7. ryanofsky approved
  8. ryanofsky commented at 10:00 PM on November 12, 2018: member

    utACK e2d9b2fec809971de4cfc67048995e33e7e4749c, though I agree it would be good to check ownership.

  9. in test/functional/combine_logs.py:25 in e2d9b2fec8 outdated
      21 | @@ -19,22 +22,29 @@
      22 |  
      23 |  def main():
      24 |      """Main function. Parses args, reads the log files and renders them as text or html."""
      25 | -
      26 | -    parser = argparse.ArgumentParser(usage='%(prog)s [options] <test temporary directory>', description=__doc__)
      27 | +    parser = argparse.ArgumentParser(description=__doc__)
    


    jnewbery commented at 10:26 PM on November 21, 2018:

    nit: can you add formatter_class=argparse.RawTextHelpFormatter here. Otherwise the newlines from the docstring get squashed in the help text.

  10. in test/functional/combine_logs.py:32 in e2d9b2fec8 outdated
      30 | +        help=('temporary test directory to combine logs from. '
      31 | +              'Defaults to the most recent'))
      32 |      parser.add_argument('-c', '--color', dest='color', action='store_true', help='outputs the combined log with events colored by source (requires posix terminal colors. Use less -r for viewing)')
      33 |      parser.add_argument('--html', dest='html', action='store_true', help='outputs the combined log as html. Requires jinja2. pip install jinja2')
      34 | -    args, unknown_args = parser.parse_known_args()
      35 | +    args, _ = parser.parse_known_args()
    


    jnewbery commented at 10:35 PM on November 21, 2018:

    I think you can just change this to parser.parse_args() and drop the unused variable.

  11. in test/functional/combine_logs.py:45 in e2d9b2fec8 outdated
      47 | +        print("No test directories found")
      48 |          sys.exit(1)
      49 |  
      50 | -    log_events = read_logs(unknown_args[0])
      51 | +    if not args.testdir:
      52 | +        print("Opening latest test directory: {}".format(testdir))
    


    jnewbery commented at 10:38 PM on November 21, 2018:

    Can you drop this print, or print to stderr.

    (printing this is problematic when using the --html output option for example)

  12. jnewbery commented at 10:55 PM on November 21, 2018: member

    Big concept ACK. Very cool.

    A few nits inline. You should also address comments by laanwj, ryanofsky and practicalswift.

  13. practicalswift commented at 6:14 AM on November 22, 2018: contributor

    Concept ACK

    Nice developer ergonomics improvement!

  14. conscott commented at 9:53 AM on November 22, 2018: contributor

    Concept ACK woot!

  15. in test/functional/combine_logs.py:86 in e2d9b2fec8 outdated
      81 | +    return testdir_paths[0] if testdir_paths else None
      82 | +
      83 | +
      84 | +def is_test_dir_name(path):
      85 | +    """Returns True if the filename indicates a test directory."""
      86 | +    return re.match(r'test\S{8}$', os.path.basename(path))
    


    MarcoFalke commented at 5:56 PM on November 22, 2018:

    Instead of matching just on "test*", which is used by other programs (such as our unit test runner, IIRC), couldn't you instead explicitly set a unique (or approximately unique) prefix for the temp folder name in the test framework?


    laanwj commented at 9:01 AM on November 23, 2018:

    maybe match the silly unicode characters as well, they're very unlikely to arise anywhere else :)


    MarcoFalke commented at 8:37 PM on November 23, 2018:

    Oh, the unicode characters are only present when run through the test runner, in which case the tests are run in parallel, so this feature wouldn't turn out useful.

    If the tests are run one-each, they use a different prefix, so I suggest to change that prefix.


    jamesob commented at 4:07 PM on November 27, 2018:

    I've updated the test framework to share a TMPDIR_PREFIX constant which has a value of "bitcoin_func_test_".

  16. jamesob force-pushed on Nov 27, 2018
  17. jamesob commented at 4:09 PM on November 27, 2018: member

    Thanks for the good feedback, all. I've incorporated everyone's suggestions - though I'm testing for tmp directory readability instead of ownership.

  18. ryanofsky approved
  19. ryanofsky commented at 9:37 PM on November 27, 2018: member

    utACK ca9698e9075fb1b85afc01e890cef97e13d25405. Just minor tweaks since last review: changing test prefix, choosing last readble directory, changing help formatting and forbidding unknown options

  20. MarcoFalke commented at 10:05 PM on November 27, 2018: member

    utACK ca9698e9075fb1b85afc01e890cef97e13d25405

  21. MarcoFalke added this to the milestone 0.18.0 on Nov 27, 2018
  22. in test/functional/combine_logs.py:18 in ca9698e907 outdated
      12 | @@ -11,6 +13,9 @@
      13 |  import os
      14 |  import re
      15 |  import sys
      16 | +import tempfile
      17 | +
      18 | +from test_framework.test_framework import TMPDIR_PREFIX
    


    jnewbery commented at 3:10 PM on November 29, 2018:

    Can we remove this dependency? I have a combine_logs.py installed in a separate bin directory and it currently works as a standalone util. Adding this dependency breaks that.

    Perhaps just directly define TMPDIR_PREFIX as "bitcoin_func_test_" here. If you want to go wild, you could add a unit test that checks that TMPDIR_PREFIX is defined the same in both files.


    jnewbery commented at 3:17 PM on November 29, 2018:

    Perhaps also add a comment to warn people against importing from test_framework in here (or I can do it in a separate PR).


    jamesob commented at 11:39 PM on November 29, 2018:

    Fixed

  23. jnewbery commented at 3:18 PM on November 29, 2018: member

    Changes mostly look good, but please remove the dependency on test_framework

  24. tests: have combine_logs default to most recent test dir 4aabadbf44
  25. jamesob force-pushed on Nov 29, 2018
  26. jnewbery commented at 11:48 PM on November 29, 2018: member

    ACK 4aabadbf44ad8f14cfa3f8921caf3135515b9ecf. Thanks for removing the dependency!

  27. pull[bot] referenced this in commit 74254fea1e on Nov 30, 2018
  28. MarcoFalke merged this on Nov 30, 2018
  29. MarcoFalke closed this on Nov 30, 2018

  30. MarcoFalke commented at 3:51 PM on November 30, 2018: member

    re-utACK 4aabadb

  31. jasonbcox referenced this in commit c60eca0efa on Oct 7, 2020
  32. 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: 2026-04-27 21:14 UTC

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