Skip to content

Commit 8beb55b

Browse files
[iris] Address PR review: drop redundant _db.close, bump pytest, harden teardown
- Remove six vestigial controller._db.close() calls in test_checkpoint.py now that the make_controller fixture stops the controller (which closes the DB) at teardown. Each redundant close blocked for ~1s draining the read pool. - Bump pytest>=8.4 in lib/iris dev deps so truncation_limit_lines/chars aren't silently dropped on fresh resolves that pick 8.3.x. - Make the make_controller teardown robust to per-controller stop() failures: collect errors, stop every controller, then re-raise. - Expand the make_controller docstring to cover db= / provider= injection. - Alphabetize the iris.cluster.controller.* import block in conftest.py. Co-authored-by: Russell Power <rjpower@users.noreply.github.com>
1 parent 20d9d20 commit 8beb55b

4 files changed

Lines changed: 24 additions & 19 deletions

File tree

lib/iris/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ dev = [
6363
"pytest-playwright>=0.6.2",
6464
"pytest-timeout",
6565
"pytest-xdist",
66-
"pytest>=8.3.2",
66+
"pytest>=8.4",
6767
]
6868

6969
[tool.hatch.build.hooks.custom]

lib/iris/tests/cluster/controller/conftest.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,16 @@
2828
)
2929
from iris.cluster.controller.autoscaler import Autoscaler
3030
from iris.cluster.controller.autoscaler.models import DemandEntry
31+
from iris.cluster.controller.autoscaler.scaling_group import ScalingGroup
32+
from iris.cluster.controller.controller import Controller, ControllerConfig
3133
from iris.cluster.controller.db import (
3234
ACTIVE_TASK_STATES,
3335
ControllerDB,
3436
_decode_attribute_rows,
3537
task_row_can_be_scheduled,
3638
task_row_is_finished,
3739
)
40+
from iris.cluster.controller.provider import ProviderUnsupportedError
3841
from iris.cluster.controller.schema import (
3942
ATTEMPT_PROJECTION,
4043
JOB_CONFIG_JOIN,
@@ -47,9 +50,6 @@
4750
WorkerRow,
4851
tasks_with_attempts,
4952
)
50-
from iris.cluster.controller.controller import Controller, ControllerConfig
51-
from iris.cluster.controller.provider import ProviderUnsupportedError
52-
from iris.cluster.controller.autoscaler.scaling_group import ScalingGroup
5353
from iris.cluster.controller.service import ControllerServiceImpl
5454
from iris.log_server.server import LogServiceImpl
5555
from iris.cluster.controller.transitions import (
@@ -213,11 +213,21 @@ def make_controller(tmp_path):
213213
monkeypatched ``LogServiceClientSync``. The factory tracks every
214214
constructed controller and ``stop()``s them at fixture teardown.
215215
216+
Pass ``db=`` to inject a pre-built ``ControllerDB`` (otherwise the
217+
``Controller`` opens one under ``config.local_state_dir``). Pass
218+
``provider=`` to override the default ``FakeProvider``. Any remaining
219+
keyword arguments are forwarded to ``ControllerConfig``.
220+
216221
Usage::
217222
218-
def test_foo(make_controller):
223+
def test_foo(make_controller, tmp_path):
219224
ctrl = make_controller(remote_state_dir="file:///tmp/iris-state")
220-
...
225+
# Or inject an existing DB / provider:
226+
ctrl = make_controller(
227+
remote_state_dir="file:///tmp/iris-state",
228+
local_state_dir=tmp_path,
229+
db=my_db,
230+
)
221231
"""
222232
created: list[Controller] = []
223233

@@ -242,8 +252,14 @@ def _factory(
242252
return controller
243253

244254
yield _factory
255+
errors: list[BaseException] = []
245256
for controller in created:
246-
controller.stop()
257+
try:
258+
controller.stop()
259+
except BaseException as exc:
260+
errors.append(exc)
261+
if errors:
262+
raise errors[0]
247263

248264

249265
def make_test_entrypoint() -> job_pb2.RuntimeEntrypoint:

lib/iris/tests/cluster/controller/test_checkpoint.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ def test_write_checkpoint_uploads_compressed(tmp_path, make_controller):
3131
assert result.task_count == 0
3232
assert result.worker_count == 0
3333

34-
controller._db.close()
35-
3634

3735
def test_begin_checkpoint_returns_remote_path(tmp_path, make_controller):
3836
"""begin_checkpoint returns a remote path string."""
@@ -44,8 +42,6 @@ def test_begin_checkpoint_returns_remote_path(tmp_path, make_controller):
4442
assert path.startswith(f"file://{tmp_path}/remote/controller-state/")
4543
assert result.job_count == 0
4644

47-
controller._db.close()
48-
4945

5046
def test_atexit_checkpoint_writes_to_remote(tmp_path, make_controller):
5147
"""_atexit_checkpoint writes directly to remote storage."""
@@ -59,8 +55,6 @@ def test_atexit_checkpoint_writes_to_remote(tmp_path, make_controller):
5955
assert len(timestamped_dirs) >= 1
6056
assert (timestamped_dirs[0] / "controller.sqlite3.zst").exists()
6157

62-
controller._db.close()
63-
6458

6559
def test_download_checkpoint_to_local(tmp_path):
6660
"""download_checkpoint_to_local copies remote DB to local path."""
@@ -101,7 +95,6 @@ def test_write_checkpoint_roundtrip(tmp_path, make_controller):
10195
remote_dir = f"file://{tmp_path}/remote"
10296
controller = make_controller(remote_state_dir=remote_dir)
10397
write_checkpoint(controller._db, remote_dir)
104-
controller._db.close()
10598

10699
local_db_dir = tmp_path / "restored"
107100
download_checkpoint_to_local(remote_dir, local_db_dir)
@@ -123,8 +116,6 @@ def test_write_checkpoint_cleans_up_temp_file(tmp_path, make_controller):
123116
sqlite_temps = [f for f in new_files if ".sqlite3" in f.name and f.name != ControllerDB.DB_FILENAME]
124117
assert len(sqlite_temps) == 0
125118

126-
controller._db.close()
127-
128119

129120
def test_local_db_exists_skips_remote_download(tmp_path):
130121
"""When a local DB already exists, download_checkpoint_to_local should not be called.
@@ -213,8 +204,6 @@ def test_periodic_checkpoint_inline(tmp_path, make_controller):
213204
assert len(timestamped_dirs) >= 1
214205
assert (timestamped_dirs[0] / "controller.sqlite3.zst").exists()
215206

216-
controller._db.close()
217-
218207

219208
def test_download_uncompressed_fallback(tmp_path):
220209
"""download_checkpoint_to_local falls back to uncompressed files from old checkpoints."""

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)