【问题标题】:How to get all task results in Bazel output如何在 Bazel 输出中获取所有任务结果
【发布时间】:2021-09-29 07:41:24
【问题描述】:

我在 CI 中运行 Bazel(通过 Bazelisk)并努力从构建中获得合理的输出。我希望在输出中看到 所有 测试和/或目标的结果(即使它们是由缓存完成的),以便开发人员可以确定他们所写的东西正在被测试。

最明显的事情是设置--show_task_finish 标志,但不幸的是that flag doesn't seem to work。我还没有找到任何可以可靠地打印出测试或目标结果的标志。不幸的是,我无法从通过的测试中打印 stdout/stderr,因为它们产生了太多的输出。

例如,如果我想确定某个特定目标已经过测试,我最近遇到的一些稍微编辑过的输出几乎完全没用:

bazel test //...
(23:19:36) INFO: Options provided by the client:
  Inherited 'common' options: --isatty=0 --terminal_columns=0
(23:19:36) INFO: Reading rc options for 'test' from /home/bazelisk/project/.bazelrc:
  Inherited 'common' options: --attempt_to_print_relative_paths --show_timestamps --experimental_allow_tags_propagation
(23:19:36) INFO: Reading rc options for 'test' from /home/bazelisk/.bazelrc:
  Inherited 'common' options: --color=yes --curses=no --show_progress_rate_limit=0.25 --show_task_finish --announce_rc
(23:19:36) INFO: Reading rc options for 'test' from /home/bazelisk/project/.bazelrc:
  Inherited 'build' options: --keep_going --verbose_failures --local_cpu_resources=HOST_CPUS*0.5 --local_ram_resources=HOST_RAM*0.5
(23:19:36) INFO: Reading rc options for 'test' from /home/bazelisk/.bazelrc:
  Inherited 'build' options: --local_cpu_resources=HOST_CPUS --local_ram_resources=HOST_RAM*.67
(23:19:36) INFO: Reading rc options for 'test' from /home/bazelisk/project/.bazelrc:
  'test' options: --test_output=errors --test_summary=detailed --test_env=LANG=en_US.utf8 --test_env=LOCALE_ARCHIVE
(23:19:36) INFO: Reading rc options for 'test' from /home/bazelisk/.bazelrc:
  'test' options: --test_verbose_timeout_warnings
(23:19:36) INFO: Current date is <blah>
(23:19:36) Loading: 
(23:19:36) Loading: 0 packages loaded
(23:19:47) Analyzing: 48 targets (0 packages loaded)
(23:19:47) INFO: Build option --test_env has changed, discarding analysis cache.
(23:19:47) Analyzing: 48 targets (0 packages loaded, 0 targets configured)
(23:19:48) INFO: Analyzed 48 targets (0 packages loaded, 13812 targets configured).
(23:19:48) INFO: Found 25 targets and 23 test targets...
(23:19:48) [0 / 3] [Prepa] BazelWorkspaceStatusAction stable-status.txt
(23:19:50) [2,529 / 2,551] 2 / 23 tests; Testing // ... (22 actions running)
(23:19:53) [2,532 / 2,551] 5 / 23 tests; Testing // ... (19 actions running)
(23:19:56) [2,533 / 2,551] 5 / 23 tests; Testing // ... (18 actions running)
(23:19:59) [2,534 / 2,551] 6 / 23 tests; Testing // ... (17 actions running)
(23:20:05) [2,535 / 2,551] 8 / 23 tests; Testing // ... (16 actions running)
(23:20:11) [2,536 / 2,551] 8 / 23 tests; Testing // ... (15 actions running)
(23:20:16) [2,539 / 2,551] 11 / 23 tests; Testing // ... (12 actions running)
(23:20:22) [2,541 / 2,551] 14 / 23 tests; Testing // ... (10 actions running)
(23:20:32) [2,544 / 2,551] 17 / 23 tests; Testing // ... (7 actions running)
(23:20:44) [2,546 / 2,551] 18 / 23 tests; Testing // ... (5 actions running)
(23:20:54) [2,546 / 2,551] 18 / 23 tests; Testing // ... (5 actions running)
(23:21:06) [2,547 / 2,551] 19 / 23 tests; Testing // ... (4 actions running)
(23:21:29) [2,549 / 2,551] 21 / 23 tests; Testing // ... (2 actions running)
(23:21:59) [2,549 / 2,551] 21 / 23 tests; Testing // ... (2 actions running)
(23:22:27) [2,549 / 2,551] 21 / 23 tests; Testing // ... (2 actions running)
(23:22:50) INFO: Elapsed time: 193.959s, Critical Path: 181.09s
(23:22:50) INFO: 24 processes: 24 processwrapper-sandbox.
(23:22:50) INFO: Build completed successfully, 24 total actions
Test cases: finished with 417 passing and 0 failing out of 417 test cases

Executed 23 out of 23 tests: 23 tests pass.
(23:22:50) INFO: Build completed successfully, 24 total actions

CircleCI received exit code 0

为方便起见,此运行的完全扩展标志如下所示:

bazel test \
  --announce_rc \
  --attempt_to_print_relative_paths \
  --color=yes \
  --curses=no \
  --experimental_allow_tags_propagation \
  --isatty=0 \
  --keep_going \
  --local_cpu_resources=HOST_CPUS \
  --local_ram_resources=HOST_RAM*.67 \
  --show_progress_rate_limit=0.25 \
  --show_task_finish \
  --show_timestamps \
  --terminal_columns=0 \
  --test_env=LANG=en_US.utf8 \
  --test_env=LOCALE_ARCHIVE \
  --test_output=errors \
  --test_summary=detailed \
  --test_verbose_timeout_warnings \
  --verbose_failures \
  //...

【问题讨论】:

    标签: bazel


    【解决方案1】:

    --show_result=1000000 将显示所有目标(使数字尽可能大以包括所有目标)。不过,这往往是很多输出。另请注意,对于测试,它表示测试二进制文件已构建,而不是已运行。

    --test_summary=short 是打印每个测试信息的方式。

    【讨论】:

    • 我会试一试,不敢相信我错过了short 摘要如果测试通过,可能会提供更多信息。
    【解决方案2】:

    看起来像--test_summary=detailed,Bazel 仅打印有关失败测试的信息:https://docs.bazel.build/versions/main/command-line-reference.html#flag--test_summary

    short 的默认值用于--test_summary 会给出所有目标:

    $ for i in $(seq 50); do echo "exit 0" > test$i.sh; done
    $ chmod +x *.sh
    $ for i in $(seq 50); do echo "sh_test(
      name = 'test$i',
      srcs = ['test$i.sh'],
    )" >> BUILD; done
    

    detailed:

    $ bazel test //... --test_summary=detailed
    Starting local Bazel server and connecting to it...
    INFO: Analyzed 50 targets (24 packages loaded, 380 targets configured).
    INFO: Found 50 test targets...
    INFO: Elapsed time: 10.812s, Critical Path: 0.33s
    INFO: 201 processes: 101 internal, 100 linux-sandbox.
    INFO: Build completed successfully, 201 total actions
    Test cases: finished with 50 passing and 0 failing out of 50 test cases
    
    Executed 50 out of 50 tests: 50 tests pass.
    INFO: Build completed successfully, 201 total actions
    

    short:

    $ bazel test //... --test_summary=short
    INFO: Analyzed 50 targets (0 packages loaded, 0 targets configured).
    INFO: Found 50 test targets...
    INFO: Elapsed time: 0.162s, Critical Path: 0.02s
    INFO: 1 process: 1 internal.
    INFO: Build completed successfully, 1 total action
    //:test1                                                        (cached) PASSED in 0.1s
    //:test10                                                       (cached) PASSED in 0.1s
    //:test11                                                       (cached) PASSED in 0.1s
    //:test12                                                       (cached) PASSED in 0.0s
    //:test13                                                       (cached) PASSED in 0.1s
    //:test14                                                       (cached) PASSED in 0.1s
    //:test15                                                       (cached) PASSED in 0.1s
    //:test16                                                       (cached) PASSED in 0.1s
    //:test17                                                       (cached) PASSED in 0.1s
    //:test18                                                       (cached) PASSED in 0.1s
    //:test19                                                       (cached) PASSED in 0.1s
    //:test2                                                        (cached) PASSED in 0.1s
    //:test20                                                       (cached) PASSED in 0.0s
    //:test21                                                       (cached) PASSED in 0.1s
    //:test22                                                       (cached) PASSED in 0.1s
    //:test23                                                       (cached) PASSED in 0.1s
    //:test24                                                       (cached) PASSED in 0.1s
    //:test25                                                       (cached) PASSED in 0.1s
    //:test26                                                       (cached) PASSED in 0.1s
    //:test27                                                       (cached) PASSED in 0.1s
    //:test28                                                       (cached) PASSED in 0.1s
    //:test29                                                       (cached) PASSED in 0.1s
    //:test3                                                        (cached) PASSED in 0.0s
    //:test30                                                       (cached) PASSED in 0.1s
    //:test31                                                       (cached) PASSED in 0.1s
    //:test32                                                       (cached) PASSED in 0.1s
    //:test33                                                       (cached) PASSED in 0.1s
    //:test34                                                       (cached) PASSED in 0.1s
    //:test35                                                       (cached) PASSED in 0.1s
    //:test36                                                       (cached) PASSED in 0.2s
    //:test37                                                       (cached) PASSED in 0.0s
    //:test38                                                       (cached) PASSED in 0.1s
    //:test39                                                       (cached) PASSED in 0.1s
    //:test4                                                        (cached) PASSED in 0.1s
    //:test40                                                       (cached) PASSED in 0.0s
    //:test41                                                       (cached) PASSED in 0.1s
    //:test42                                                       (cached) PASSED in 0.1s
    //:test43                                                       (cached) PASSED in 0.1s
    //:test44                                                       (cached) PASSED in 0.0s
    //:test45                                                       (cached) PASSED in 0.1s
    //:test46                                                       (cached) PASSED in 0.1s
    //:test47                                                       (cached) PASSED in 0.0s
    //:test48                                                       (cached) PASSED in 0.1s
    //:test49                                                       (cached) PASSED in 0.1s
    //:test5                                                        (cached) PASSED in 0.1s
    //:test50                                                       (cached) PASSED in 0.1s
    //:test6                                                        (cached) PASSED in 0.1s
    //:test7                                                        (cached) PASSED in 0.1s
    //:test8                                                        (cached) PASSED in 0.1s
    //:test9                                                        (cached) PASSED in 0.1s
    
    Executed 0 out of 50 tests: 50 tests pass.
    INFO: Build completed successfully, 1 total action
    

    detailed 和测试失败:

    $ bazel test //... --test_summary=detailed
    INFO: Analyzed 50 targets (0 packages loaded, 0 targets configured).
    INFO: Found 50 test targets...
    FAIL: //:test2 (see /home/ahumesky/.cache/bazel/_bazel_ahumesky/d7e5f46ce97861928779430e418f94f3/execroot/__main__/bazel-out/k8-fastbuild/testlogs/test2/test.log)
    INFO: Elapsed time: 0.124s, Critical Path: 0.04s
    INFO: 2 processes: 2 linux-sandbox.
    INFO: Build completed, 1 test FAILED, 2 total actions
    //:test2                                                                 FAILED in 0.0s
        ERROR   .test2 (0.0s)
    Test cases: finished with 49 passing and 1 failing out of 50 test cases
    
    Executed 1 out of 50 tests: 49 tests pass and 1 fails locally.
    INFO: Build completed, 1 test FAILED, 2 total actions
    
    

    short 和测试失败:

    $ bazel test //... --test_summary=short
    INFO: Analyzed 50 targets (0 packages loaded, 0 targets configured).
    INFO: Found 50 test targets...
    FAIL: //:test2 (see /home/ahumesky/.cache/bazel/_bazel_ahumesky/d7e5f46ce97861928779430e418f94f3/execroot/__main__/bazel-out/k8-fastbuild/testlogs/test2/test.log)
    INFO: Elapsed time: 0.164s, Critical Path: 0.06s
    INFO: 2 processes: 2 linux-sandbox.
    INFO: Build completed, 1 test FAILED, 2 total actions
    //:test1                                                        (cached) PASSED in 0.1s
    //:test10                                                       (cached) PASSED in 0.1s
    //:test11                                                       (cached) PASSED in 0.1s
    //:test12                                                       (cached) PASSED in 0.0s
    //:test13                                                       (cached) PASSED in 0.1s
    //:test14                                                       (cached) PASSED in 0.1s
    //:test15                                                       (cached) PASSED in 0.1s
    //:test16                                                       (cached) PASSED in 0.1s
    //:test17                                                       (cached) PASSED in 0.1s
    //:test18                                                       (cached) PASSED in 0.1s
    //:test19                                                       (cached) PASSED in 0.1s
    //:test20                                                       (cached) PASSED in 0.0s
    //:test21                                                       (cached) PASSED in 0.1s
    //:test22                                                       (cached) PASSED in 0.1s
    //:test23                                                       (cached) PASSED in 0.1s
    //:test24                                                       (cached) PASSED in 0.1s
    //:test25                                                       (cached) PASSED in 0.1s
    //:test26                                                       (cached) PASSED in 0.1s
    //:test27                                                       (cached) PASSED in 0.1s
    //:test28                                                       (cached) PASSED in 0.1s
    //:test29                                                       (cached) PASSED in 0.1s
    //:test3                                                        (cached) PASSED in 0.0s
    //:test30                                                       (cached) PASSED in 0.1s
    //:test31                                                       (cached) PASSED in 0.1s
    //:test32                                                       (cached) PASSED in 0.1s
    //:test33                                                       (cached) PASSED in 0.1s
    //:test34                                                       (cached) PASSED in 0.1s
    //:test35                                                       (cached) PASSED in 0.1s
    //:test36                                                       (cached) PASSED in 0.2s
    //:test37                                                       (cached) PASSED in 0.0s
    //:test38                                                       (cached) PASSED in 0.1s
    //:test39                                                       (cached) PASSED in 0.1s
    //:test4                                                        (cached) PASSED in 0.1s
    //:test40                                                       (cached) PASSED in 0.0s
    //:test41                                                       (cached) PASSED in 0.1s
    //:test42                                                       (cached) PASSED in 0.1s
    //:test43                                                       (cached) PASSED in 0.1s
    //:test44                                                       (cached) PASSED in 0.0s
    //:test45                                                       (cached) PASSED in 0.1s
    //:test46                                                       (cached) PASSED in 0.1s
    //:test47                                                       (cached) PASSED in 0.0s
    //:test48                                                       (cached) PASSED in 0.1s
    //:test49                                                       (cached) PASSED in 0.1s
    //:test5                                                        (cached) PASSED in 0.1s
    //:test50                                                       (cached) PASSED in 0.1s
    //:test6                                                        (cached) PASSED in 0.1s
    //:test7                                                        (cached) PASSED in 0.1s
    //:test8                                                        (cached) PASSED in 0.1s
    //:test9                                                        (cached) PASSED in 0.1s
    //:test2                                                                 FAILED in 0.0s
      /home/ahumesky/.cache/bazel/_bazel_ahumesky/d7e5f46ce97861928779430e418f94f3/execroot/__main__/bazel-out/k8-fastbuild/testlogs/test2/test.log
    
    Executed 1 out of 50 tests: 49 tests pass and 1 fails locally.
    INFO: Build completed, 1 test FAILED, 2 total actions
    

    【讨论】:

    • 不敢相信我错过了short 可能比detailed 提供更多信息。谢谢!
    【解决方案3】:

    build event protocol 提供您需要的所有数据。

    BuildBuddy 等工具可以为您可视化构建事件协议。

    来自 BuildBuddy 的屏幕截图:

    BuildBuddy 例如显示所有测试以及相应的测试结果。您可以单击每个单独的测试并查看相应的日志:

    构建事件协议提供实时流。这样谁可以为您的开发人员提供实时构建/测试信息。

    还有一个来自 EngFlow 的商业专用解决方案,称为 Build Dashboard

    【讨论】:

    • 这看起来真的很酷!目前,我们与 CI 的不同技术密切相关,但如果我们使用主要是 Bazel 的构建设置,我一定会牢记这一点。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多