当所有单独的测试都通过时,为啥我的 Bazel 测试报告失败?

Posted

技术标签:

【中文标题】当所有单独的测试都通过时,为啥我的 Bazel 测试报告失败?【英文标题】:Why does my Bazel test report failure when all individual tests are passing?当所有单独的测试都通过时,为什么我的 Bazel 测试报告失败? 【发布时间】:2019-06-25 06:36:21 【问题描述】:

当通过 Bazel 运行我的单元测试 (gtest) 时,我看到了一个失败报告。但是,日志表明我的测试运行成功并通过了。

我项目中的其他测试都通过了,异常测试与其他测试的唯一区别是异常测试是多线程的。

我自己运行了bazel-bin 中的测试二进制文件,它通过并成功返回。

Bazel 版本:

Build label: 0.26.0
Build target: bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Tue May 28 08:35:14 2019 (1559032514)
Build timestamp: 1559032514
Build timestamp as int: 1559032514

我的BUILD文件中的相关块:

cc_test(
  name = "DBControllerIntegration",
  srcs = ["dbcontroller_integration_test.cc"],
  deps = [
    "//src:db_ctl_lib",
    "//test/mocks:sstable_mock_lib",
    "@boost//:filesystem",
    "@com_google_protobuf//:protobuf",
    "@glog//:glog",
    "@googletest//:gtest_main",
  ],
  copts = ["-std=c++17"],
)

Bazel 测试失败输出:

>> bazel test //test:DBControllerIntegration --test_output=errors
INFO: Invocation ID: ccca8fa7-27a5-4c8c-badf-3f342934e4e5
INFO: Analysed target //test:DBControllerIntegration (0 packages loaded, 0 targets configured).
INFO: Found 1 test target...
FAIL: //test:DBControllerIntegration (see /home/tallen/.cache/bazel/_bazel_tallen/f087948e065d612174d90a43a5740198/execroot/diodb/bazel-out/k8-dbg/testlogs/test/DBControllerIntegration/test.log)
INFO: From Testing //test:DBControllerIntegration:
==================== Test output for //test:DBControllerIntegration:
Running main() from gmock_main.cc
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from DBControllerIntegrationTest
[ RUN      ] DBControllerIntegrationTest.Basic

... <omitting my application's logs> ...

[       OK ] DBControllerIntegrationTest.Basic (4000 ms)
[----------] 1 test from DBControllerIntegrationTest (4000 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (4001 ms total)
[  PASSED  ] 1 test.
================================================================================
Target //test:DBControllerIntegration up-to-date:
  bazel-bin/test/DBControllerIntegration
INFO: Elapsed time: 4.706s, Critical Path: 4.57s
INFO: 1 process: 1 processwrapper-sandbox.
INFO: Build completed, 1 test FAILED, 2 total actions
//test:DBControllerIntegration                                           FAILED in 4.6s
  /home/tallen/.cache/bazel/_bazel_tallen/f087948e065d612174d90a43a5740198/execroot/diodb/bazel-out/k8-dbg/testlogs/test/DBControllerIntegration/test.log

INFO: Build completed, 1 test FAILED, 2 total actions

自行运行测试二进制文件:

>> ./bazel-bin/test/DBControllerIntegration
Running main() from gmock_main.cc
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from DBControllerIntegrationTest
[ RUN      ] DBControllerIntegrationTest.Basic

... <omitting my application's logs> ...

[       OK ] DBControllerIntegrationTest.Basic (4001 ms)
[----------] 1 test from DBControllerIntegrationTest (4001 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (4001 ms total)
[  PASSED  ] 1 test.

我希望 Bazel 测试结果报告为通过,因为实际测试通过了,但我认为测试失败了。

【问题讨论】:

使用 --cache_test_results=no 运行 - 我猜一些 chaced 测试会导致这个错误 有趣的是,我现在在 Bazel 中看到了一个段错误:external/bazel_tools/tools/test/test-setup.sh: line 310: 14 Segmentation fault (core dumped) "$TEST_PATH" "$@" 2&gt;&amp;1 其他有此段错误的帖子似乎已经降级了 Bazel,但这并不是真正的解决方案。我正在用我的 Bazel 版本更新帖子。 【参考方案1】:

当优雅地终止我的项目产生的所有线程时,此问题已得到解决。

【讨论】:

以上是关于当所有单独的测试都通过时,为啥我的 Bazel 测试报告失败?的主要内容,如果未能解决你的问题,请参考以下文章

为啥我的自动化测试在一起运行时会失败,但单独通过?

为啥我的添加好友测试路由在 insomina 中通过了 200 OK,但是当我调用获取所有用户时它没有嵌套?

当所有测试一起运行时,Android Instrumented 测试失败

我的摩卡测试单独工作,但一次运行时失败

一个测试容器用于多个测试

为啥当我的着色器文件的所有信息都正确读入字符串并且语法正确时,OpenGL会给出语法错误