Skip to content

Avoid frequent test failure in greedy_test.py by increasing timeout #7188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 26, 2025

Conversation

mhucka
Copy link
Contributor

@mhucka mhucka commented Mar 26, 2025

On my MacOS 15.x Apple M1 laptop, I frequently get a test failure in cirq-core/cirq/contrib/routing/greedy_test.py:

[gw2] darwin -- Python 3.11.9 /Users/mhucka/.pyenv/versions/cirq-py311-np1/bin/python3

    def test_router_hanging():
        """Run a separate process and check if greedy router hits timeout (5s)."""
        circuit, device_graph = create_circuit_and_device()
        process = Process(target=create_hanging_routing_instance, args=[circuit, device_graph])
        process.start()
        process.join(timeout=5)
        try:
>           assert not process.is_alive(), "Greedy router timeout"
E           AssertionError: Greedy router timeout
E           assert not True
E            +  where True = is_alive()
E            +    where is_alive = <Process name='Process-1' pid=58097 parent=56380 started>.is_alive

cirq-core/cirq/contrib/routing/greedy_test.py:58: AssertionError

This happens with Python 3.10 and 3.12 as well.

Since assertion being tested is that the process is not alive, it seems that 5 seconds can be too short. And indeed, if the timeout is increased to 20 seconds, the error never seems to occur in my local Mac testing.

It's not obvious to me whether a short timeout is needed for the purposes of the test. Shortening the duration to 10 sec also works, but might not in other people's environments. So, 20 sec seems safer. However, if it needs to be as short as possible, then 10 seconds seems workable too.

@mhucka mhucka changed the title Fix frequent test failure in greedy_test.py Avoid frequent test failure in greedy_test.py by increasing timeout Mar 26, 2025
On my MacOS 15.x Apple M1 laptop, I frequently get a test failure in
`cirq-core/cirq/contrib/routing/greedy_test.py`:

```
[gw2] darwin -- Python 3.11.9 /Users/mhucka/.pyenv/versions/cirq-py311-np1/bin/python3

    def test_router_hanging():
        """Run a separate process and check if greedy router hits timeout (5s)."""
        circuit, device_graph = create_circuit_and_device()
        process = Process(target=create_hanging_routing_instance, args=[circuit, device_graph])
        process.start()
        process.join(timeout=5)
        try:
>           assert not process.is_alive(), "Greedy router timeout"
E           AssertionError: Greedy router timeout
E           assert not True
E            +  where True = is_alive()
E            +    where is_alive = <Process name='Process-1' pid=58097 parent=56380 started>.is_alive

cirq-core/cirq/contrib/routing/greedy_test.py:58: AssertionError
```

This happens with Python 3.10 and 3.12 as well.

Since assertion being tested is that the process is _not_ alive, it
seems that 5 seconds can be too short. And indeed, the timeout is
increased to 20 seconds, the error never seems to occur in my local
Mac testing.

It's not obvious whether a short timeout is needed for the purposes
of the test. Shortening the duration to 10 sec also works, but might
not in other people's environments. So, 20 sec seems safer. However,
if it needs to be as short as possible, then 10 seconds seems workable
too.
@mhucka mhucka force-pushed the mh-fix-greedy-test-timeout branch from 2d18654 to a1c9e6f Compare March 26, 2025 04:33
Copy link

codecov bot commented Mar 26, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.14%. Comparing base (0eea89e) to head (428433c).
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7188      +/-   ##
==========================================
- Coverage   98.14%   98.14%   -0.01%     
==========================================
  Files        1100     1100              
  Lines       96191    96191              
==========================================
- Hits        94409    94405       -4     
- Misses       1782     1786       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mhucka mhucka marked this pull request as ready for review March 26, 2025 04:50
@mhucka mhucka requested review from vtomole and a team as code owners March 26, 2025 04:50
@mhucka mhucka requested a review from viathor March 26, 2025 04:50
@mhucka mhucka self-assigned this Mar 26, 2025
@mhucka mhucka requested a review from pavoljuhas March 26, 2025 04:50
@@ -53,7 +53,7 @@ def test_router_hanging():
circuit, device_graph = create_circuit_and_device()
process = Process(target=create_hanging_routing_instance, args=[circuit, device_graph])
process.start()
process.join(timeout=5)
process.join(timeout=20)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please update docstring on line 52 above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice catch. Thanks!

@mhucka mhucka added this pull request to the merge queue Mar 26, 2025
Merged via the queue into quantumlib:main with commit cdbc196 Mar 26, 2025
38 checks passed
@mhucka mhucka deleted the mh-fix-greedy-test-timeout branch March 26, 2025 18:23
BichengYing pushed a commit to BichengYing/Cirq that referenced this pull request Jun 20, 2025
…uantumlib#7188)

* Fix frequent test failure in greedy_test.py

On my MacOS 15.x Apple M1 laptop, I frequently get a test failure in
`cirq-core/cirq/contrib/routing/greedy_test.py`:

```
[gw2] darwin -- Python 3.11.9 /Users/mhucka/.pyenv/versions/cirq-py311-np1/bin/python3

    def test_router_hanging():
        """Run a separate process and check if greedy router hits timeout (5s)."""
        circuit, device_graph = create_circuit_and_device()
        process = Process(target=create_hanging_routing_instance, args=[circuit, device_graph])
        process.start()
        process.join(timeout=5)
        try:
>           assert not process.is_alive(), "Greedy router timeout"
E           AssertionError: Greedy router timeout
E           assert not True
E            +  where True = is_alive()
E            +    where is_alive = <Process name='Process-1' pid=58097 parent=56380 started>.is_alive

cirq-core/cirq/contrib/routing/greedy_test.py:58: AssertionError
```

This happens with Python 3.10 and 3.12 as well.

Since assertion being tested is that the process is _not_ alive, it
seems that 5 seconds can be too short. And indeed, the timeout is
increased to 20 seconds, the error never seems to occur in my local
Mac testing.

It's not obvious whether a short timeout is needed for the purposes
of the test. Shortening the duration to 10 sec also works, but might
not in other people's environments. So, 20 sec seems safer. However,
if it needs to be as short as possible, then 10 seconds seems workable
too.

* Update docstring to match change in code
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.

3 participants