Skip to content

test: Fix failing tests due to parallelization - #159

Merged
garlontas merged 1 commit into
mainfrom
fix/fix-failing-parallel-tests
Oct 19, 2026
Merged

garlontas merged 1 commit into
mainfrom
fix/fix-failing-parallel-tests

Conversation

@garlontas

@garlontas garlontas commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

Summary by Sourcery

Allow parallelized stream tests to pass regardless of result ordering.

Enhancements:

  • Make stream tests resilient to nondeterministic ordering introduced by parallel execution.

Tests:

  • Update collection and grouping assertions to accept valid order variations while preserving expected contents.

@sourcery-ai

sourcery-ai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Updates stream tests so they validate the contents and valid grouping outcomes without assuming deterministic ordering introduced by parallelization, while improving object representations for readable assertion failures.

File-Level Changes

Change Details Files
Relax order-sensitive assertions in stream tests to accommodate nondeterministic parallel execution.
  • Use order-insensitive collection comparisons for flat stream outputs.
  • Accept valid permutations of grouped results and grouped item order.
  • Add Point.repr to improve failure diagnostics for permutation-based assertions.
tests/_streams/error/test_error_handler_streams.py
tests/_streams/test_stream_implementation.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sonarqubecloud

Copy link
Copy Markdown

@garlontas
garlontas merged commit f4f15de into main Oct 19, 2026
10 of 13 checks passed
@garlontas
garlontas deleted the fix/fix-failing-parallel-tests branch October 19, 2026 19:34

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="tests/_streams/test_stream_implementation.py" line_range="198" />
<code_context>
             .group_by(lambda x: x.isalnum())\
             .to_list()
-        self.assertListEqual(result, [(True, ["b", "a"])])
+        self.assertIn(result, [
+            [(True, ['b', 'a'])],
+            [(True, ['a', 'b'])]
</code_context>
<issue_to_address>
**Valid parallel groups fail tests**

When parallel scheduling produces either omitted key and bucket ordering, `ParallelStream._group_to_dict` can insert keys and append bucket values independently, producing valid permutations absent from the six `assertIn` alternatives; the grouping test then fails despite correct grouping.

Assert group membership and bucket contents without requiring a particular parallel key or value order.

Also at `tests/_streams/test_stream_implementation.py:204-205`.
</issue_to_address>

### Comment 2
<location path="tests/_streams/test_stream_implementation.py" line_range="37" />
<code_context>
         out = []
         self.stream([1, 2, 3, 9]).map_to_str().for_each(out.append)
-        self.assertListEqual(out, ["1", "2", "3", "9"])
+        self.assertCountEqual(out, ["1", "2", "3", "9"])

     def test_map_str_to_int(self):
</code_context>
<issue_to_address>
**Sequential callback order regressions pass**

When a sequential implementation invokes callbacks out of encounter order, the parameterized test uses `assertCountEqual`, so reordered `for_each` or `peek` callbacks still pass and the suite misses a sequential encounter-order regression.

Keep an order-sensitive assertion for sequential callbacks while allowing unordered parallel callbacks.

Also at `tests/_streams/test_stream_implementation.py:127`, `tests/_streams/test_stream_implementation.py:198-205`, `tests/_streams/test_stream_implementation.py:220-225`, `tests/_streams/error/test_error_handler_streams.py:66-70`.
</issue_to_address>

Sourcery assessment

Approval pending. 2 findings to address first.

Blocking findings: tests/_streams/test_stream_implementation.py:198, tests/_streams/test_stream_implementation.py:37


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

.group_by(lambda p: p.x) \
.to_list()
self.assertListEqual(result, [(1, [pt1, pt2]), (2, [pt3, pt4])])
self.assertIn(result, [

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium · Valid parallel groups fail tests

When parallel scheduling produces either omitted key and bucket ordering, ParallelStream._group_to_dict can insert keys and append bucket values independently, producing valid permutations absent from the six assertIn alternatives; the grouping test then fails despite correct grouping.

Assert group membership and bucket contents without requiring a particular parallel key or value order.

Also at tests/_streams/test_stream_implementation.py:204-205.

Prompt for AI agents
In `tests/_streams/test_stream_implementation.py` at line 198:

**Valid parallel groups fail tests**

When parallel scheduling produces either omitted key and bucket ordering, `ParallelStream._group_to_dict` can insert keys and append bucket values independently, producing valid permutations absent from the six `assertIn` alternatives; the grouping test then fails despite correct grouping.

Assert group membership and bucket contents without requiring a particular parallel key or value order.

Also at `tests/_streams/test_stream_implementation.py:204-205`.

out = []
self.stream([1, 2, 3, 9]).map_to_str().for_each(out.append)
self.assertListEqual(out, ["1", "2", "3", "9"])
self.assertCountEqual(out, ["1", "2", "3", "9"])

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium · Sequential callback order regressions pass

When a sequential implementation invokes callbacks out of encounter order, the parameterized test uses assertCountEqual, so reordered for_each or peek callbacks still pass and the suite misses a sequential encounter-order regression.

Keep an order-sensitive assertion for sequential callbacks while allowing unordered parallel callbacks.

Also at tests/_streams/test_stream_implementation.py:127, tests/_streams/test_stream_implementation.py:198-205, tests/_streams/test_stream_implementation.py:220-225, tests/_streams/error/test_error_handler_streams.py:66-70.

Prompt for AI agents
In `tests/_streams/test_stream_implementation.py` at line 37:

**Sequential callback order regressions pass**

When a sequential implementation invokes callbacks out of encounter order, the parameterized test uses `assertCountEqual`, so reordered `for_each` or `peek` callbacks still pass and the suite misses a sequential encounter-order regression.

Keep an order-sensitive assertion for sequential callbacks while allowing unordered parallel callbacks.

Also at `tests/_streams/test_stream_implementation.py:127`, `tests/_streams/test_stream_implementation.py:198-205`, `tests/_streams/test_stream_implementation.py:220-225`, `tests/_streams/error/test_error_handler_streams.py:66-70`.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant