GH-49783: [C++][FlightRPC][ODBC] Reuse connections across test suite#49784
GH-49783: [C++][FlightRPC][ODBC] Reuse connections across test suite#49784justing-bq wants to merge 1 commit intoapache:mainfrom
Conversation
Co-Authored-By: Alina (Xi) Li <96995091+alinaliBQ@users.noreply.github.com>
|
|
There was a problem hiding this comment.
Pull request overview
This PR refactors the Flight SQL ODBC C++ test suite to reuse ODBC environment/connection handles across the entire test run (global SetUp/TearDown), reducing connect/disconnect churn that can crash tests on Linux.
Changes:
- Introduces shared handle pools (remote/mock, ODBC v2/v3, plus “non-connection” handles) and rewires fixtures to point
env/conn/stmtat the appropriate shared handles. - Moves remote/mock connection establishment into a global
::testing::Environmentand updates helper APIs (Connect,Disconnect, etc.) to accept explicit handle references. - Adjusts a few tests to use the new connection helper signature and adds a Windows-only CMake source tweak.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| cpp/src/arrow/flight/sql/odbc/tests/odbc_test_suite.h | Adds shared handle structs/pools and updates test base APIs to take explicit handles. |
| cpp/src/arrow/flight/sql/odbc/tests/odbc_test_suite.cc | Implements a global test environment that connects once and reuses handles across suites/tests. |
| cpp/src/arrow/flight/sql/odbc/tests/connection_info_test.cc | Updates handle-based tests to call ConnectWithString(..., conn). |
| cpp/src/arrow/flight/sql/odbc/tests/connection_attr_test.cc | Allocates a local env/conn for a DM-only attribute test and uses new helpers. |
| cpp/src/arrow/flight/sql/odbc/tests/CMakeLists.txt | Adds a Windows-only extra source intended to address a Windows crash. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # Resolve segmentation fault error on Windows platform due to Arrow Compute Library Initialization | ||
| if(WIN32) | ||
| list(APPEND ARROW_FLIGHT_SQL_ODBC_TEST_SRCS ../../../../compute/test_env.cc) | ||
| endif() |
There was a problem hiding this comment.
Adding ../../../../compute/test_env.cc introduces a second main() (see cpp/src/arrow/compute/test_env.cc), which will likely cause a linker error (multiple definition of main) or unintentionally override the test runner entrypoint on Windows. Instead, initialize Arrow Compute from an existing global test environment (e.g., call arrow::compute::Initialize() inside OdbcTestEnvironment::SetUp() under #ifdef _WIN32) or add a small helper source that registers the compute environment but does not define main().
| # Resolve segmentation fault error on Windows platform due to Arrow Compute Library Initialization | |
| if(WIN32) | |
| list(APPEND ARROW_FLIGHT_SQL_ODBC_TEST_SRCS ../../../../compute/test_env.cc) | |
| endif() | |
| # Do not add ../../../../compute/test_env.cc here: it defines its own main(), | |
| # which would conflict with this test target's runner on Windows. Any Arrow | |
| # Compute initialization must be performed from the existing ODBC test | |
| # environment or from a helper source that does not define main(). |
| inline OdbcHandles mock_odbcv2_handles; | ||
| inline OdbcHandles mock_non_connection_handles; | ||
|
|
||
| // These handles are meant to point to to the relevant handle above |
There was a problem hiding this comment.
Typo in comment: "point to to" -> "point to".
| // These handles are meant to point to to the relevant handle above | |
| // These handles are meant to point to the relevant handle above |
Rationale for this change
We avoid crashing tests on Linux if we minimize the number of connect/disconnect attempts. So now we are reusing the same connection as much as possible throughout the tests.
What changes are included in this PR?
All our necessary connections happen during global
SetUp()and then they get disconnected during globalTearDown().Test Fixture SetUp logic is now about updating pointers to the correct environment, connection, and statement handles for those tests.
Are these changes tested?
Yes.
Are there any user-facing changes?
No.