Skip to content

Commit

Permalink
add retry logic to normal case tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vgvoleg committed Jan 23, 2025
1 parent 030275b commit ba5c216
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/aio/query/test_query_session_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,19 @@ async def callee(session: QuerySession):
)
@pytest.mark.asyncio
async def test_retry_tx_normal(self, pool: QuerySessionPool, tx_mode: Optional[ydb.BaseQueryTxMode]):
retry_no = 0

async def callee(tx: QueryTxContext):
nonlocal retry_no
if retry_no < 2:
retry_no += 1
raise ydb.Unavailable("Fake fast backoff error")
result_stream = await tx.execute("SELECT 1")
return [result_set async for result_set in result_stream]

result = await pool.retry_tx_async(callee=callee, tx_mode=tx_mode)
assert len(result) == 1
assert retry_no == 2

@pytest.mark.asyncio
async def test_retry_tx_raises(self, pool: QuerySessionPool):
Expand Down
7 changes: 7 additions & 0 deletions tests/query/test_query_session_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,19 @@ def callee(session: QuerySession):
],
)
def test_retry_tx_normal(self, pool: QuerySessionPool, tx_mode: Optional[ydb.BaseQueryTxMode]):
retry_no = 0

def callee(tx: QueryTxContext):
nonlocal retry_no
if retry_no < 2:
retry_no += 1
raise ydb.Unavailable("Fake fast backoff error")
result_stream = tx.execute("SELECT 1")
return [result_set for result_set in result_stream]

result = pool.retry_tx_sync(callee=callee, tx_mode=tx_mode)
assert len(result) == 1
assert retry_no == 2

def test_retry_tx_raises(self, pool: QuerySessionPool):
class CustomException(Exception):
Expand Down

0 comments on commit ba5c216

Please sign in to comment.