Skip to content

Commit 1afb909

Browse files
authored
Fix slow unit tests for FilesExt (#1074)
## What changes are proposed in this pull request? The unit tests for the FilesExt module are very slow because they exercise the retry pathway using a real clock, resulting in long periods spent waiting for retries. For unit tests, this is not necessary; they can use the clock provided in the Config, which is a RealClock by default in production but can be mocked in tests using FakeClock. To fix this, I changed the call of `retried` to use the config's clock, and then I updated the mock Config we provide as a fixture to use the fake clock. ## How is this tested? Existing tests should continue to work & pass. Unit tests should be substantially faster than before. NO_CHANGELOG=true
1 parent 70d1788 commit 1afb909

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

databricks/sdk/mixins/files.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,6 +1337,7 @@ def extended_is_retryable(e: BaseException) -> Optional[str]:
13371337
# where we believe request didn't reach the server
13381338
is_retryable=extended_is_retryable,
13391339
before_retry=before_retry,
1340+
clock=self._config.clock,
13401341
)(delegate)()
13411342

13421343
def _open_download_stream(

tests/conftest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from databricks.sdk.core import Config
99
from databricks.sdk.credentials_provider import credentials_strategy
1010

11+
from .clock import FakeClock
1112
from .integration.conftest import restorable_env # type: ignore
1213

1314

@@ -18,7 +19,7 @@ def noop_credentials(_: any):
1819

1920
@pytest.fixture
2021
def config():
21-
return Config(host="http://localhost", credentials_strategy=noop_credentials)
22+
return Config(host="http://localhost", credentials_strategy=noop_credentials, clock=FakeClock())
2223

2324

2425
@pytest.fixture

0 commit comments

Comments
 (0)