Skip to content

Commit fcf1d1b

Browse files
rustyconoverclaude
andcommitted
ci: make the suite green again
Three independent reds, none of which CI could have caught before the work that introduced them landed: mypy tests/. Six errors were mine, from the aggregate/COPY client tests -- I ran `mypy vgi/` but never `mypy tests/`, which CI runs separately. A heterogeneous `pa.schema([pa.field(...), ...])` infers `list[object]`, so those go through the `vgi.schema(...)` helper instead; the writer options dict needs an explicit `dict[str, pa.Scalar[Any]]` annotation to survive dict invariance; and read_schema takes a Buffer, not a BufferReader. Drops a tautological `assert copy_to(...) is None` -- the contract it gestured at (a COPY-TO sink has no Source phase) is what test_copy_to_rejects_a_non_copy_handler actually pins. mypy + ruff format on the Rust codegen. Two stale `# type: ignore[attr-defined]` on `rpc_methods` (it resolves now, as the un-ignored import in ts_client.py already showed), a dict-invariance error, and three files that were committed unformatted. pa.map_'s `keys_sorted` keeps a narrow ignore: the runtime keyword really is `keys_sorted` taking a bool, and pyarrow-stubs says `key_sorted` taking a literal. A teardown flake that predates all of it. `proc.wait(timeout=...)` was unguarded, so a worker slow to exit raised TimeoutExpired straight out of `stop()` / `__exit__` -- leaking the process and masking whatever exception was already unwinding. On main this reddens whichever test happens to be teardown-adjacent under load; stashing the fix and running tests/client tests/table tests/scalar reproduced it 4 runs out of 4, across three different files. Now the wait kills and reaps on timeout, and PROCESS_WAIT_TIMEOUT goes 5s -> 30s: it is a hang guard, not a latency budget, and a saturated machine (the suite under `pytest -n auto`, each fixture worker booting its own sub-workers) can push a perfectly clean exit past five seconds. The regression test forces the timed wait to raise rather than shrinking the budget, so it does not race a worker that exits promptly. Same slice: 4/4 flaky before, 5/5 clean after; full suite 3/3 clean. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 48b69d2 commit fcf1d1b

8 files changed

Lines changed: 156 additions & 74 deletions

‎tests/client/test_aggregate_client.py‎

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import pyarrow as pa
2020
import pytest
2121

22+
from vgi import schema
2223
from vgi.arguments import Arguments
2324
from vgi.client.client import Client, ClientError
2425

@@ -34,10 +35,10 @@ def client(client_transport: Any) -> Any:
3435

3536
def _grouped_batches() -> list[pa.RecordBatch]:
3637
"""Two batches whose groups straddle the batch boundary."""
37-
schema = pa.schema([pa.field("cat", pa.string()), pa.field("value", pa.int64())])
38+
s = schema(cat=pa.string(), value=pa.int64())
3839
return [
39-
pa.RecordBatch.from_pydict({"cat": ["a", "b", "a"], "value": [1, 10, 2]}, schema=schema),
40-
pa.RecordBatch.from_pydict({"cat": ["b", "a"], "value": [20, 3]}, schema=schema),
40+
pa.RecordBatch.from_pydict({"cat": ["a", "b", "a"], "value": [1, 10, 2]}, schema=s),
41+
pa.RecordBatch.from_pydict({"cat": ["b", "a"], "value": [20, 3]}, schema=s),
4142
]
4243

4344

@@ -90,15 +91,15 @@ def test_grouped_over_empty_input_is_zero_rows(self, client: Client) -> None:
9091
schema_name=MAIN,
9192
input=[],
9293
group_by=["cat"],
93-
input_schema=pa.schema([pa.field("value", pa.int64())]),
94+
input_schema=schema(value=pa.int64()),
9495
)
9596
assert out.num_rows == 0
9697
assert out.schema.names == ["cat", "result"]
9798

9899
def test_empty_batches_are_skipped(self, client: Client) -> None:
99100
"""A zero-row batch contributes nothing but must not break the drive loop."""
100-
schema = pa.schema([pa.field("value", pa.int64())])
101-
empty = pa.RecordBatch.from_pydict({"value": pa.array([], type=pa.int64())}, schema=schema)
101+
s = schema(value=pa.int64())
102+
empty = pa.RecordBatch.from_pydict({"value": pa.array([], type=pa.int64())}, schema=s)
102103
out = client.aggregate_function(function_name="vgi_sum", schema_name=MAIN, input=[empty, _values(5), empty])
103104
assert out.column("result").to_pylist() == [5]
104105

@@ -214,7 +215,7 @@ def test_bind_reports_execution_id_and_output_schema(self, client: Client) -> No
214215
with client.aggregate_session(
215216
function_name="vgi_sum",
216217
schema_name=MAIN,
217-
input_schema=pa.schema([pa.field("value", pa.int64())]),
218+
input_schema=schema(value=pa.int64()),
218219
) as session:
219220
assert session.execution_id
220221
assert session.output_schema.names == ["result"]
@@ -224,7 +225,7 @@ def test_update_then_finalize(self, client: Client) -> None:
224225
with client.aggregate_session(
225226
function_name="vgi_sum",
226227
schema_name=MAIN,
227-
input_schema=pa.schema([pa.field("value", pa.int64())]),
228+
input_schema=schema(value=pa.int64()),
228229
) as session:
229230
session.update(group_ids=[0, 1, 0], batch=_values(1, 100, 2))
230231
session.update(group_ids=[1], batch=_values(200))
@@ -234,7 +235,7 @@ def test_finalize_order_follows_requested_group_ids(self, client: Client) -> Non
234235
with client.aggregate_session(
235236
function_name="vgi_sum",
236237
schema_name=MAIN,
237-
input_schema=pa.schema([pa.field("value", pa.int64())]),
238+
input_schema=schema(value=pa.int64()),
238239
) as session:
239240
session.update(group_ids=[0, 1], batch=_values(7, 9))
240241
assert session.finalize([1, 0]).column("result").to_pylist() == [9, 7]
@@ -244,7 +245,7 @@ def test_finalize_of_never_updated_group_is_null(self, client: Client) -> None:
244245
with client.aggregate_session(
245246
function_name="vgi_sum",
246247
schema_name=MAIN,
247-
input_schema=pa.schema([pa.field("value", pa.int64())]),
248+
input_schema=schema(value=pa.int64()),
248249
) as session:
249250
assert session.finalize([42]).column("result").to_pylist() == [None]
250251

@@ -253,7 +254,7 @@ def test_combine_merges_source_into_target(self, client: Client) -> None:
253254
with client.aggregate_session(
254255
function_name="vgi_sum",
255256
schema_name=MAIN,
256-
input_schema=pa.schema([pa.field("value", pa.int64())]),
257+
input_schema=schema(value=pa.int64()),
257258
) as session:
258259
session.update(group_ids=[0, 0, 1], batch=_values(1, 2, 100))
259260
session.combine(source_group_ids=[1], target_group_ids=[0])
@@ -264,7 +265,7 @@ def test_update_rejects_mismatched_row_counts(self, client: Client) -> None:
264265
client.aggregate_session(
265266
function_name="vgi_sum",
266267
schema_name=MAIN,
267-
input_schema=pa.schema([pa.field("value", pa.int64())]),
268+
input_schema=schema(value=pa.int64()),
268269
) as session,
269270
pytest.raises(ValueError, match="group_ids has 2 entries but batch has 3 rows"),
270271
):
@@ -275,7 +276,7 @@ def test_combine_rejects_mismatched_lengths(self, client: Client) -> None:
275276
client.aggregate_session(
276277
function_name="vgi_sum",
277278
schema_name=MAIN,
278-
input_schema=pa.schema([pa.field("value", pa.int64())]),
279+
input_schema=schema(value=pa.int64()),
279280
) as session,
280281
pytest.raises(ValueError, match="source_group_ids has 2 entries"),
281282
):
@@ -285,7 +286,7 @@ def test_group_ids_accept_arrow_arrays(self, client: Client) -> None:
285286
with client.aggregate_session(
286287
function_name="vgi_sum",
287288
schema_name=MAIN,
288-
input_schema=pa.schema([pa.field("value", pa.int64())]),
289+
input_schema=schema(value=pa.int64()),
289290
) as session:
290291
session.update(group_ids=pa.array([5, 5], type=pa.int32()), batch=_values(4, 6))
291292
assert session.finalize(pa.array([5], type=pa.int64())).column("result").to_pylist() == [10]
@@ -295,7 +296,7 @@ def test_destroy_is_idempotent(self, client: Client) -> None:
295296
session = client.aggregate_bind(
296297
function_name="vgi_sum",
297298
schema_name=MAIN,
298-
input_schema=pa.schema([pa.field("value", pa.int64())]),
299+
input_schema=schema(value=pa.int64()),
299300
)
300301
session.destroy()
301302
session.destroy()
@@ -312,7 +313,7 @@ def test_window_over_a_partition(self, client: Client) -> None:
312313
with client.aggregate_session(
313314
function_name="vgi_window_sum",
314315
schema_name=MAIN,
315-
input_schema=pa.schema([pa.field("value", pa.int64())]),
316+
input_schema=schema(value=pa.int64()),
316317
) as session:
317318
session.window_init(partition_id=0, partition=_values(1, 2, 3, 4))
318319
assert session.window(partition_id=0, rid=0, frames=[(0, 1)]).column("result").to_pylist() == [1]
@@ -324,7 +325,7 @@ def test_window_batch_computes_many_rows_at_once(self, client: Client) -> None:
324325
with client.aggregate_session(
325326
function_name="vgi_window_sum_batch",
326327
schema_name=MAIN,
327-
input_schema=pa.schema([pa.field("value", pa.int64())]),
328+
input_schema=schema(value=pa.int64()),
328329
) as session:
329330
session.window_init(partition_id=0, partition=_values(1, 2, 3, 4))
330331
running = session.window_batch(partition_id=0, row_idx=0, frames=[[(0, end + 1)] for end in range(4)])
@@ -336,7 +337,7 @@ def test_window_filter_mask_excludes_rows(self, client: Client) -> None:
336337
with client.aggregate_session(
337338
function_name="vgi_window_sum",
338339
schema_name=MAIN,
339-
input_schema=pa.schema([pa.field("value", pa.int64())]),
340+
input_schema=schema(value=pa.int64()),
340341
) as session:
341342
session.window_init(
342343
partition_id=0,
@@ -352,7 +353,7 @@ def test_several_partitions_are_independent(self, client: Client) -> None:
352353
with client.aggregate_session(
353354
function_name="vgi_window_sum",
354355
schema_name=MAIN,
355-
input_schema=pa.schema([pa.field("value", pa.int64())]),
356+
input_schema=schema(value=pa.int64()),
356357
) as session:
357358
session.window_init(partition_id=0, partition=_values(1, 1))
358359
session.window_init(partition_id=1, partition=_values(100, 100))
@@ -366,7 +367,7 @@ def test_window_on_an_unknown_partition_raises(self, client: Client) -> None:
366367
client.aggregate_session(
367368
function_name="vgi_window_sum",
368369
schema_name=MAIN,
369-
input_schema=pa.schema([pa.field("value", pa.int64())]),
370+
input_schema=schema(value=pa.int64()),
370371
) as session,
371372
pytest.raises(ClientError),
372373
):
@@ -381,34 +382,34 @@ def test_window_on_an_unknown_partition_raises(self, client: Client) -> None:
381382
class TestAggregateStreaming:
382383
@staticmethod
383384
def _schema() -> pa.Schema:
384-
return pa.schema([pa.field("k", pa.string()), pa.field("ts", pa.int64()), pa.field("v", pa.int64())])
385+
return schema(k=pa.string(), ts=pa.int64(), v=pa.int64())
385386

386387
def test_running_value_per_row(self, client: Client) -> None:
387388
"""One output row per input row: the partition's value at that position."""
388-
schema = self._schema()
389+
s = self._schema()
389390
with client.aggregate_streaming(
390391
function_name="vgi_streaming_sum",
391392
schema_name=MAIN,
392-
input_schema=schema,
393+
input_schema=s,
393394
partition_key_count=1,
394395
order_key_count=1,
395396
) as session:
396397
chunk = pa.RecordBatch.from_pydict(
397-
{"k": ["a", "b", "a", "b"], "ts": [1, 1, 2, 2], "v": [1, 10, 2, 20]}, schema=schema
398+
{"k": ["a", "b", "a", "b"], "ts": [1, 1, 2, 2], "v": [1, 10, 2, 20]}, schema=s
398399
)
399400
assert session.chunk(chunk).column(0).to_pylist() == [1, 10, 3, 30]
400401

401402
def test_state_carries_across_chunks(self, client: Client) -> None:
402-
schema = self._schema()
403+
s = self._schema()
403404
with client.aggregate_streaming(
404405
function_name="vgi_streaming_sum",
405406
schema_name=MAIN,
406-
input_schema=schema,
407+
input_schema=s,
407408
partition_key_count=1,
408409
order_key_count=1,
409410
) as session:
410-
first = pa.RecordBatch.from_pydict({"k": ["a"], "ts": [1], "v": [5]}, schema=schema)
411-
second = pa.RecordBatch.from_pydict({"k": ["a"], "ts": [2], "v": [7]}, schema=schema)
411+
first = pa.RecordBatch.from_pydict({"k": ["a"], "ts": [1], "v": [5]}, schema=s)
412+
second = pa.RecordBatch.from_pydict({"k": ["a"], "ts": [2], "v": [7]}, schema=s)
412413
assert session.chunk(first).column(0).to_pylist() == [5]
413414
assert session.chunk(second).column(0).to_pylist() == [12]
414415

‎tests/client/test_copy_client.py‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import pyarrow as pa
1919
import pytest
2020

21+
from vgi import schema
2122
from vgi.arguments import Arguments
2223
from vgi.client.client import Client, ClientError
2324

@@ -27,7 +28,7 @@
2728
WRITER = "example_lines_writer"
2829
WRITER_FORMAT = "example_lines_out"
2930

30-
SOURCE_SCHEMA = pa.schema([pa.field("a", pa.int32()), pa.field("b", pa.string())])
31+
SOURCE_SCHEMA = schema(a=pa.int32(), b=pa.string())
3132

3233

3334
@pytest.fixture
@@ -44,9 +45,9 @@ def _rows() -> list[pa.RecordBatch]:
4445
]
4546

4647

47-
def _write(client: Client, dest: str, **options: Any) -> None:
48+
def _write(client: Client, dest: str, **options: pa.Scalar[Any]) -> None:
4849
"""Run the fixture writer with ``null_string`` plus whatever else is asked."""
49-
named = {"null_string": pa.scalar("NA")}
50+
named: dict[str, pa.Scalar[Any]] = {"null_string": pa.scalar("NA")}
5051
named.update(options)
5152
client.copy_to(
5253
function_name=WRITER,
@@ -71,11 +72,6 @@ def test_writes_the_destination(self, client: Client, tmp_path: pathlib.Path) ->
7172
_write(client, dest)
7273
assert pathlib.Path(dest).read_text() == "1,x\n2,NA\n3,z\n"
7374

74-
def test_returns_nothing(self, client: Client, tmp_path: pathlib.Path) -> None:
75-
"""A COPY-TO sink has no Source phase, so the driver returns None."""
76-
dest = str(tmp_path / "out.txt")
77-
assert _write(client, dest) is None
78-
7975
def test_options_reach_the_writer(self, client: Client, tmp_path: pathlib.Path) -> None:
8076
"""COPY options arrive as the function's normal named arguments."""
8177
dest = str(tmp_path / "out.psv")
@@ -267,7 +263,7 @@ def test_copy_formats_advertises_option_schemas(client: Client) -> None:
267263
attached = client.catalog_attach(name="example", data_version_spec=None, implementation_version=None)
268264
formats = {f.format_name: f for f in client.copy_formats(attach_opaque_data=attached.attach_opaque_data)}
269265

270-
options = pa.ipc.read_schema(pa.BufferReader(bytes(formats[READER_FORMAT].options)))
266+
options = pa.ipc.read_schema(pa.py_buffer(formats[READER_FORMAT].options))
271267
assert set(options.names) == {"null_string", "delimiter", "skip_rows", "on_error"}
272268

273269

‎tests/client/test_stop_force.py‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
from __future__ import annotations
1717

18+
import subprocess
1819
import sys
1920
import time
2021
from typing import Any
@@ -99,3 +100,36 @@ def test_client_can_restart_after_a_forced_stop() -> None:
99100
assert client._primary is not None # noqa: SLF001 - restart sanity check
100101
finally:
101102
client.stop()
103+
104+
105+
def test_graceful_stop_kills_a_worker_that_overruns_the_wait() -> None:
106+
"""A worker that outlives the exit wait is killed, not raised out of ``stop()``.
107+
108+
``proc.wait(timeout=...)`` raises ``TimeoutExpired``, and letting that escape
109+
would leak the process *and* mask whatever exception was already unwinding
110+
through ``__exit__``. Forcing the timed wait to raise is deterministic;
111+
shrinking ``PROCESS_WAIT_TIMEOUT`` instead would race a worker that happens
112+
to exit promptly.
113+
"""
114+
client = _started_client(pool=None)
115+
assert client._primary is not None # noqa: SLF001 - a started client always has one
116+
proc = client._primary.proc # noqa: SLF001 - asserting the process really died
117+
assert proc is not None
118+
119+
real_wait = proc.wait
120+
timed_waits: list[float | None] = []
121+
122+
def wait_that_times_out(timeout: float | None = None) -> int:
123+
if timeout is None: # the untimed reap after the kill
124+
return real_wait()
125+
timed_waits.append(timeout)
126+
raise subprocess.TimeoutExpired(proc.args, timeout)
127+
128+
proc.wait = wait_that_times_out # type: ignore[method-assign]
129+
130+
returncode = client.stop()
131+
132+
assert timed_waits, "stop() should have waited on the worker with a timeout"
133+
assert proc.poll() is not None, "worker process should be reaped, not left running"
134+
if sys.platform != "win32":
135+
assert returncode < 0, "the timeout path kills, so the exit code is a signal"

‎tests/test_generated_rust_request_builders.py‎

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import re
1919
from pathlib import Path
2020

21+
import pyarrow as pa
2122
import pytest
2223

2324
from vgi.codegen._common import collect_schemas, sanitize_name
@@ -28,14 +29,7 @@ def _vgi_rust_generated_path() -> Path:
2829
override = os.environ.get("VGI_RUST_GENERATED_PARAMS_RS")
2930
if override:
3031
return Path(override)
31-
return (
32-
Path(__file__).resolve().parents[2]
33-
/ "vgi-rust"
34-
/ "vgi-protocol"
35-
/ "src"
36-
/ "generated"
37-
/ "request_params.rs"
38-
)
32+
return Path(__file__).resolve().parents[2] / "vgi-rust" / "vgi-protocol" / "src" / "generated" / "request_params.rs"
3933

4034

4135
_REGEN_HINT = (
@@ -57,8 +51,8 @@ def test_generator_is_deterministic() -> None:
5751
assert _emitted() == _emitted(), "rust_request_builders generator is non-deterministic"
5852

5953

60-
def _params_by_method() -> dict[str, object]:
61-
out = {}
54+
def _params_by_method() -> dict[str, pa.Schema]:
55+
out: dict[str, pa.Schema] = {}
6256
for es in collect_schemas():
6357
if es.name.endswith("Params"):
6458
out[es.origin.split("'")[1]] = es.schema
@@ -106,19 +100,15 @@ def test_every_emitted_struct_derives_vgi_arrow() -> None:
106100
structs = re.findall(r"pub struct (\w+Params) \{", src)
107101
assert structs, "no structs emitted"
108102
derives = re.findall(r"#\[derive\(Debug, Clone, VgiArrow\)\]\npub struct (\w+Params) \{", src)
109-
assert set(structs) == set(derives), (
110-
f"structs missing the VgiArrow derive: {sorted(set(structs) - set(derives))}"
111-
)
103+
assert set(structs) == set(derives), f"structs missing the VgiArrow derive: {sorted(set(structs) - set(derives))}"
112104

113105

114106
def test_parity_test_module_covers_every_struct() -> None:
115107
"""The emitted Rust test must assert on each struct it ships beside."""
116108
src = _emitted()
117109
structs = set(re.findall(r"pub struct (\w+Params) \{", src))
118110
asserted = set(re.findall(r"flat_schema::<(\w+Params)>\(\)", src))
119-
assert structs == asserted, (
120-
f"schema_parity module does not cover: {sorted(structs - asserted)}"
121-
)
111+
assert structs == asserted, f"schema_parity module does not cover: {sorted(structs - asserted)}"
122112

123113

124114
def test_checked_in_rust_matches_generator() -> None:

0 commit comments

Comments
 (0)