Skip to content

Commit 0ef857d

Browse files
committed
Fix tests on Linux
1 parent 62cdda9 commit 0ef857d

11 files changed

Lines changed: 143 additions & 73 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: 13 additions & 9 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,
@@ -416,6 +420,8 @@ TYPED_TEST(ColumnsTest, SQLColumnsTestInputData) {
416420
ValidateFetch(this->stmt, SQL_SUCCESS);
417421
}
418422

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

@@ -1210,6 +1216,7 @@ TEST_F(ColumnsMockTest, TestSQLColumnsTableColumnPattern) {
12101216
// There is no more column
12111217
EXPECT_EQ(SQL_NO_DATA, SQLFetch(this->stmt));
12121218
}
1219+
#endif // __linux__
12131220

12141221
TEST_F(ColumnsMockTest, TestSQLColumnsInvalidTablePattern) {
12151222
ASSIGN_SQLWCHAR_ARR(table_pattern, L"non-existent-table");
@@ -2560,10 +2567,6 @@ TEST_F(ColumnsMockTest, SQLDescribeColUnicodeTableMetadata) {
25602567

25612568
ASSIGN_SQLWCHAR_ARR_AND_LEN(sql_query, L"SELECT * from 数据 LIMIT 1;");
25622569

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-
25672570
ASSERT_EQ(SQL_SUCCESS, SQLExecDirect(this->stmt, sql_query, sql_query_len));
25682571

25692572
ASSERT_EQ(SQL_SUCCESS, SQLFetch(this->stmt));
@@ -2572,13 +2575,14 @@ TEST_F(ColumnsMockTest, SQLDescribeColUnicodeTableMetadata) {
25722575
buf_char_len, &name_length, &column_data_type,
25732576
&column_size, &decimal_digits, &nullable));
25742577

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

25772581
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);
2582+
EXPECT_EQ(expected_column_name_wstr, returned);
2583+
EXPECT_EQ(expected_column_name_len, name_length);
2584+
EXPECT_EQ(SQL_WVARCHAR, column_data_type);
2585+
EXPECT_EQ(0, column_size);
25822586
EXPECT_EQ(0, decimal_digits);
25832587
EXPECT_EQ(SQL_NULLABLE, nullable);
25842588

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

Lines changed: 47 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(this->conn, SQL_ATTR_ASYNC_DBC_EVENT, 0, 0));
@@ -117,31 +124,34 @@ TYPED_TEST(ConnectionAttributeTest, TestSQLSetConnectAttrTraceDMOnly) {
117124
}
118125
#endif // __APPLE__
119126

120-
TYPED_TEST(ConnectionAttributeTest, TestSQLSetConnectAttrTracefileDMOnly) {
127+
TYPED_TEST(ConnectionAttributePreConnectTest, TestSQLSetConnectAttrTracefileDMOnly) {
121128
// Verify DM-only attribute is handled by Driver Manager
122129

123130
// Use placeholder value as we want the call to fail, or else
124131
// the driver manager will produce a trace file.
125132
std::wstring trace_file = L"invalid/file/path";
126133
std::vector<SQLWCHAR> trace_file0(trace_file.begin(), trace_file.end());
134+
135+
#ifdef _WIN32
127136
ASSERT_EQ(SQL_ERROR, SQLSetConnectAttr(this->conn, SQL_ATTR_TRACEFILE, &trace_file0[0],
128137
static_cast<SQLINTEGER>(trace_file0.size())));
129-
#ifdef __APPLE__
130-
VerifyOdbcErrorState(SQL_HANDLE_DBC, this->conn, kErrorStateHYC00);
131-
#else
132138
VerifyOdbcErrorState(SQL_HANDLE_DBC, this->conn, kErrorStateHY000);
133-
#endif // __APPLE__
139+
#else // Mac & Linux
140+
ASSERT_EQ(SQL_SUCCESS,
141+
SQLSetConnectAttr(this->conn, SQL_ATTR_TRACEFILE, &trace_file0[0],
142+
static_cast<SQLINTEGER>(trace_file0.size())));
143+
#endif
134144
}
135145

136146
TYPED_TEST(ConnectionAttributeTest, TestSQLSetConnectAttrTranslateLabDMOnly) {
137147
// Verify DM-only attribute is handled by Driver Manager
138148
ASSERT_EQ(SQL_ERROR, SQLSetConnectAttr(this->conn, SQL_ATTR_TRANSLATE_LIB, 0, 0));
139149
// Checks for invalid argument return error
140-
#ifdef __APPLE__
141-
VerifyOdbcErrorState(SQL_HANDLE_DBC, this->conn, kErrorStateHYC00);
142-
#else
150+
#ifdef _WIN32
143151
VerifyOdbcErrorState(SQL_HANDLE_DBC, this->conn, kErrorStateHY024);
144-
#endif // __APPLE__
152+
#else // Mac & Linux
153+
VerifyOdbcErrorState(SQL_HANDLE_DBC, this->conn, kErrorStateHYC00);
154+
#endif
145155
}
146156

147157
TYPED_TEST(ConnectionAttributeTest, TestSQLSetConnectAttrTranslateOptionUnsupported) {
@@ -166,8 +176,8 @@ TYPED_TEST(ConnectionAttributeTest, TestSQLGetConnectAttrDbcInfoTokenSetOnly) {
166176
}
167177
#endif
168178

169-
// iODBC does not treat SQL_ATTR_ODBC_CURSORS as DM-only
170-
#ifndef __APPLE__
179+
// Driver Manager behavior tests for Windows only.
180+
#ifdef _WIN32
171181
TYPED_TEST(ConnectionAttributeTest, TestSQLGetConnectAttrOdbcCursorsDMOnly) {
172182
// Verify that DM-only attribute is handled by driver manager
173183
SQLULEN cursor_attr;
@@ -176,7 +186,6 @@ TYPED_TEST(ConnectionAttributeTest, TestSQLGetConnectAttrOdbcCursorsDMOnly) {
176186
EXPECT_EQ(SQL_CUR_USE_DRIVER, cursor_attr);
177187
}
178188

179-
// iODBC needs to be compiled with tracing enabled to handle SQL_ATTR_TRACE
180189
TYPED_TEST(ConnectionAttributeTest, TestSQLGetConnectAttrTraceDMOnly) {
181190
// Verify that DM-only attribute is handled by driver manager
182191
SQLUINTEGER trace;
@@ -185,7 +194,6 @@ TYPED_TEST(ConnectionAttributeTest, TestSQLGetConnectAttrTraceDMOnly) {
185194
EXPECT_EQ(SQL_OPT_TRACE_OFF, trace);
186195
}
187196

188-
// iODBC needs to be compiled with tracing enabled to handle SQL_ATTR_TRACEFILE
189197
TYPED_TEST(ConnectionAttributeTest, TestSQLGetConnectAttrTraceFileDMOnly) {
190198
// Verify that DM-only attribute is handled by driver manager
191199
SQLWCHAR out_str[kOdbcBufferSize];
@@ -199,7 +207,7 @@ TYPED_TEST(ConnectionAttributeTest, TestSQLGetConnectAttrTraceFileDMOnly) {
199207
ODBC::SqlWcharToString(out_str, static_cast<SQLSMALLINT>(out_str_len));
200208
EXPECT_FALSE(out_connection_string.empty());
201209
}
202-
#endif // __APPLE__
210+
#endif // _WIN32
203211

204212
TYPED_TEST(ConnectionAttributeTest, TestSQLGetConnectAttrTranslateLibUnsupported) {
205213
SQLWCHAR out_str[kOdbcBufferSize];
@@ -226,11 +234,17 @@ TYPED_TEST(ConnectionAttributeTest, TestSQLGetConnectAttrTxnIsolationUnsupported
226234
#ifdef SQL_ATTR_ASYNC_DBC_FUNCTIONS_ENABLE
227235
TYPED_TEST(ConnectionAttributeTest,
228236
TestSQLGetConnectAttrAsyncDbcFunctionsEnableUnsupported) {
229-
// Verifies that the Windows driver manager returns HY114 for unsupported functionality
230237
SQLUINTEGER enable;
238+
# ifdef _WIN32
239+
// Verifies that the Windows driver manager returns HY114 for unsupported functionality
231240
ASSERT_EQ(SQL_ERROR, SQLGetConnectAttr(this->conn, SQL_ATTR_ASYNC_DBC_FUNCTIONS_ENABLE,
232241
&enable, 0, 0));
233242
VerifyOdbcErrorState(SQL_HANDLE_DBC, this->conn, kErrorStateHY114);
243+
# else // Mac & Linux
244+
ASSERT_EQ(
245+
SQL_SUCCESS,
246+
SQLGetConnectAttr(this->conn, SQL_ATTR_ASYNC_DBC_FUNCTIONS_ENABLE, &enable, 0, 0));
247+
# endif
234248
}
235249
#endif
236250

@@ -357,14 +371,23 @@ TYPED_TEST(ConnectionAttributeTest, TestSQLSetConnectAttrLoginTimeoutValid) {
357371
EXPECT_EQ(42, timeout);
358372
}
359373

374+
#ifdef __linux__
375+
// On Linux, SQL_ATTR_PACKET_SIZE can only be set before connection
376+
// which is why use a different test fixture for Linux.
377+
TYPED_TEST(ConnectionAttributePreConnectTest, TestSQLSetConnectAttrPacketSizeValid) {
378+
#else // Windows & Mac
360379
TYPED_TEST(ConnectionAttributeTest, TestSQLSetConnectAttrPacketSizeValid) {
361-
// The driver always returns 0. PACKET_SIZE value is unused by the driver.
362-
380+
#endif
363381
// Check default value first
364382
SQLUINTEGER size = -1;
383+
#ifdef __linux__
384+
ASSERT_EQ(SQL_ERROR, SQLGetConnectAttr(conn, SQL_ATTR_PACKET_SIZE, &size, 0, nullptr));
385+
VerifyOdbcErrorState(SQL_HANDLE_DBC, conn, kErrorState08003);
386+
#else // Windows & Mac
365387
ASSERT_EQ(SQL_SUCCESS,
366388
SQLGetConnectAttr(this->conn, SQL_ATTR_PACKET_SIZE, &size, 0, nullptr));
367389
EXPECT_EQ(0, size);
390+
#endif
368391

369392
ASSERT_EQ(SQL_SUCCESS, SQLSetConnectAttr(this->conn, SQL_ATTR_PACKET_SIZE,
370393
reinterpret_cast<SQLPOINTER>(0), 0));
@@ -374,12 +397,18 @@ TYPED_TEST(ConnectionAttributeTest, TestSQLSetConnectAttrPacketSizeValid) {
374397
SQLGetConnectAttr(this->conn, SQL_ATTR_PACKET_SIZE, &size, 0, nullptr));
375398
EXPECT_EQ(0, size);
376399

377-
// Attempt to set to non-zero value, driver should return warning and not error
400+
// Attempt to set to non-zero value,
401+
#ifdef __linux__
402+
EXPECT_EQ(SQL_SUCCESS, SQLSetConnectAttr(this->conn, SQL_ATTR_PACKET_SIZE,
403+
reinterpret_cast<SQLPOINTER>(2), 0));
404+
#else // Windows & Mac
405+
// driver should return warning and not error
378406
EXPECT_EQ(SQL_SUCCESS_WITH_INFO, SQLSetConnectAttr(this->conn, SQL_ATTR_PACKET_SIZE,
379407
reinterpret_cast<SQLPOINTER>(2), 0));
380408

381409
// Verify warning status
382410
VerifyOdbcErrorState(SQL_HANDLE_DBC, this->conn, kErrorState01S02);
411+
#endif
383412
}
384413

385414
} // 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) {
@@ -331,9 +335,11 @@ TYPED_TEST(ConnectionInfoTest, TestSQLGetInfoOdbcVer) {
331335

332336
std::wstring result = ConvertToWString(value);
333337

334-
#ifdef __APPLE__
338+
#if defined(__APPLE__)
335339
EXPECT_EQ(std::wstring(L"03.52.0000"), result);
336-
#else
340+
#elif defined(__linux__)
341+
EXPECT_EQ(std::wstring(L"03.52"), result);
342+
#else // WINDOWS
337343
EXPECT_EQ(std::wstring(L"03.80.0000"), result);
338344
#endif // __APPLE__
339345
}

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -313,15 +313,20 @@ TYPED_TEST(ErrorsTest, TestSQLGetDiagRecInputData) {
313313
EXPECT_EQ(SQL_NO_DATA, SQLGetDiagRec(SQL_HANDLE_DBC, this->conn, 1, nullptr, nullptr,
314314
nullptr, 0, nullptr));
315315

316-
// Invalid handle
317316
#ifdef __APPLE__
318317
// MacOS ODBC driver manager requires connection handle
319318
EXPECT_EQ(SQL_INVALID_HANDLE,
320319
SQLGetDiagRec(0, this->conn, 1, nullptr, nullptr, nullptr, 0, nullptr));
321320
#else
322-
EXPECT_EQ(SQL_INVALID_HANDLE,
321+
// Linux & Windows driver managers have different expected return values
322+
# ifdef __linux__
323+
SQLRETURN expected_rc = SQL_ERROR;
324+
# else // Windows
325+
SQLRETURN expected_rc = SQL_INVALID_HANDLE;
326+
# endif
327+
EXPECT_EQ(expected_rc,
323328
SQLGetDiagRec(0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr));
324-
#endif // __APPLE__
329+
#endif
325330
}
326331

327332
TYPED_TEST(ErrorsOdbcV2Test, TestSQLErrorInputData) {
@@ -491,13 +496,13 @@ TYPED_TEST(ErrorsOdbcV2Test, TestSQLErrorEnvErrorFromDriverManager) {
491496
EXPECT_EQ(0, native_error);
492497

493498
// Function sequence error state from driver manager
494-
#ifdef _WIN32
495-
// Windows Driver Manager returns S1010
496-
EXPECT_EQ(kErrorStateS1010, SqlWcharToString(sql_state));
497-
#else
498-
// unix Driver Manager returns HY010
499+
#ifdef __APPLE__
500+
// MacOS Driver Manager returns HY010
499501
EXPECT_EQ(kErrorStateHY010, SqlWcharToString(sql_state));
500-
#endif // _WIN32
502+
#else // Linux & Windows
503+
// Linux & Windows Driver Managers returns S1010
504+
EXPECT_EQ(kErrorStateS1010, SqlWcharToString(sql_state));
505+
#endif
501506

502507
std::string msg = SqlWcharToString(message);
503508
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

@@ -218,6 +219,6 @@ TYPED_TEST(GetFunctionsOdbcV2Test, TestSQLGetFunctionsUnsupportedSingleAPI) {
218219
api_exists = -1;
219220
}
220221
}
221-
#endif // __APPLE__
222+
#endif // _WIN32
222223

223224
} // 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
@@ -246,6 +246,7 @@ bool CompareConnPropertyMap(Connection::ConnPropertyMap map1,
246246
/// Get error message from ODBC driver using SQLGetDiagRec
247247
std::string GetOdbcErrorMessage(SQLSMALLINT handle_type, SQLHANDLE handle);
248248

249+
static constexpr std::string_view kErrorState00000 = "00000";
249250
static constexpr std::string_view kErrorState01004 = "01004";
250251
static constexpr std::string_view kErrorState01S02 = "01S02";
251252
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
@@ -427,7 +427,11 @@ TYPED_TEST(StatementAttributeTest, TestSQLSetStmtAttrAsyncEnableUnsupported) {
427427
TYPED_TEST(StatementAttributeTest, TestSQLSetStmtAttrAsyncStmtEventUnsupported) {
428428
// Driver does not support asynchronous notification
429429
ValidateSetStmtAttrErrorCode(this->stmt, SQL_ATTR_ASYNC_STMT_EVENT, 0, SQL_ERROR,
430+
# ifdef __linux__
431+
kErrorStateHYC00);
432+
# else // Windows & Mac
430433
kErrorStateHY118);
434+
# endif
431435
}
432436
#endif
433437

0 commit comments

Comments
 (0)