Skip to content

Commit 57c785d

Browse files
krynjuclaude
andcommitted
test: regression tests for deaf-watch fixes
- Watch Events: convert each received event object with kuber_obj — exercises the AbstractDict path (JSON.Object under JSON.jl 1.x) that previously threw MethodError on the first event of every watch. - New "Watch processor failure aborts watch" testset (no cluster needed): a throwing streamprocessor must propagate its error out of watch() promptly instead of leaving @sync waiting on the producer task forever. Verified to hang on the unfixed code. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 35118f6 commit 57c785d

1 file changed

Lines changed: 40 additions & 1 deletion

File tree

test/runtests.jl

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,12 +314,51 @@ function test_versioned(ctx, testid)
314314
@test !isempty(events)
315315
for event in events
316316
@test isa(event, Union{Typedefs.CoreV1.WatchEvent,Typedefs.CoreV1.PodList})
317+
# Watch event objects parse to `JSON.Object` under JSON.jl 1.x —
318+
# an AbstractDict, not a Dict{String,Any}. `kuber_obj` must accept
319+
# them: a MethodError here used to kill the stream processor and
320+
# leave the watch silently deaf (see the watch-processor-failure
321+
# test below for the propagation side).
322+
if isa(event, Typedefs.CoreV1.WatchEvent)
323+
obj = Kuber.kuber_obj(ctx, event.object)
324+
@test isa(obj, OpenAPI.APIModel)
325+
end
317326
end
318327
end
319328
end
320329
end
321330

322-
function test_all()
331+
function function test_watch_processor_failure()
332+
# A `streamprocessor` that throws must abort the watch promptly and
333+
# propagate the error. Before the fix, the processor task died silently
334+
# while `@sync` kept waiting on the (long-running) `watched` task — a
335+
# deaf watch: events kept buffering with no error surfaced until the
336+
# server dropped the connection.
337+
ctx = KuberContext() # only passed through to KuberWatchContext; no server needed
338+
producer = (watchctx) -> begin
339+
# mimic the HTTP watch task: keep streaming events; ends only when the
340+
# stream is closed under it (put! on a closed channel throws)
341+
i = 0
342+
while true
343+
put!(watchctx.stream, (i += 1))
344+
sleep(0.05)
345+
end
346+
end
347+
t0 = time()
348+
@test_throws Exception watch(ctx, producer) do stream
349+
take!(stream)
350+
error("processor failure")
351+
end
352+
# must fail fast — processor death closes the stream, which kills the
353+
# producer's next put! — not linger until the producer would have ended
354+
@test (time() - t0) < 10.0
355+
end
356+
357+
@testset "Watch processor failure aborts watch" begin
358+
test_watch_processor_failure()
359+
end
360+
361+
test_all()
323362
ctx = init_context()
324363
@testset "Kuber Tests" begin
325364
@testset "Server Preferred API Versions" begin

0 commit comments

Comments
 (0)