Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for http transport errors #149

Merged
merged 4 commits into from
Jul 9, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions test/integration/http_transport_errors_test.py
Original file line number Diff line number Diff line change
@@ -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):
Nicoretti marked this conversation as resolved.
Show resolved Hide resolved
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
Nicoretti marked this conversation as resolved.
Show resolved Hide resolved


@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")
Loading