Skip to content

Fix flaky test_elf_upload_timeout in HDAWG tests - #242

Merged
heevasti merged 1 commit into
mainfrom
claude/issue-239-20261028-0803
Oct 28, 2026
Merged

heevasti merged 1 commit into
mainfrom
claude/issue-239-20261028-0803

Conversation

@claude

@claude claude Bot commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes a flaky unit test reported in #239.

test_elf_upload_timeout in tests/instruments/zurich_instruments/test_hdawg.py relied on real wall-clock timing via time.sleep(), combined with a mocked upload progress sequence (getDouble.side_effect = [0.0, 0.5]), to land on exactly two poll iterations before the upload timeout tripped. Under CI scheduling jitter, the real elapsed time could exceed the timeout one poll iteration earlier than intended, causing the test to see 0.0% progress in the timeout message instead of the expected 50.0%:

AssertionError: 'Upload process timed out (timeout=0.1) at 50.0%' != 'Upload process timed out (timeout=0.1) at 0.0%'

Changes

  • tests/instruments/zurich_instruments/test_hdawg.py: mock time.monotonic() (and time.sleep(), to keep the test fast) inside test_elf_upload_timeout, so the timeout trip point is fully deterministic and no longer depends on actual elapsed wall-clock time or CI scheduling.
  • CHANGELOG.md: documented the fix under "Fixed" in the Unreleased section.

No production code (qmi/instruments/zurich_instruments/hdawg.py) was changed — this is purely a test-determinism fix.

Test plan

  • test_elf_upload_timeout passes consistently (ran 20x in a loop, all green; runtime dropped from ~2s to ~0.006s since it no longer sleeps for real)
  • Full tests/instruments/zurich_instruments/test_hdawg.py suite passes (97 tests)
  • Full test suite passes (uv run coverage run --branch -m unittest discover --start-directory="tests" --pattern="test_*.py", 3185 tests, OK)
  • uv run ruff check --fix --output-format pylint clean
  • uv run mypy qmi --namespace-package --explicit-package-bases — no issues (pre-existing, unrelated errors in examples/ and missing jsonschema stubs in tests/ are untouched by this change)

🤖 Generated with Claude Code

The test relied on real wall-clock timing via time.sleep(), combined with
a mocked upload progress sequence, to land on exactly two poll iterations
before the upload timeout tripped. Under CI scheduling jitter, the real
elapsed time could exceed the timeout one iteration earlier than intended,
reporting 0.0% progress instead of the expected 50.0%.

Mock time.monotonic() (and time.sleep()) so the timeout trip point is
deterministic and independent of actual elapsed wall-clock time.

Fixes #239

Co-authored-by: heevasti <87366176+heevasti@users.noreply.github.com>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@claude
claude Bot requested a review from heevasti October 28, 2026 08:12
@claude claude Bot mentioned this pull request Oct 28, 2026

@heevasti heevasti left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ready for merging.

@heevasti
heevasti merged commit 7b02875 into main Oct 28, 2026
7 checks passed
@heevasti
heevasti deleted the claude/issue-239-20261028-0803 branch October 28, 2026 08:37
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