Skip to content

Commit e64992a

Browse files
rustyconoverclaude
andcommitted
fixtures: add buffered_table failure-injection functions
Adds five fixtures used by the C++ extension's new failure-mode tests: - CrashOnProcessFunction — SIGKILLs its own worker during process() - CrashOnCombineFunction — raises during combine() - CrashOnFinalizeFunction — raises during finalize() - HangOnProcessFunction — sleeps in process() (manual cancel smoke) - LargeStateFunction — accumulates ~1 MB per batch into state, exercises IPC chunking on the combine/finalize response path All subclass BufferInputFunction (or use the same TableInOutGenerator shape) so the override surface stays small. Registered in the fixture worker's function list. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 13d7edb commit e64992a

2 files changed

Lines changed: 191 additions & 0 deletions

File tree

‎vgi/_test_fixtures/table_in_out.py‎

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,18 @@
2525
ExceptionProcessFunction - Raises exception during process (test)
2626
ExceptionFinalizeFunction - Raises exception during finalize (test)
2727
SumAllColumnsSimpleDistributed - Distributed aggregation via callback API
28+
CrashOnProcessFunction - SIGKILLs the worker mid-process (test)
29+
CrashOnCombineFunction - Raises during combine() (test)
30+
CrashOnFinalizeFunction - Raises during finalize() (test)
31+
HangOnProcessFunction - Sleeps forever in process() (manual cancel test)
32+
LargeStateFunction - Buffers ~N MB per state_id (IPC chunking test)
2833
"""
2934

3035
from __future__ import annotations
3136

37+
import os
38+
import signal
39+
import time
3240
from dataclasses import dataclass, field
3341
from collections.abc import Iterator
3442
from typing import Annotated, Any
@@ -59,6 +67,11 @@
5967
"SumAllColumnsSimpleDistributed",
6068
"ExceptionProcessFunction",
6169
"ExceptionFinalizeFunction",
70+
"CrashOnProcessFunction",
71+
"CrashOnCombineFunction",
72+
"CrashOnFinalizeFunction",
73+
"HangOnProcessFunction",
74+
"LargeStateFunction",
6275
]
6376

6477

@@ -755,3 +768,171 @@ def finish(
755768
sums[field.name] = pc.sum(table.column(field.name))
756769

757770
return [pa.RecordBatch.from_pylist([{name: val for name, val in sums.items()}], schema=params.output_schema)]
771+
772+
773+
# ============================================================================
774+
# Failure-injection fixtures
775+
# ============================================================================
776+
# These are buffered_table functions designed to exercise crash/error paths in
777+
# the C++ Sink+Source operator. Each one fails in a specific phase so we can
778+
# test that the operator: throws cleanly, drains the worker pool, doesn't leak
779+
# in-flight workers, and recovers on the next query.
780+
781+
782+
class CrashOnProcessFunction(BufferInputFunction):
783+
"""SIGKILLs its own worker process on the first process() call.
784+
785+
Tests the C++ side's handling of an abrupt worker death mid-RPC:
786+
subprocess writes the request, worker dies before responding, ReadUnary
787+
sees EOF / EPIPE / SIGCHLD depending on timing. The exception should
788+
propagate cleanly and gstate teardown should cancel-dispatch peer workers.
789+
"""
790+
791+
class Meta(BufferInputFunction.Meta):
792+
name = "crash_on_process"
793+
description = "Worker SIGKILLs itself during process (test)"
794+
categories = ["test", "crash"]
795+
796+
@classmethod
797+
def process( # type: ignore[override]
798+
cls,
799+
params: ProcessParams[SingleTableArguments],
800+
state: BufferInputState,
801+
batch: pa.RecordBatch,
802+
out: OutputCollector,
803+
) -> None:
804+
# SIGKILL with no handler; the process dies immediately. The C++
805+
# side has a pending unary RPC awaiting the response.
806+
os.kill(os.getpid(), signal.SIGKILL)
807+
808+
809+
class CrashOnCombineFunction(BufferInputFunction):
810+
"""Buffers input normally; raises during combine().
811+
812+
Tests that a combine RPC error propagates as IOException, that the
813+
combine_worker is dropped (not pushed back into gstate.workers), and
814+
that the rest of the worker pool drains.
815+
"""
816+
817+
class Meta(BufferInputFunction.Meta):
818+
name = "crash_on_combine"
819+
description = "Worker raises during combine (test)"
820+
categories = ["test", "crash"]
821+
822+
@classmethod
823+
def combine( # type: ignore[override]
824+
cls, state_ids: list[int], params: ProcessParams[SingleTableArguments]
825+
) -> list[int]:
826+
raise RuntimeError("Intentional exception during combine()")
827+
828+
829+
class CrashOnFinalizeFunction(BufferInputFunction):
830+
"""Buffers input, combine returns normally, finalize raises on first yield.
831+
832+
Tests source-phase error propagation: GetData calls
833+
RpcBufferedTableFinalize, the worker raises, the IOException unwinds the
834+
source thread, and remaining workers are still released cleanly.
835+
"""
836+
837+
class Meta(BufferInputFunction.Meta):
838+
name = "crash_on_finalize"
839+
description = "Worker raises during finalize (test)"
840+
categories = ["test", "crash"]
841+
842+
@classmethod
843+
def finalize( # type: ignore[override]
844+
cls, finalize_state_id: int, params: ProcessParams[SingleTableArguments]
845+
) -> Iterator[pa.RecordBatch]:
846+
raise RuntimeError("Intentional exception during finalize()")
847+
yield # type: ignore[unreachable] # make this a generator function
848+
849+
850+
class HangOnProcessFunction(BufferInputFunction):
851+
"""Sleeps for an hour in process(); used by the manual cancellation smoke.
852+
853+
sqllogictest can't simulate Ctrl-C cleanly, so this fixture is driven by
854+
scripts/smoke_buffered_cancel.sh — it starts the query, waits a moment,
855+
then SIGINTs the duckdb process and asserts the query was cancelled.
856+
"""
857+
858+
class Meta(BufferInputFunction.Meta):
859+
name = "hang_on_process"
860+
description = "Worker sleeps in process (manual cancel test)"
861+
categories = ["test", "hang"]
862+
863+
@classmethod
864+
def process( # type: ignore[override]
865+
cls,
866+
params: ProcessParams[SingleTableArguments],
867+
state: BufferInputState,
868+
batch: pa.RecordBatch,
869+
out: OutputCollector,
870+
) -> None:
871+
time.sleep(3600)
872+
873+
874+
@dataclass(kw_only=True)
875+
class LargeStateState(ArrowSerializableDataclass):
876+
"""Holds a single large bytes buffer; the C++ side ships this through
877+
combine/finalize via the RPC's outer envelope, exercising IPC chunking
878+
on the response path."""
879+
880+
payload: bytes = b""
881+
882+
883+
class LargeStateFunction(TableInOutGenerator[SingleTableArguments, LargeStateState]):
884+
"""Accumulates a large payload per state_id and emits it during finalize.
885+
886+
Each process() call appends N KB to the per-state_id payload. The total
887+
bytes per finalize_state_id grows linearly with input row count. The
888+
test passes ~100 MB through combine to exercise the IPC chunking that
889+
happens transparently in vgi_rpc for large messages.
890+
"""
891+
892+
state_class = LargeStateState
893+
894+
class Meta:
895+
name = "large_state"
896+
description = "Buffers ~1 MB per input batch into state (IPC test)"
897+
categories = ["test", "memory"]
898+
buffered_table = True
899+
900+
@classmethod
901+
def initial_state(cls, params: ProcessParams[SingleTableArguments]) -> LargeStateState:
902+
return LargeStateState()
903+
904+
@classmethod
905+
def process(
906+
cls,
907+
params: ProcessParams[SingleTableArguments],
908+
state: LargeStateState,
909+
batch: pa.RecordBatch,
910+
out: OutputCollector,
911+
) -> None:
912+
# Append 1 MB of zero bytes per input batch. Combine ships the full
913+
# accumulated payload back via Arrow IPC; chunking is the worker
914+
# library's responsibility — we just want to land a multi-MB message
915+
# on the wire.
916+
state.payload += b"\x00" * (1024 * 1024)
917+
out.emit(empty_batch(params.output_schema))
918+
919+
@classmethod
920+
def combine(
921+
cls, state_ids: list[int], params: ProcessParams[SingleTableArguments]
922+
) -> list[int]:
923+
return state_ids
924+
925+
@classmethod
926+
def finalize(
927+
cls, finalize_state_id: int, params: ProcessParams[SingleTableArguments]
928+
) -> Iterator[pa.RecordBatch]:
929+
stored = params.storage.aggregate_get([finalize_state_id])
930+
if not stored or stored[0] is None:
931+
return
932+
state = LargeStateState.deserialize_from_bytes(stored[0][1])
933+
# Emit one row with the payload length so the test can assert
934+
# we round-tripped the right number of bytes through combine.
935+
yield pa.RecordBatch.from_pydict(
936+
{name: [len(state.payload)] for name in params.output_schema.names},
937+
schema=params.output_schema,
938+
)

‎vgi/_test_fixtures/worker.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,15 @@
159159
)
160160
from vgi._test_fixtures.table_in_out import (
161161
BufferInputFunction,
162+
CrashOnCombineFunction,
163+
CrashOnFinalizeFunction,
164+
CrashOnProcessFunction,
162165
EchoFunction,
163166
ExceptionFinalizeFunction,
164167
ExceptionProcessFunction,
165168
FilterBySettingFunction,
169+
HangOnProcessFunction,
170+
LargeStateFunction,
166171
RepeatInputsFunction,
167172
SumAllColumnsFunction,
168173
SumAllColumnsSimpleDistributed,
@@ -286,6 +291,11 @@ def _build_enum_stats() -> dict[str, ColumnStatisticsInput]:
286291
UnnestTensorRowsFunction,
287292
ExceptionFinalizeFunction,
288293
ExceptionProcessFunction,
294+
CrashOnProcessFunction,
295+
CrashOnCombineFunction,
296+
CrashOnFinalizeFunction,
297+
HangOnProcessFunction,
298+
LargeStateFunction,
289299
# TableFunctionGenerator - generate output without input
290300
ConstantColumnsFunction,
291301
SlowCancellableFunction,

0 commit comments

Comments
 (0)