Skip to content

Commit

Permalink
Add test for concurrent access on connection (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicoretti authored Jun 21, 2024
1 parent ffa4e0d commit f730bb9
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions test/integration/concurrency_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import pytest
import pyexasol
import threading
from pyexasol import ExaConcurrencyError


class QueryThread(threading.Thread):

def __init__(self, connection, timeout):
self.connection = connection
self.seconds = timeout
self.exception = None
super().__init__()

def run(self):
try:
# run heavy query
self.connection.execute(f'SELECT "$SLEEP"({self.seconds})')
except Exception as ex:
self.exception = ex

def join(self, timeout=None):
threading.Thread.join(self, timeout=timeout)
if self.exception:
raise self.exception


@pytest.mark.exceptions
def test_concurrency_error(dsn, user, password, schema):

# Note all timeouts and sleeps in this test case have been chosen by well-educated guesses
# TL;DR: Adjust timeouts if required/reasonable
query_time_in_seconds = 0.5

con = pyexasol.connect(dsn=dsn, user=user, password=password, schema=schema)
q1 = QueryThread(con, timeout=query_time_in_seconds)
q2 = QueryThread(con, timeout=query_time_in_seconds)

with pytest.raises(ExaConcurrencyError):
q1.start()
q2.start()
q1.join()
q2.join()

0 comments on commit f730bb9

Please sign in to comment.