From c6c65c5d1e701d0d282241b49d04a0e20c9088c8 Mon Sep 17 00:00:00 2001 From: Nicola Coretti Date: Tue, 9 Jul 2024 10:32:52 +0200 Subject: [PATCH 1/3] Add tests regarding http transport errors --- .../integration/http_transport_errors_test.py | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 test/integration/http_transport_errors_test.py diff --git a/test/integration/http_transport_errors_test.py b/test/integration/http_transport_errors_test.py new file mode 100644 index 0000000..5f7b5a2 --- /dev/null +++ b/test/integration/http_transport_errors_test.py @@ -0,0 +1,83 @@ +import os +import time +import pytest +import shutil +import pyexasol + + +@pytest.fixture +def dev_null(): + with open(os.devnull, "wb") as f: + yield f + + +@pytest.fixture +def statement(): + yield "SELECT * FROM USERS LIMIT 1000" + + +@pytest.fixture +def invalid_statement(): + yield "SELECT * FROM DoesNotExist LIMIT 1000" + + +@pytest.mark.etl +@pytest.mark.exceptions +def test_sql_error(connection, dev_null, invalid_statement): + def export_cb(pipe, dst, **kwargs): + shutil.copyfileobj(pipe, dev_null) + + with pytest.raises(pyexasol.exceptions.ExaQueryError): + connection.export_to_callback(export_cb, None, invalid_statement) + + +@pytest.mark.etl +@pytest.mark.exceptions +def test_abort_query(connection, dev_null, statement): + def export_cb(pipe, dst, **kwargs): + connection.abort_query() + # Make sure abort has time to propagate + time.sleep(1) + shutil.copyfileobj(pipe, dev_null) + + with pytest.raises(pyexasol.exceptions.ExaError): + connection.export_to_callback(export_cb, None, statement) + + +@pytest.mark.etl +@pytest.mark.exceptions +def test_error_in_export_callback(connection, statement): + error_msg = "Error from callback" + + def export_cb(pipe, dst, **kwargs): + raise Exception(error_msg) + + with pytest.raises(Exception) as exec_info: + connection.export_to_callback(export_cb, None, statement) + + expected = error_msg + actual = f"{exec_info.value}" + + assert actual == expected + + +@pytest.mark.etl +@pytest.mark.exceptions +def test_error_in_import_callback(connection, statement): + def import_cb(pipe, src, **kwargs): + raise Exception() + + with pytest.raises(pyexasol.exceptions.ExaQueryError): + connection.import_from_callback(import_cb, None, "users") + + +@pytest.mark.etl +@pytest.mark.exceptions +def test_closed_ws_connection(connection, dev_null, statement): + def import_cb(pipe, src, **kwargs): + connection.close(disconnect=False) + time.sleep(1) + shutil.copyfileobj(pipe, dev_null) + + with pytest.raises(pyexasol.exceptions.ExaError): + connection.import_from_callback(import_cb, None, "users") From 866b84ad0f5c38cd192eaa77f3c7f23eb57bd742 Mon Sep 17 00:00:00 2001 From: Nicola Coretti Date: Tue, 9 Jul 2024 11:59:43 +0200 Subject: [PATCH 2/3] Update test/integration/http_transport_errors_test.py Co-authored-by: Christoph Pirkl <4711730+kaklakariada@users.noreply.github.com> --- test/integration/http_transport_errors_test.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/test/integration/http_transport_errors_test.py b/test/integration/http_transport_errors_test.py index 5f7b5a2..b2efce9 100644 --- a/test/integration/http_transport_errors_test.py +++ b/test/integration/http_transport_errors_test.py @@ -52,14 +52,9 @@ def test_error_in_export_callback(connection, statement): def export_cb(pipe, dst, **kwargs): raise Exception(error_msg) - with pytest.raises(Exception) as exec_info: + with pytest.raises(Exception, matches=error_msg): connection.export_to_callback(export_cb, None, statement) - expected = error_msg - actual = f"{exec_info.value}" - - assert actual == expected - @pytest.mark.etl @pytest.mark.exceptions From d6418ead7b9a6af5f11bc5406e611eba191805be Mon Sep 17 00:00:00 2001 From: Nicola Coretti Date: Tue, 9 Jul 2024 12:07:49 +0200 Subject: [PATCH 3/3] Fix typo --- test/integration/http_transport_errors_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/http_transport_errors_test.py b/test/integration/http_transport_errors_test.py index b2efce9..d4b7cae 100644 --- a/test/integration/http_transport_errors_test.py +++ b/test/integration/http_transport_errors_test.py @@ -52,7 +52,7 @@ def test_error_in_export_callback(connection, statement): def export_cb(pipe, dst, **kwargs): raise Exception(error_msg) - with pytest.raises(Exception, matches=error_msg): + with pytest.raises(Exception, match=error_msg): connection.export_to_callback(export_cb, None, statement)