Skip to content

perf(amber): replace Thread.sleep with event-driven waits in e2e specs - #4518

Merged
Yicong-Huang merged 5 commits into
apache:mainfrom
Yicong-Huang:perf/event-driven-waits
Apr 26, 2026
Merged

Yicong-Huang merged 5 commits into
apache:mainfrom
Yicong-Huang:perf/event-driven-waits

Conversation

@Yicong-Huang

@Yicong-Huang Yicong-Huang commented Apr 26, 2026 •

Copy link
Copy Markdown
Contributor

What changes were proposed in this PR?

PauseSpec.shouldPause and ReconfigurationSpec.shouldReconfigure used hardcoded Thread.sleep to wait for the engine to reach PAUSED (4s + 0.4s + 4s in PauseSpec, 4s in ReconfigurationSpec).

Replaced with a stateReached(client, target) helper that resolves a Promise on the next matching ExecutionStateUpdate. The post-resume sleep is dropped entirely — Await.result(resumeWorkflow) already blocks until ResumeHandler finishes, by which point all workers are in RUNNING.

Wait timeout: 10s (~2.5× the original sleep, leaves CI headroom while keeping hang feedback fast).

Any related issues, documentation, discussions?

Closes #4517.

How was this PR tested?

Local timing (warm sbt + DB):

Run completed in
before 41s 869ms
after 31s 355ms

ReconfigurationSpec can't be measured locally on JDK 17 (Arrow MemoryUtil reflection); CI on JDK 11 will exercise it.

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

Generated-by: Claude Code (Opus 4.7)

PauseSpec.shouldPause used three Thread.sleep calls (4000+400+4000 ms)
to wait for the engine to settle into PAUSED before each next action;
ReconfigurationSpec.shouldReconfigure had one Thread.sleep(4000) after
pauseWorkflow. AmberClient already exposes registerCallback for
ExecutionStateUpdate, so a Promise that resolves on the target state
is a drop-in replacement and exits as soon as the engine transitions.

Add a stateReached helper to TestUtils and use it in both specs to
wait for PAUSED. Local measurement: PauseSpec 41.87s -> 28.79s (~13s
saved); ReconfigurationSpec change measured via CI since the spec's
Python UDF path requires JDK 11.

The 400ms sleep after resumeWorkflow stays for now: ResumeHandler does
not emit an ExecutionStateUpdate (apache#4514). Once that fix lands, the
400ms sleep can be removed in a follow-up. The 1000ms sleep inside
ReconfigurationSpec's COMPLETED callback is also left alone -- its
TODO marks it as a workaround for a separate completion-reporting bug.

Closes apache#4517

@zuozhiw zuozhiw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Once apache#4515 (ResumeHandler emits ExecutionStateUpdate) lands, the
post-resume Thread.sleep(400) in PauseSpec.shouldPause can be replaced
with stateReached(client, RUNNING). The test verifies pause/resume
mechanics; it does not need to ensure tuple-level progress between
the two pause-resume cycles, so a state-based wait is sufficient.

Marks this PR as dependent on apache#4515.
@Yicong-Huang
Yicong-Huang marked this pull request as draft April 26, 2026 02:16
Await.result(resumeWorkflow) already blocks until ResumeHandler's .map
block has run, by which point all workers have transitioned to RUNNING.
The extra stateReached(RUNNING) wait was redundant and would have
required ResumeHandler to broadcast a new ExecutionStateUpdate event,
which is not warranted just for this test.
@Yicong-Huang
Yicong-Huang marked this pull request as ready for review April 26, 2026 02:24
Original code used Thread.sleep(4000) (4s); using a 30s ceiling for
the event-driven replacement is way more than needed and would make
genuine hangs slow to surface. 10s gives ample headroom over the
typical sub-second transition while keeping failure feedback quick.
@Yicong-Huang
Yicong-Huang merged commit 20c3a57 into apache:main Apr 26, 2026
11 checks passed
@Yicong-Huang
Yicong-Huang deleted the perf/event-driven-waits branch June 15, 2026 06:46
yangzhang75 pushed a commit to yangzhang75/texera that referenced this pull request Jun 22, 2026
apache#4518)

### What changes were proposed in this PR?

`PauseSpec.shouldPause` and `ReconfigurationSpec.shouldReconfigure` used
hardcoded `Thread.sleep` to wait for the engine to reach `PAUSED` (4s +
0.4s + 4s in `PauseSpec`, 4s in `ReconfigurationSpec`).

Replaced with a `stateReached(client, target)` helper that resolves a
`Promise` on the next matching `ExecutionStateUpdate`. The post-resume
sleep is dropped entirely — `Await.result(resumeWorkflow)` already
blocks until `ResumeHandler` finishes, by which point all workers are in
`RUNNING`.

Wait timeout: 10s (~2.5× the original sleep, leaves CI headroom while
keeping hang feedback fast).

### Any related issues, documentation, discussions?

Closes apache#4517.

### How was this PR tested?

Local timing (warm sbt + DB):

| | `Run completed in` |
|---|---|
| before | 41s 869ms |
| after  | 31s 355ms |

`ReconfigurationSpec` can't be measured locally on JDK 17 (Arrow
`MemoryUtil` reflection); CI on JDK 11 will exercise it.

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

Generated-by: Claude Code (Opus 4.7)
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.

Replace Thread.sleep with event-driven waits in pause/reconfiguration tests

2 participants