Skip to content

tests: rethrow worker-thread assertion in portable runner test to fix assert_that flake (fixes #35211) - #36355

Closed
jh1231223 wants to merge 0 commit into
apache:masterfrom
jh1231223:fix-portable-runner-warn
Closed

tests: rethrow worker-thread assertion in portable runner test to fix assert_that flake (fixes #35211)#36355
jh1231223 wants to merge 0 commit into
apache:masterfrom
jh1231223:fix-portable-runner-warn

Conversation

@jh1231223

@jh1231223 jh1231223 commented Oct 2, 2025

Copy link
Copy Markdown
Contributor

Thanks for reviewing!

It seems the current failures are unrelated to the modifications in this PR. If I’ve overlooked something, please let me know and I’ll address it promptly.

Context / Issue

What this change does

  • Captures threading.excepthook during the test run.
  • Wraps beam.Pipeline.run(...).wait_until_finish() so that any captured worker-thread exception is rethrown on the main thread at the end of the run.
  • Updates test_assert_that to use this shim and assert the expected failure via assertRaisesRegex, turning the flaky pass into a deterministic failure for the negative case.

Why
Ensures the failure path for assert_that is exercised reliably and reported as a proper test failure, rather than a warning emitted from a background thread.

Verification
Stress run x200 (no flakes):

for i in {1..200}; do
  echo "Run $i"
  pytest -q apache_beam/runners/portability/portable_runner_test.py::PortableRunnerTest::test_assert_that \
    -W error::pytest.PytestUnhandledThreadExceptionWarning -s --maxfail=1 || break
done

Result: 200/200 passes; no thread-exception warnings.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @jh1231223, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a critical flakiness issue in a specific test by implementing a robust exception propagation mechanism. It ensures that exceptions originating from worker threads during pipeline execution are consistently re-raised on the main thread, thereby converting an intermittently passing test (due to warnings) into a reliably failing one when an assertion condition is not met. This significantly improves the stability and correctness of the test suite.

Highlights

  • Flaky Test Fix: Addresses a known flaky behavior in PortableRunnerTest::test_assert_that where assert_that failures in worker threads were only surfaced as warnings, leading to intermittent test passes.
  • Exception Handling Enhancement: Introduces a mechanism to capture threading.excepthook during test runs, allowing exceptions raised on worker threads to be caught.
  • Main Thread Exception Rethrowing: Wraps beam.Pipeline.run(...).wait_until_finish() to rethrow any captured worker-thread exceptions on the main thread at the end of the pipeline run.
  • Deterministic Test Failure: Updates test_assert_that to utilize this new exception handling shim, transforming the previously flaky test into a deterministic failure for the negative case, ensuring reliable testing of assertion failures.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions

github-actions Bot commented Oct 2, 2025

Copy link
Copy Markdown
Contributor

Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment assign set of reviewers

@jh1231223 jh1231223 closed this Oct 9, 2025
@jh1231223
jh1231223 force-pushed the fix-portable-runner-warn branch from 7efb3e7 to 08c96f2 Compare October 9, 2025 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant