Skip to content

Fix flaky MatrixPowerTest.test_basics by reading all generated shards#38585

Merged
shunping merged 2 commits into
apache:masterfrom
shunping:fix-matrix-power
May 21, 2026
Merged

Fix flaky MatrixPowerTest.test_basics by reading all generated shards#38585
shunping merged 2 commits into
apache:masterfrom
shunping:fix-matrix-power

Conversation

@shunping
Copy link
Copy Markdown
Collaborator

@shunping shunping commented May 21, 2026

Flaky test (https://github.com/apache/beam/actions/runs/26220137898/job/77152699556):

_________________________ MatrixPowerTest.test_basics __________________________
[gw3] linux -- Python 3.11.15 /runner/_work/beam/beam/sdks/python/test-suites/tox/py311/build/srcs/sdks/python/target/.tox-py311-cloud/py311-cloud/bin/python

self = <apache_beam.examples.matrix_power_test.MatrixPowerTest testMethod=test_basics>

    def test_basics(self):
      matrix_path = self.create_temp_file(self.MATRIX_INPUT)
      vector_path = self.create_temp_file(self.VECTOR_INPUT)
      matrix_power.run((
          '--input_matrix=%s --input_vector=%s --exponent=%d --output=%s.result' %
          (matrix_path, vector_path, self.EXPONENT, vector_path)).split())
      # Parse result file and compare.
>     with open(vector_path + '.result-00000-of-00001') as result_file:
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E     FileNotFoundError: [Errno 2] No such file or directory: '/runner/_work/beam/beam/sdks/python/test-suites/tox/py311/build/srcs/sdks/python/target/.tox-py311-cloud/py311-cloud/tmp/tmp2mc8u76w.result-00000-of-00001'

apache_beam/examples/matrix_power_test.py:54: FileNotFoundError

The test was previously expecting the output to be written to a single file shard (.result-00000-of-00001). Depending on the runner execution details, the output can be split into multiple shards, resulting in a flaky FileNotFoundError.

This PR dynamically finds and reads all generated shards matching the prefix using glob, merging their contents before validating against the expected output.

Related to #38484

@shunping shunping marked this pull request as ready for review May 21, 2026 13:30
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 recurring flakiness issue in the MatrixPowerTest suite. By implementing a glob-based approach to locate and aggregate all output files matching the expected prefix, the test now correctly handles scenarios where the runner generates multiple shards, ensuring consistent and reliable validation.

Highlights

  • Test Flakiness Resolution: Updated the MatrixPowerTest.test_basics method to dynamically read all generated output shards instead of relying on a single hardcoded filename, preventing FileNotFoundError in environments where multiple shards are produced.
New Features

🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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 the 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 counterproductive. 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.

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.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the matrix power integration test to handle multiple output shards by using the glob module to aggregate results instead of reading a single hardcoded file. The reviewer suggested adding an assertion to ensure that output shards are actually found, which improves debuggability by preventing the test from proceeding with an empty result set if the pipeline fails to generate output.

Comment thread sdks/python/apache_beam/examples/matrix_power_test.py
@shunping
Copy link
Copy Markdown
Collaborator Author

r: @derrickaw (another flaky test related to asserting text output with different number of shards)

@github-actions
Copy link
Copy Markdown
Contributor

Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control. If you'd like to restart, comment assign set of reviewers

@shunping shunping merged commit 898c1a8 into apache:master May 21, 2026
98 of 102 checks passed
@shunping shunping deleted the fix-matrix-power branch May 21, 2026 15:28
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.

2 participants