Add Bazel unit test target and Windows (MSVC) support#510
Conversation
|
This is a very good addition, thank you for taking care of that. There is one issue that I didn't notice at first. I tried importing This works fine as long as I don't use OpenSSL. However, when I enable OpenSSL, I get linker errors. I managed to solve the problem by linking against the libraries that provide the missing functions: I was wondering what the proper solution to this problem would be. I feel like it makes sense to link these libraries in |
|
I also noticed that you included some unit tests that can run in the test environment. What would be the recommended approach for handling non-hermetic E2E tests? Do you think we should split them into a separate executable and run it directly with |
Summary
Follow-up to #501, in two parts:
cc_testtarget covering the server-independent subset of the existing googletest suite inut/, wired into the Bazel CI workflow.windows-latestis added to the CI matrix. MSVC is the toolchain here because it is what Bazel supports on Windows — Bazel has no MinGW support (unlike the CMake build, which has a separate MinGW CI workflow), so the existingWindows mingwcoverage remains CMake-only.Part 1: Unit tests
ut/BUILD.bazel//ut:unit_testscc_test targetMODULE.bazelgoogletest 1.17.0.bcr.2from BCR, markeddev_dependency = Trueso library consumers never pull it in.github/workflows/bazel.ymlbazel test //ut:unit_testsstep on the matrixTest selection — only tests that run hermetically, i.e. no running ClickHouse server required:
types_ut,type_parser_ut,columns_ut,column_array_ut,block_ut,itemview_ut,stream_ut,utils_ut,CreateColumnByType_ut, plussocket_ut(spins up its ownLocalTcpServeron localhost, which works inside the Bazel test sandbox), together with the shared support code (utils.cpp,value_generators.cpp,tcp_server.cpp) and the gtestmain.cpp.$CLICKHOUSE_HOST—client_ut,roundtrip_tests,Column_ut,low_cardinality_nullable_tests,array_of_low_cardinality_tests,abnormal_column_names_test,readonly_client_test,connection_failed_client_test,performance_tests,ssl_ut. These keep running in the CMake CI, which provides a server via docker-compose. Running them under Bazel (e.g. with a dockerized server fixture) could be a future follow-up.The split is documented in a comment at the top of
ut/BUILD.bazel.googletestis adev_dependency, so it does not participate in version resolution for downstream consumers — it only exists when this module is the root.Part 2: Windows support
Adding
windows-latestto the matrix surfaced that the Bazel build didn't link on Windows except by luck:tls=noandtls=opensslfailed withLNK2019: unresolved external symbol __imp_ntohl / __imp_socket / ...— the Winsock library was never declared.tls=boringsslonly worked because BoringSSL's own BUILD file propagatesws2_32to its dependents.Fixes, mirroring what the CMake build already does:
BUILD.bazellinkopts:-DEFAULTLIB:ws2_32.libon WindowsIF (WIN32 OR MINGW) TARGET_LINK_LIBRARIES(... wsock32 ws2_32)ut/BUILD.bazel/bigobjon WindowsIF (MSVC) TARGET_COMPILE_OPTIONS(... /bigobj)MODULE.bazelplatforms 1.1.0(for@platforms//os:windowsinselect())Notably, the BCR
opensslmodule itself compiled cleanly under MSVC — the failure was purely the missing Winsock declaration in this repo's BUILD file.CI
The Bazel workflow matrix is now 3 OS × 3 TLS modes = 9 combinations (Linux, macOS, Windows ×
boringssl,openssl,no), each running build + unit tests. All 9 are green on this branch.Test plan
bazel test //ut:unit_testspasses locally on darwin-arm64 for all three TLS modes: 192 tests, 191 passed, 1 skipped by design (Socketcase.connecttimeout), 1 pre-existingDISABLEDtest.