зеркало из https://github.com/Azure/pykusto.git
fixed bug with retry config override for a query + added a matching test (#159)
* fixed bug with retry config override for a query + added a matching test * adapted the test after pull from latest master version Co-authored-by: Ofri Kleinfeld <okleinfeld@microsoft.com>
This commit is contained in:
Родитель
68121cdd79
Коммит
c42dea7d4b
|
@ -371,7 +371,7 @@ class Table(_ItemFetcher):
|
||||||
return KQL(table_names[0])
|
return KQL(table_names[0])
|
||||||
|
|
||||||
def execute(self, query: KQL, retry_config: RetryConfig = None) -> KustoResponse:
|
def execute(self, query: KQL, retry_config: RetryConfig = None) -> KustoResponse:
|
||||||
return self.__database.execute(query, retry_config)
|
return self.__database.execute(query, retry_config=retry_config)
|
||||||
|
|
||||||
def get_columns_names(self) -> Generator[str, None, None]:
|
def get_columns_names(self) -> Generator[str, None, None]:
|
||||||
yield from self._get_item_names()
|
yield from self._get_item_names()
|
||||||
|
|
|
@ -222,3 +222,28 @@ class TestClient(TestBase):
|
||||||
KustoError("Mock exception for test", None),
|
KustoError("Mock exception for test", None),
|
||||||
lambda: Query(table).take(5).execute(),
|
lambda: Query(table).take(5).execute(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_override_retry_config_for_query(self):
|
||||||
|
num_retries = 2
|
||||||
|
num_failed_attempts = num_retries - 1
|
||||||
|
retry_sleep_time = 0.1
|
||||||
|
|
||||||
|
mock_kusto_client = self.unreliable_mock_kusto_client(num_failed_attempts)
|
||||||
|
table = PyKustoClient(mock_kusto_client, fetch_by_default=False)['test_db']['mock_table']
|
||||||
|
retry_config = RetryConfig(num_retries, sleep_time=retry_sleep_time, jitter=0)
|
||||||
|
|
||||||
|
with self.assertLogs(_logger, logging.INFO) as cm:
|
||||||
|
Query(table).take(5).execute(retry_config=retry_config)
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
[RecordedQuery('test_db', 'mock_table | take 5')] * num_retries,
|
||||||
|
mock_kusto_client.recorded_queries
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
[
|
||||||
|
f"INFO:pykusto:Attempt number {num_failed_attempts} out of {num_retries} failed, "
|
||||||
|
f"previous sleep time was {retry_sleep_time} seconds. "
|
||||||
|
f"Exception: KustoServiceError('Mock exception for test')"
|
||||||
|
],
|
||||||
|
cm.output
|
||||||
|
)
|
||||||
|
|
Загрузка…
Ссылка в новой задаче