Skip to content

test(pyamber): extend the StartWorkerHandler unit tests - #7061

Merged
aglinxinyuan merged 1 commit into
apache:mainfrom
eugenegujing:test/start-worker-handler-spec
Jul 30, 2026
Merged

aglinxinyuan merged 1 commit into
apache:mainfrom
eugenegujing:test/start-worker-handler-spec

Conversation

@eugenegujing

@eugenegujing eugenegujing commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

What changes were proposed in this PR?

Rewrites amber/src/test/python/core/architecture/handlers/control/test_start_worker_handler.py, added by #6988 while this PR was open, to cover all three branches of StartWorkerHandler and the shared tail.

Four behaviors the previous file did not assert:

Behavior Why it matters
Branch precedence is_source wins even when materialization reader threads exist, so the elif predicate must go unqueried
Empty marker scope A self-addressed marker propagates nowhere
EmptyRequest unwrapped via get_one_of AsyncRpcServer unwraps the payload before dispatching; an unset oneof delivers None, and betterproto's __eq__ cannot see the difference
Markers land on the data sub-queue ECMElements are data traffic, so a source worker's own start/end markers are gated by disable_data — pause and backpressure — unlike control messages

It also pins the ordering of add_input_port before register_input (the reverse raises KeyError on a real InputManager, since register_input ends with self._ports[port_id].add_channel(...)).

Six tests run against real collaborators — a StateManager built on the production transition graph and a real InputManager sharing the context's InternalQueue — rather than mocks, because they pin behavior mocks cannot express: a rejected transition from UNINITIALIZED leaves the queue, the state and the InputManager untouched; the two markers are routed to the data sub-queue; and the response version tracks the real state clock on both the source and the non-source paths. The two non-source cases (READY/0 with reader threads, PAUSED/1 echoed untouched) carry over from #6988; everything else that file asserted is subsumed by a stricter assertion here.

test_double_start_enqueues_a_second_pair_of_markers deliberately pins observed current behavior rather than correctness. StateManager.transit_to returns early when the target equals the current state, so a second StartWorker is a silent no-op on the state and appends another marker pair — including a second PORT_ALIGNMENT EndChannel on the same port. The test comment says so and asks for a rewrite if an idempotency guard is ever added.

Test-only change; no production code is touched.

Any related issues, documentation, discussions?

Closes #7058.

The real-collaborator tests double as a Python-side guard against the stale-state-snapshot family of bugs described in #6010 (WorkerExecution.scala:56); a mocked get_state_with_version returns a constant and cannot catch a hoisted snapshot.

How was this PR tested?

New unit tests only; no production behavior changes.

cd amber
pytest src/test/python/core/architecture/handlers/ -q
  • 23 cases in this file; the handlers package goes from 46 to 69 passing tests.
  • black --check and ruff check clean.

Was this PR authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Opus 5)

@github-actions

github-actions Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Automated Reviewer Suggestions

Based on the git blame history of the changed files, we recommend the following reviewers:

  • Contributors with relevant context: @aglinxinyuan
    You can notify them by mentioning @aglinxinyuan in a comment.

Rewrites test_start_worker_handler.py, added by apache#6988, to cover all three
branches and the shared tail. The source branch pins the RUNNING transition,
the synthetic port and SOURCE_STARTER channel registration (including their
order, since the reverse raises KeyError on a real InputManager), and the
ordered pair of enqueued ECMElements: StartChannel with NO_ALIGNMENT then
EndChannel with PORT_ALIGNMENT, both carrying the no-reply command id -1.
Branch precedence, the empty marker scope, the unwrappable EmptyRequest and
the data-sub-queue routing of the markers were not previously asserted.

Six tests use real collaborators rather than mocks, for behavior mocks cannot
express -- a rejected transition leaves the queue, the state and the
InputManager untouched, the markers land in the data sub-queue and so are
gated by disable_data, and the response version tracks the real state clock
on both the source and the non-source paths. One of them pins observed current
behavior rather than correctness, and says so in a comment: a second
StartWorker silently appends another marker pair.

The two real-state-clock tests on the non-source paths carry over the READY
and PAUSED cases from apache#6988; everything else that file asserted is subsumed
by a stricter assertion here.

Closes apache#7058
@aglinxinyuan
aglinxinyuan force-pushed the test/start-worker-handler-spec branch from b6079c3 to 43ca78c Compare July 30, 2026 01:51
@aglinxinyuan
aglinxinyuan enabled auto-merge July 30, 2026 01:52
@aglinxinyuan aglinxinyuan changed the title test(pyamber): add unit tests for StartWorkerHandler test(pyamber): extend the StartWorkerHandler unit tests Jul 30, 2026
@aglinxinyuan

Copy link
Copy Markdown
Contributor

Rebased this onto main and resolved the conflict — no action needed on your end.

#6988 landed this morning and added a test_start_worker_handler.py at the same path, so this was an add/add collision rather than a real overlap in intent. I took your file as the base: it subsumes what #6988 asserted about the handler and pins four things that one didn't — branch precedence (is_source wins even when reader threads exist), the empty marker scope, the EmptyRequest checked through get_one_of the way AsyncRpcServer unwraps it, and the markers landing on the data sub-queue rather than the control one.

The one thing I carried over from #6988 is its two non-source cases against a real StateManager — READY/0 with reader threads and PAUSED/1 echoed untouched. Your real-collaborator tests only covered the source path, and by your own argument in the description a mocked get_state_with_version can't catch a hoisted snapshot, so it seemed worth having that guard on both paths. _build_real_handler takes an optional input_manager now to allow it.

Also refreshed the title and description, which still described this as the first test for the handler. 23 cases in the file, handlers package at 69 passing, black/ruff clean locally.

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Benchmark changes need a look

🟢 2 better · 🔴 1 worse · ⚪ 12 noise (<±5%) · 0 without baseline

Compared against main 7d5276d benchmarked on this same runner, so the delta is largely free of cross-runner hardware noise. The "7d avg" column still reflects the gh-pages dashboard. Treat <±5% as noise unless repeated.

Dashboard · Run

config throughput MB/s latency max Δ latest / 7d
🔴 bs=10 sw=10 sl=64 550 0.336 18,781/24,687/24,687 us 🔴 +13.3% / 🔴 +56.5%
🟢 bs=100 sw=10 sl=64 1,205 0.735 81,353/100,671/100,671 us 🟢 -15.4% / 🟢 +20.5%
⚪ bs=1000 sw=10 sl=64 1,425 0.87 699,851/738,237/738,237 us ⚪ within ±5% / 🟢 +38.2%
Baseline details

Latest main 7d5276d from same runner

config metric PR latest main 7d avg Δ latest Δ 7d
bs=10 sw=10 sl=64 throughput 550 tuples/sec 572 tuples/sec 786.12 tuples/sec -3.8% -30.0%
bs=10 sw=10 sl=64 MB/s 0.336 MB/s 0.349 MB/s 0.48 MB/s -3.7% -30.0%
bs=10 sw=10 sl=64 p50 18,781 us 16,577 us 12,305 us +13.3% +52.6%
bs=10 sw=10 sl=64 p95 24,687 us 25,820 us 15,774 us -4.4% +56.5%
bs=10 sw=10 sl=64 p99 24,687 us 25,820 us 18,978 us -4.4% +30.1%
bs=100 sw=10 sl=64 throughput 1,205 tuples/sec 1,178 tuples/sec 999.71 tuples/sec +2.3% +20.5%
bs=100 sw=10 sl=64 MB/s 0.735 MB/s 0.719 MB/s 0.61 MB/s +2.2% +20.5%
bs=100 sw=10 sl=64 p50 81,353 us 82,756 us 100,616 us -1.7% -19.1%
bs=100 sw=10 sl=64 p95 100,671 us 119,023 us 107,356 us -15.4% -6.2%
bs=100 sw=10 sl=64 p99 100,671 us 119,023 us 113,255 us -15.4% -11.1%
bs=1000 sw=10 sl=64 throughput 1,425 tuples/sec 1,456 tuples/sec 1,031 tuples/sec -2.1% +38.2%
bs=1000 sw=10 sl=64 MB/s 0.87 MB/s 0.888 MB/s 0.63 MB/s -2.0% +38.2%
bs=1000 sw=10 sl=64 p50 699,851 us 683,749 us 980,328 us +2.4% -28.6%
bs=1000 sw=10 sl=64 p95 738,237 us 724,071 us 1,027,528 us +2.0% -28.2%
bs=1000 sw=10 sl=64 p99 738,237 us 724,071 us 1,054,298 us +2.0% -30.0%
Raw CSV
config_idx,batch_size,schema_width,string_len,num_batches,total_ms,total_tuples,total_bytes,tuples_per_sec,mb_per_sec,lat_p50_us,lat_p95_us,lat_p99_us
0,10,10,64,20,363.84,200,128000,550,0.336,18781.30,24687.18,24687.18
1,100,10,64,20,1659.97,2000,1280000,1205,0.735,81352.98,100671.36,100671.36
2,1000,10,64,20,14036.00,20000,12800000,1425,0.870,699850.50,738236.91,738236.91

@aglinxinyuan
aglinxinyuan added this pull request to the merge queue Jul 30, 2026
Merged via the queue into apache:main with commit f28d8ec Jul 30, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add unit test coverage for Python StartWorkerHandler

2 participants