Skip to content

Commit 0ebcb1c

Browse files
committed
Fix tests on Linux
1 parent cf5d53d commit 0ebcb1c

11 files changed

Lines changed: 142 additions & 75 deletions

ci/scripts/cpp_test.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ if ! type minio >/dev/null 2>&1; then
5555
fi
5656
case "$(uname)" in
5757
Linux)
58-
exclude_tests+=("arrow-flight-sql-odbc-test")
5958
n_jobs=$(nproc)
6059
;;
6160
Darwin)

cpp/src/arrow/flight/sql/odbc/tests/columns_test.cc

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ TYPED_TEST_SUITE(ColumnsOdbcV2Test, TestTypesOdbcV2);
4646

4747
namespace {
4848
// Helper functions
49+
50+
// GH-49702: TODO Disabled on Linux due to BlockingQueue issue
51+
#ifndef __linux__
4952
void CheckSQLColumns(
5053
SQLHSTMT stmt, const std::wstring& expected_table,
5154
const std::wstring& expected_column, const SQLINTEGER& expected_data_type,
@@ -125,6 +128,7 @@ void CheckRemoteSQLColumns(
125128
expected_octet_char_length, expected_ordinal_position,
126129
expected_is_nullable);
127130
}
131+
#endif // __linux__
128132

129133
void CheckSQLColAttribute(SQLHSTMT stmt, SQLUSMALLINT idx,
130134
const std::string& expected_column_name,
@@ -415,6 +419,8 @@ TYPED_TEST(ColumnsTest, SQLColumnsTestInputData) {
415419
ValidateFetch(stmt, SQL_SUCCESS);
416420
}
417421

422+
// GH-49702: TODO Disabled on Linux due to BlockingQueue issue
423+
#ifndef __linux__
418424
TEST_F(ColumnsMockTest, TestSQLColumnsAllColumns) {
419425
// Check table pattern and column pattern returns all columns
420426

@@ -1209,6 +1215,7 @@ TEST_F(ColumnsMockTest, TestSQLColumnsTableColumnPattern) {
12091215
// There is no more column
12101216
EXPECT_EQ(SQL_NO_DATA, SQLFetch(stmt));
12111217
}
1218+
#endif // __linux__
12121219

12131220
TEST_F(ColumnsMockTest, TestSQLColumnsInvalidTablePattern) {
12141221
ASSIGN_SQLWCHAR_ARR(table_pattern, L"non-existent-table");
@@ -1224,8 +1231,7 @@ TEST_F(ColumnsMockTest, TestSQLColumnsInvalidTablePattern) {
12241231
TYPED_TEST(ColumnsTest, SQLColAttributeTestInputData) {
12251232
ASSIGN_SQLWCHAR_ARR_AND_LEN(wsql, L"SELECT 1 as col1;");
12261233

1227-
ASSERT_EQ(SQL_SUCCESS, SQLExecDirect(stmt, wsql, wsql_len))
1228-
<< GetOdbcErrorMessage(SQL_HANDLE_DBC, conn);
1234+
ASSERT_EQ(SQL_SUCCESS, SQLExecDirect(stmt, wsql, wsql_len));
12291235

12301236
ASSERT_EQ(SQL_SUCCESS, SQLFetch(stmt));
12311237

@@ -2560,10 +2566,6 @@ TEST_F(ColumnsMockTest, SQLDescribeColUnicodeTableMetadata) {
25602566

25612567
ASSIGN_SQLWCHAR_ARR_AND_LEN(sql_query, L"SELECT * from 数据 LIMIT 1;");
25622568

2563-
ASSIGN_SQLWCHAR_ARR_AND_LEN(expected_column_name, L"资料");
2564-
SQLSMALLINT expected_column_data_type = SQL_WVARCHAR;
2565-
SQLULEN expected_column_size = 0;
2566-
25672569
ASSERT_EQ(SQL_SUCCESS, SQLExecDirect(stmt, sql_query, sql_query_len));
25682570

25692571
ASSERT_EQ(SQL_SUCCESS, SQLFetch(stmt));
@@ -2572,13 +2574,14 @@ TEST_F(ColumnsMockTest, SQLDescribeColUnicodeTableMetadata) {
25722574
SQLDescribeCol(stmt, column_index, column_name, buf_char_len, &name_length,
25732575
&column_data_type, &column_size, &decimal_digits, &nullable));
25742576

2575-
EXPECT_EQ(name_length, expected_column_name_len);
2577+
std::wstring expected_column_name_wstr = std::wstring(L"资料");
2578+
size_t expected_column_name_len = expected_column_name_wstr.length();
25762579

25772580
std::wstring returned(column_name, column_name + name_length);
2578-
std::wstring expected_col_name_str = ConvertToWString(expected_column_name);
2579-
EXPECT_EQ(expected_col_name_str, returned);
2580-
EXPECT_EQ(expected_column_data_type, column_data_type);
2581-
EXPECT_EQ(expected_column_size, column_size);
2581+
EXPECT_EQ(expected_column_name_wstr, returned);
2582+
EXPECT_EQ(expected_column_name_len, name_length);
2583+
EXPECT_EQ(SQL_WVARCHAR, column_data_type);
2584+
EXPECT_EQ(0, column_size);
25822585
EXPECT_EQ(0, decimal_digits);
25832586
EXPECT_EQ(SQL_NULLABLE, nullable);
25842587

cpp/src/arrow/flight/sql/odbc/tests/connection_attr_test.cc

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ using TestTypes =
3333
::testing::Types<FlightSQLODBCMockTestBase, FlightSQLODBCRemoteTestBase>;
3434
TYPED_TEST_SUITE(ConnectionAttributeTest, TestTypes);
3535

36+
template <typename T>
37+
class ConnectionAttributePreConnectTest : public T {};
38+
39+
using TestTypesHandle = ::testing::Types<FlightSQLOdbcEnvConnHandleMockTestBase,
40+
FlightSQLOdbcEnvConnHandleRemoteTestBase>;
41+
TYPED_TEST_SUITE(ConnectionAttributePreConnectTest, TestTypesHandle);
42+
3643
#ifdef SQL_ATTR_ASYNC_DBC_EVENT
3744
TYPED_TEST(ConnectionAttributeTest, TestSQLSetConnectAttrAsyncDbcEventUnsupported) {
3845
ASSERT_EQ(SQL_ERROR, SQLSetConnectAttr(conn, SQL_ATTR_ASYNC_DBC_EVENT, 0, 0));
@@ -114,31 +121,33 @@ TYPED_TEST(ConnectionAttributeTest, TestSQLSetConnectAttrTraceDMOnly) {
114121
}
115122
#endif // __APPLE__
116123

117-
TYPED_TEST(ConnectionAttributeTest, TestSQLSetConnectAttrTracefileDMOnly) {
124+
TYPED_TEST(ConnectionAttributePreConnectTest, TestSQLSetConnectAttrTracefileDMOnly) {
118125
// Verify DM-only attribute is handled by Driver Manager
119126

120127
// Use placeholder value as we want the call to fail, or else
121128
// the driver manager will produce a trace file.
122129
std::wstring trace_file = L"invalid/file/path";
123130
std::vector<SQLWCHAR> trace_file0(trace_file.begin(), trace_file.end());
131+
132+
#ifdef _WIN32
124133
ASSERT_EQ(SQL_ERROR, SQLSetConnectAttr(conn, SQL_ATTR_TRACEFILE, &trace_file0[0],
125134
static_cast<SQLINTEGER>(trace_file0.size())));
126-
#ifdef __APPLE__
127-
VerifyOdbcErrorState(SQL_HANDLE_DBC, conn, kErrorStateHYC00);
128-
#else
129135
VerifyOdbcErrorState(SQL_HANDLE_DBC, conn, kErrorStateHY000);
130-
#endif // __APPLE__
136+
#else // Mac & Linux
137+
ASSERT_EQ(SQL_SUCCESS, SQLSetConnectAttr(conn, SQL_ATTR_TRACEFILE, &trace_file0[0],
138+
static_cast<SQLINTEGER>(trace_file0.size())));
139+
#endif
131140
}
132141

133142
TYPED_TEST(ConnectionAttributeTest, TestSQLSetConnectAttrTranslateLabDMOnly) {
134143
// Verify DM-only attribute is handled by Driver Manager
135144
ASSERT_EQ(SQL_ERROR, SQLSetConnectAttr(conn, SQL_ATTR_TRANSLATE_LIB, 0, 0));
136145
// Checks for invalid argument return error
137-
#ifdef __APPLE__
138-
VerifyOdbcErrorState(SQL_HANDLE_DBC, conn, kErrorStateHYC00);
139-
#else
146+
#ifdef _WIN32
140147
VerifyOdbcErrorState(SQL_HANDLE_DBC, conn, kErrorStateHY024);
141-
#endif // __APPLE__
148+
#else // Mac & Linux
149+
VerifyOdbcErrorState(SQL_HANDLE_DBC, conn, kErrorStateHYC00);
150+
#endif
142151
}
143152

144153
TYPED_TEST(ConnectionAttributeTest, TestSQLSetConnectAttrTranslateOptionUnsupported) {
@@ -162,8 +171,8 @@ TYPED_TEST(ConnectionAttributeTest, TestSQLGetConnectAttrDbcInfoTokenSetOnly) {
162171
}
163172
#endif
164173

165-
// iODBC does not treat SQL_ATTR_ODBC_CURSORS as DM-only
166-
#ifndef __APPLE__
174+
// Driver Manager behavior tests for Windows only.
175+
#ifdef _WIN32
167176
TYPED_TEST(ConnectionAttributeTest, TestSQLGetConnectAttrOdbcCursorsDMOnly) {
168177
// Verify that DM-only attribute is handled by driver manager
169178
SQLULEN cursor_attr;
@@ -172,15 +181,13 @@ TYPED_TEST(ConnectionAttributeTest, TestSQLGetConnectAttrOdbcCursorsDMOnly) {
172181
EXPECT_EQ(SQL_CUR_USE_DRIVER, cursor_attr);
173182
}
174183

175-
// iODBC needs to be compiled with tracing enabled to handle SQL_ATTR_TRACE
176184
TYPED_TEST(ConnectionAttributeTest, TestSQLGetConnectAttrTraceDMOnly) {
177185
// Verify that DM-only attribute is handled by driver manager
178186
SQLUINTEGER trace;
179187
ASSERT_EQ(SQL_SUCCESS, SQLGetConnectAttr(conn, SQL_ATTR_TRACE, &trace, 0, nullptr));
180188
EXPECT_EQ(SQL_OPT_TRACE_OFF, trace);
181189
}
182190

183-
// iODBC needs to be compiled with tracing enabled to handle SQL_ATTR_TRACEFILE
184191
TYPED_TEST(ConnectionAttributeTest, TestSQLGetConnectAttrTraceFileDMOnly) {
185192
// Verify that DM-only attribute is handled by driver manager
186193
SQLWCHAR out_str[kOdbcBufferSize];
@@ -194,7 +201,7 @@ TYPED_TEST(ConnectionAttributeTest, TestSQLGetConnectAttrTraceFileDMOnly) {
194201
ODBC::SqlWcharToString(out_str, static_cast<SQLSMALLINT>(out_str_len));
195202
EXPECT_FALSE(out_connection_string.empty());
196203
}
197-
#endif // __APPLE__
204+
#endif // _WIN32
198205

199206
TYPED_TEST(ConnectionAttributeTest, TestSQLGetConnectAttrTranslateLibUnsupported) {
200207
SQLWCHAR out_str[kOdbcBufferSize];
@@ -221,11 +228,16 @@ TYPED_TEST(ConnectionAttributeTest, TestSQLGetConnectAttrTxnIsolationUnsupported
221228
#ifdef SQL_ATTR_ASYNC_DBC_FUNCTIONS_ENABLE
222229
TYPED_TEST(ConnectionAttributeTest,
223230
TestSQLGetConnectAttrAsyncDbcFunctionsEnableUnsupported) {
224-
// Verifies that the Windows driver manager returns HY114 for unsupported functionality
225231
SQLUINTEGER enable;
232+
# ifdef _WIN32
233+
// Verifies that the Windows driver manager returns HY114 for unsupported functionality
226234
ASSERT_EQ(SQL_ERROR,
227235
SQLGetConnectAttr(conn, SQL_ATTR_ASYNC_DBC_FUNCTIONS_ENABLE, &enable, 0, 0));
228236
VerifyOdbcErrorState(SQL_HANDLE_DBC, conn, kErrorStateHY114);
237+
# else // Mac & Linux
238+
ASSERT_EQ(SQL_SUCCESS,
239+
SQLGetConnectAttr(conn, SQL_ATTR_ASYNC_DBC_FUNCTIONS_ENABLE, &enable, 0, 0));
240+
# endif
229241
}
230242
#endif
231243

@@ -350,14 +362,23 @@ TYPED_TEST(ConnectionAttributeTest, TestSQLSetConnectAttrLoginTimeoutValid) {
350362
EXPECT_EQ(42, timeout);
351363
}
352364

365+
#ifdef __linux__
366+
// On Linux, SQL_ATTR_PACKET_SIZE can only be set before connection
367+
// which is why use a different test fixture for Linux.
368+
TYPED_TEST(ConnectionAttributePreConnectTest, TestSQLSetConnectAttrPacketSizeValid) {
369+
#else // Windows & Mac
353370
TYPED_TEST(ConnectionAttributeTest, TestSQLSetConnectAttrPacketSizeValid) {
354-
// The driver always returns 0. PACKET_SIZE value is unused by the driver.
355-
371+
#endif
356372
// Check default value first
357373
SQLUINTEGER size = -1;
374+
#ifdef __linux__
375+
ASSERT_EQ(SQL_ERROR, SQLGetConnectAttr(conn, SQL_ATTR_PACKET_SIZE, &size, 0, nullptr));
376+
VerifyOdbcErrorState(SQL_HANDLE_DBC, conn, kErrorState08003);
377+
#else // Windows & Mac
358378
ASSERT_EQ(SQL_SUCCESS,
359379
SQLGetConnectAttr(conn, SQL_ATTR_PACKET_SIZE, &size, 0, nullptr));
360380
EXPECT_EQ(0, size);
381+
#endif
361382

362383
ASSERT_EQ(SQL_SUCCESS, SQLSetConnectAttr(conn, SQL_ATTR_PACKET_SIZE,
363384
reinterpret_cast<SQLPOINTER>(0), 0));
@@ -367,12 +388,18 @@ TYPED_TEST(ConnectionAttributeTest, TestSQLSetConnectAttrPacketSizeValid) {
367388
SQLGetConnectAttr(conn, SQL_ATTR_PACKET_SIZE, &size, 0, nullptr));
368389
EXPECT_EQ(0, size);
369390

370-
// Attempt to set to non-zero value, driver should return warning and not error
391+
// Attempt to set to non-zero value,
392+
#ifdef __linux__
393+
EXPECT_EQ(SQL_SUCCESS, SQLSetConnectAttr(conn, SQL_ATTR_PACKET_SIZE,
394+
reinterpret_cast<SQLPOINTER>(2), 0));
395+
#else // Windows & Mac
396+
// driver should return warning and not error
371397
EXPECT_EQ(SQL_SUCCESS_WITH_INFO, SQLSetConnectAttr(conn, SQL_ATTR_PACKET_SIZE,
372398
reinterpret_cast<SQLPOINTER>(2), 0));
373399

374400
// Verify warning status
375401
VerifyOdbcErrorState(SQL_HANDLE_DBC, conn, kErrorState01S02);
402+
#endif
376403
}
377404

378405
} // namespace arrow::flight::sql::odbc

cpp/src/arrow/flight/sql/odbc/tests/connection_info_test.cc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ TYPED_TEST(ConnectionInfoTest, TestSQLGetInfoDataSourceName) {
143143
}
144144

145145
#ifdef SQL_DRIVER_AWARE_POOLING_SUPPORTED
146+
// GH-49782: TODO Disabled on Linux until SQL_DRIVER_AWARE_POOLING_SUPPORTED is
147+
// implemented in the driver.
148+
# ifndef __linux__
146149
TYPED_TEST(ConnectionInfoTest, TestSQLGetInfoDriverAwarePoolingSupported) {
147150
// According to Microsoft documentation, ODBC driver does not need to implement
148151
// SQL_DRIVER_AWARE_POOLING_SUPPORTED and the Driver Manager will ignore the
@@ -153,7 +156,8 @@ TYPED_TEST(ConnectionInfoTest, TestSQLGetInfoDriverAwarePoolingSupported) {
153156

154157
EXPECT_EQ(static_cast<SQLUINTEGER>(SQL_DRIVER_AWARE_POOLING_NOT_CAPABLE), value);
155158
}
156-
#endif
159+
# endif // __linux__
160+
#endif // SQL_DRIVER_AWARE_POOLING_SUPPORTED
157161

158162
// These information types are implemented by the Driver Manager alone.
159163
TYPED_TEST(ConnectionInfoTest, TestSQLGetInfoDriverHdbc) {
@@ -329,9 +333,11 @@ TYPED_TEST(ConnectionInfoTest, TestSQLGetInfoOdbcVer) {
329333

330334
std::wstring result = ConvertToWString(value);
331335

332-
#ifdef __APPLE__
336+
#if defined(__APPLE__)
333337
EXPECT_EQ(std::wstring(L"03.52.0000"), result);
334-
#else
338+
#elif defined(__linux__)
339+
EXPECT_EQ(std::wstring(L"03.52"), result);
340+
#else // WINDOWS
335341
EXPECT_EQ(std::wstring(L"03.80.0000"), result);
336342
#endif // __APPLE__
337343
}

cpp/src/arrow/flight/sql/odbc/tests/errors_test.cc

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -309,15 +309,20 @@ TYPED_TEST(ErrorsTest, TestSQLGetDiagRecInputData) {
309309
EXPECT_EQ(SQL_NO_DATA, SQLGetDiagRec(SQL_HANDLE_DBC, conn, 1, nullptr, nullptr, nullptr,
310310
0, nullptr));
311311

312-
// Invalid handle
313312
#ifdef __APPLE__
314313
// MacOS ODBC driver manager requires connection handle
315314
EXPECT_EQ(SQL_INVALID_HANDLE,
316315
SQLGetDiagRec(0, conn, 1, nullptr, nullptr, nullptr, 0, nullptr));
317316
#else
318-
EXPECT_EQ(SQL_INVALID_HANDLE,
317+
// Linux & Windows driver managers have different expected return values
318+
# ifdef __linux__
319+
SQLRETURN expected_rc = SQL_ERROR;
320+
# else // Windows
321+
SQLRETURN expected_rc = SQL_INVALID_HANDLE;
322+
# endif
323+
EXPECT_EQ(expected_rc,
319324
SQLGetDiagRec(0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr));
320-
#endif // __APPLE__
325+
#endif
321326
}
322327

323328
TYPED_TEST(ErrorsOdbcV2Test, TestSQLErrorInputData) {
@@ -485,13 +490,13 @@ TYPED_TEST(ErrorsOdbcV2Test, TestSQLErrorEnvErrorFromDriverManager) {
485490
EXPECT_EQ(0, native_error);
486491

487492
// Function sequence error state from driver manager
488-
#ifdef _WIN32
489-
// Windows Driver Manager returns S1010
490-
EXPECT_EQ(kErrorStateS1010, SqlWcharToString(sql_state));
491-
#else
492-
// unix Driver Manager returns HY010
493+
#ifdef __APPLE__
494+
// MacOS Driver Manager returns HY010
493495
EXPECT_EQ(kErrorStateHY010, SqlWcharToString(sql_state));
494-
#endif // _WIN32
496+
#else // Linux & Windows
497+
// Linux & Windows Driver Managers returns S1010
498+
EXPECT_EQ(kErrorStateS1010, SqlWcharToString(sql_state));
499+
#endif
495500

496501
std::string msg = SqlWcharToString(message);
497502
EXPECT_FALSE(msg.empty());

cpp/src/arrow/flight/sql/odbc/tests/get_functions_test.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ using TestTypesOdbcV2 =
4040
::testing::Types<FlightSQLOdbcV2MockTestBase, FlightSQLOdbcV2RemoteTestBase>;
4141
TYPED_TEST_SUITE(GetFunctionsOdbcV2Test, TestTypesOdbcV2);
4242

43-
// MacOS driver manager iODBC does not support SQLGetFunctions for ODBC 3.x or 2.x driver
44-
#ifndef __APPLE__
43+
// Unix driver managers iODBC and Unix-ODBC do not support SQLGetFunctions
44+
// for ODBC 3.x or 2.x driver
45+
#ifdef _WIN32
4546
TYPED_TEST(GetFunctionsTest, TestSQLGetFunctionsAllFunctions) {
4647
// Verify driver manager return values for SQLGetFunctions
4748

@@ -217,6 +218,6 @@ TYPED_TEST(GetFunctionsOdbcV2Test, TestSQLGetFunctionsUnsupportedSingleAPI) {
217218
api_exists = -1;
218219
}
219220
}
220-
#endif // __APPLE__
221+
#endif // _WIN32
221222

222223
} // namespace arrow::flight::sql::odbc

cpp/src/arrow/flight/sql/odbc/tests/odbc_test_suite.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ bool CompareConnPropertyMap(Connection::ConnPropertyMap map1,
235235
/// Get error message from ODBC driver using SQLGetDiagRec
236236
std::string GetOdbcErrorMessage(SQLSMALLINT handle_type, SQLHANDLE handle);
237237

238+
static constexpr std::string_view kErrorState00000 = "00000";
238239
static constexpr std::string_view kErrorState01004 = "01004";
239240
static constexpr std::string_view kErrorState01S02 = "01S02";
240241
static constexpr std::string_view kErrorState01S07 = "01S07";

cpp/src/arrow/flight/sql/odbc/tests/statement_attr_test.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,11 @@ TYPED_TEST(StatementAttributeTest, TestSQLSetStmtAttrAsyncEnableUnsupported) {
424424
TYPED_TEST(StatementAttributeTest, TestSQLSetStmtAttrAsyncStmtEventUnsupported) {
425425
// Driver does not support asynchronous notification
426426
ValidateSetStmtAttrErrorCode(stmt, SQL_ATTR_ASYNC_STMT_EVENT, 0, SQL_ERROR,
427+
# ifdef __linux__
428+
kErrorStateHYC00);
429+
# else // Windows & Mac
427430
kErrorStateHY118);
431+
# endif
428432
}
429433
#endif
430434

0 commit comments

Comments
 (0)