Skip to content

Conversation

@shsms
Copy link
Contributor

@shsms shsms commented May 16, 2025

And migrate to latest time-machine version v2.16.0

This new version of time-machine mocks the monotonic clock of
asyncio.

This was causing the
test_battery_status.py::TestBatteryStatus::test_async_battery_status
test to fail, because channels.Timers weren't working properly.

To fix this, this commit switches this test file to use an
async_solipsism event loop instead, which time-machine doesn't
affect.

But introducing the async_solipsism event loop caused the
TestBatteryStatusRecovery::test_stale_data test to fail, because it
needed the clock time to make progress, which wasn't happening because
sleep was returning immediately.

To fix this, this commit also updates that test to use time-machine
and moves the time forward manually, so the test can pass.

Copilot AI review requested due to automatic review settings May 16, 2025 11:33
@shsms shsms requested a review from a team as a code owner May 16, 2025 11:33
@shsms shsms requested review from ela-kotulska-frequenz and removed request for a team May 16, 2025 11:33
@github-actions github-actions bot added part:tests Affects the unit, integration and performance (benchmarks) tests part:tooling Affects the development tooling (CI, deployment, dependency management, etc.) labels May 16, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates the test suite to support the latest version of time-machine (v2.16.0) and introduces an async event loop policy via async_solipsism to align with the updated dependencies.

  • Updated time-machine dependency in pyproject.toml.
  • Added an import for async_solipsism and a new pytest fixture (event_loop_policy) to configure the event loop.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
tests/microgrid/power_distributing/_component_status/test_battery_status.py Added async_solipsism import and an event_loop_policy fixture for handling asynchronous tests.
pyproject.toml Updated the time-machine dependency to v2.16.0.

@shsms shsms force-pushed the new-time-machine branch from cf6cf07 to 6221bc3 Compare May 16, 2025 11:41
@shsms shsms enabled auto-merge May 16, 2025 11:45
Copy link
Contributor

@llucax llucax left a comment

Choose a reason for hiding this comment

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

LGTM, but can you explain in the commit and/or PR what was going on exactly? Why this test hangs with the new version of time-machine?

And migrate to latest time-machine version v2.16.0

This new version of `time-machine` mocks the monotonic clock of
asyncio.

This was causing the
`test_battery_status.py::TestBatteryStatus::test_async_battery_status`
test to fail, because `channels.Timer`s weren't working properly.

To fix this, this commit switches this test file to use an
`async_solipsism` event loop instead, which `time-machine` doesn't
affect.

But introducing the `async_solipsism` event loop caused the
`TestBatteryStatusRecovery::test_stale_data` test to fail, because it
needed the clock time to make progress, which wasn't happening because
`sleep` was returning immediately.

To fix this, this commit also updates that test to use `time-machine`
and moves the time forward manually, so the test can pass.

Signed-off-by: Sahas Subramanian <[email protected]>
@shsms shsms force-pushed the new-time-machine branch from 6221bc3 to 254c367 Compare May 16, 2025 12:32
@shsms
Copy link
Contributor Author

shsms commented May 16, 2025

LGTM, but can you explain in the commit and/or PR what was going on exactly? Why this test hangs with the new version of time-machine?

done

@shsms shsms added this pull request to the merge queue May 16, 2025
@github-project-automation github-project-automation bot moved this from To do to Review approved in Python SDK Roadmap May 16, 2025
Merged via the queue into frequenz-floss:v1.x.x with commit ac4959e May 16, 2025
5 checks passed
@shsms shsms deleted the new-time-machine branch May 16, 2025 12:43
@github-project-automation github-project-automation bot moved this from Review approved to Done in Python SDK Roadmap May 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

part:tests Affects the unit, integration and performance (benchmarks) tests part:tooling Affects the development tooling (CI, deployment, dependency management, etc.)

Projects

Development

Successfully merging this pull request may close these issues.

2 participants