Skip to content

Fix flakey undulator dcm test - #2142

Merged
oliwenmandiamond merged 21 commits into
mainfrom
fix_flakey_undulator_dcm_test
Aug 26, 2026
Merged

Fix flakey undulator dcm test#2142
oliwenmandiamond merged 21 commits into
mainfrom
fix_flakey_undulator_dcm_test

Conversation

@oliwenmandiamond

@oliwenmandiamond oliwenmandiamond commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Fixes #2141

Have verified that it is no longer flakey using the event_loop_fuzzing fixture and ran 100 times and all passed as shown below

image

Instructions to reviewer on how to test:

  1. Check new test makes sense

Checks for reviewer

  • Would the PR title make sense to a scientist on a set of release notes
  • If a new device has been added does it follow the standards
  • If changing the API for a pre-existing device, ensure that any beamlines using this device have updated their Bluesky plans accordingly
  • Have the connection tests for the relevant beamline(s) been run via dodal connect ${BEAMLINE}

oliwenmandiamond and others added 18 commits July 17, 2026 10:25
ophyd-async 0.20.1 adds set_mock_attr (in ophyd_async.core) and enforces
that test code can no longer assign directly to attribute names that
collide with bluesky protocol verbs (set, read, trigger, kickoff,
complete, prepare, describe, check_value). Replace direct assignments
like `signal.set = AsyncMock(...)` with `set_mock_attr(signal, "set",
AsyncMock(...))` across the affected test files and fixtures.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EQPRwf3pUved4ihrBLPi1g
The set_mock_attr fixes in the previous commit cover every reserved-attr
NameError that this autouse fixture was blanket-suppressing, so the
mask is no longer needed.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EQPRwf3pUved4ihrBLPi1g
set_mock_attr(device, "attr", mock) doesn't let pyright narrow
device.attr to the mock's type, so later device.attr.assert_*() calls
failed with reportAttributeAccessIssue. Capture set_mock_attr's return
value (it returns the mock unchanged, per its own docstring) and assert
on that instead.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EQPRwf3pUved4ihrBLPi1g
…LightSource/dodal into update_to_ophyd_async_0_20
@oliwenmandiamond
oliwenmandiamond requested a review from a team as a code owner July 29, 2026 09:54
@oliwenmandiamond
oliwenmandiamond changed the base branch from main to update_to_ophyd_async_0_20 July 29, 2026 09:55
@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.19%. Comparing base (2e21a50) to head (36eeeb1).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2142   +/-   ##
=======================================
  Coverage   99.19%   99.19%           
=======================================
  Files         367      367           
  Lines       14596    14596           
=======================================
  Hits        14479    14479           
  Misses        117      117           

☔ View full report in Codecov by Harness.
📢 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.

Base automatically changed from update_to_ophyd_async_0_20 to main July 29, 2026 13:22

@Relm-Arrowny Relm-Arrowny 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.

It fixed it but I think all we needed to do is increase the time out. but it is nice to not have type: ignore.

Comment on lines +244 to 246
done, _ = await asyncio.wait([status.task], timeout=0.1)
assert status.task in done

@Relm-Arrowny Relm-Arrowny Aug 25, 2026

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.

nit: The cause of the flakey test was the timeout being too short, we could have just change it to 0.1 and it would have fixed it.

Suggested change
done, _ = await asyncio.wait([status.task], timeout=0.1)
assert status.task in done
await status
assert status.done

Or

    await asyncio.wait_for(status, timeout=0.1)

New code still fail with old timeout:
Image

@oliwenmandiamond
oliwenmandiamond merged commit 3922223 into main Aug 26, 2026
11 checks passed
@oliwenmandiamond
oliwenmandiamond deleted the fix_flakey_undulator_dcm_test branch August 26, 2026 09:47
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.

Undulator DCM has flakey test

3 participants