Merge pull request #33305 from nvartolomei/nv/test-odbc

Add test for broken connection
This commit is contained in:
tavplubix 2022-01-10 14:23:38 +03:00 committed by GitHub
commit 376709b249
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View File

@ -91,6 +91,25 @@ T execute(nanodbc::ConnectionHolderPtr connection_holder, std::function<T(nanodb
connection_holder->updateConnection(); connection_holder->updateConnection();
return query_func(connection_holder->get()); return query_func(connection_holder->get());
} }
/// psqlodbc driver error handling is incomplete and under some scenarious
/// it doesn't propagate correct errors to the caller.
/// As a quick workaround we run a quick "ping" query over the connection
/// on generic errors.
/// If "ping" fails, recycle the connection and try the query once more.
if (e.state().starts_with("HY00"))
{
try
{
just_execute(connection_holder->get(), "SELECT 1");
}
catch (...)
{
connection_holder->updateConnection();
return query_func(connection_holder->get());
}
}
throw; throw;
} }
} }

View File

@ -338,6 +338,8 @@ def test_postgres_odbc_hashed_dictionary_with_schema(started_cluster):
cursor.execute("truncate table clickhouse.test_table") cursor.execute("truncate table clickhouse.test_table")
cursor.execute("insert into clickhouse.test_table values(1, 1, 'hello'),(2, 2, 'world')") cursor.execute("insert into clickhouse.test_table values(1, 1, 'hello'),(2, 2, 'world')")
node1.query("SYSTEM RELOAD DICTIONARY postgres_odbc_hashed") node1.query("SYSTEM RELOAD DICTIONARY postgres_odbc_hashed")
node1.exec_in_container(["ss", "-K", "dport", "postgresql"], privileged=True, user='root')
node1.query("SYSTEM RELOAD DICTIONARY postgres_odbc_hashed")
assert_eq_with_retry(node1, "select dictGetString('postgres_odbc_hashed', 'column2', toUInt64(1))", "hello") assert_eq_with_retry(node1, "select dictGetString('postgres_odbc_hashed', 'column2', toUInt64(1))", "hello")
assert_eq_with_retry(node1, "select dictGetString('postgres_odbc_hashed', 'column2', toUInt64(2))", "world") assert_eq_with_retry(node1, "select dictGetString('postgres_odbc_hashed', 'column2', toUInt64(2))", "world")