|
| 1 | +import json |
| 2 | + |
1 | 3 | import pytest
|
2 | 4 | import ydb
|
3 | 5 | import time
|
4 | 6 | from concurrent import futures
|
5 | 7 |
|
6 | 8 | from typing import Optional
|
7 | 9 |
|
| 10 | +from tests.conftest import wait_container_ready |
| 11 | +from ydb import QueryExplainResultFormat |
8 | 12 | from ydb.query.pool import QuerySessionPool
|
9 | 13 | from ydb.query.session import QuerySession, QuerySessionStateEnum
|
10 | 14 | from ydb.query.transaction import QueryTxContext
|
@@ -147,6 +151,7 @@ def test_no_session_leak(self, driver_sync, docker_project):
|
147 | 151 | assert pool._current_size == 0
|
148 | 152 |
|
149 | 153 | docker_project.start()
|
| 154 | + wait_container_ready(driver_sync) |
150 | 155 | pool.stop()
|
151 | 156 |
|
152 | 157 | def test_execute_with_retries_async(self, pool: QuerySessionPool):
|
@@ -200,3 +205,28 @@ def test_async_methods_after_stop_raise(self, pool: QuerySessionPool):
|
200 | 205 | pool.stop()
|
201 | 206 | with pytest.raises(ydb.SessionPoolClosed):
|
202 | 207 | pool.execute_with_retries_async("select 1;")
|
| 208 | + |
| 209 | + def test_explain_with_retries(self, pool: QuerySessionPool): |
| 210 | + pool.execute_with_retries("DROP TABLE IF EXISTS test_explain") |
| 211 | + pool.execute_with_retries("CREATE TABLE test_explain (id Int64, PRIMARY KEY (id))") |
| 212 | + try: |
| 213 | + |
| 214 | + plan = pool.explain_with_retries("SELECT * FROM test_explain", result_format=QueryExplainResultFormat.STR) |
| 215 | + isinstance(plan, str) |
| 216 | + assert "FullScan" in plan |
| 217 | + |
| 218 | + plan = pool.explain_with_retries("SELECT * FROM test_explain", result_format=QueryExplainResultFormat.DICT) |
| 219 | + assert isinstance(plan, dict) |
| 220 | + |
| 221 | + plan_string = json.dumps(plan) |
| 222 | + assert "FullScan" in plan_string |
| 223 | + |
| 224 | + plan = pool.explain_with_retries( |
| 225 | + "SELECT * FROM test_explain WHERE id = $id", |
| 226 | + {"$id": 1}, |
| 227 | + result_format=ydb.QueryExplainResultFormat.DICT, |
| 228 | + ) |
| 229 | + plan_string = json.dumps(plan) |
| 230 | + assert "Lookup" in plan_string |
| 231 | + finally: |
| 232 | + pool.execute_with_retries("DROP TABLE test_explain") |
0 commit comments