-
Couldn't load subscription status.
- Fork 6
WIP: Add test for filter calls between fetch() #175
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
base: v0.x.x
Are you sure you want to change the base?
Changes from all commits
432d140
88304ad
227da85
091cbe8
062cf16
7762602
8800b30
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -13,12 +13,13 @@ | |||||||
| import pytest | ||||||||
| import time_machine | ||||||||
| from frequenz.channels import Receiver | ||||||||
| from frequenz.channels.timer import SkipMissedAndResync, Timer | ||||||||
| from frequenz.client.common.microgrid import MicrogridId | ||||||||
| from frequenz.client.dispatch.recurrence import Frequency, RecurrenceRule | ||||||||
| from frequenz.client.dispatch.test.client import FakeClient, to_create_params | ||||||||
| from frequenz.client.dispatch.test.generator import DispatchGenerator | ||||||||
| from frequenz.client.dispatch.types import Dispatch as BaseDispatch | ||||||||
| from frequenz.client.dispatch.types import TargetIds | ||||||||
| from frequenz.client.dispatch.types import DispatchId, TargetIds | ||||||||
| from pytest import fixture | ||||||||
|
|
||||||||
| from frequenz.dispatch import ( | ||||||||
|
|
@@ -692,6 +693,86 @@ async def test_multiple_dispatches_sequential_intervals_merge( | |||||||
| assert not stopped.started | ||||||||
|
|
||||||||
|
|
||||||||
| async def test_sequential_overlapping_dispatches_between_fetch( | ||||||||
| fake_time: time_machine.Coordinates, | ||||||||
| generator: DispatchGenerator, | ||||||||
| ) -> None: | ||||||||
| """Test that sequential overlapping dispatches are handled correctly.""" | ||||||||
| microgrid_id = MicrogridId(randint(1, 100)) | ||||||||
| client = FakeClient() | ||||||||
| service = DispatchScheduler(microgrid_id=microgrid_id, client=client) | ||||||||
| service.start() | ||||||||
|
|
||||||||
| receiver = await service.new_running_state_event_receiver( | ||||||||
| "TEST_TYPE", merge_strategy=MergeByType() | ||||||||
| ) | ||||||||
|
|
||||||||
| # Create two overlapping dispatches | ||||||||
| dispatch1 = replace( | ||||||||
| generator.generate_dispatch(), | ||||||||
| active=True, | ||||||||
| duration=timedelta(seconds=10), | ||||||||
| target=TargetIds(1, 2), | ||||||||
| start_time=_now() + timedelta(seconds=5), | ||||||||
| recurrence=RecurrenceRule(), | ||||||||
| type="TEST_TYPE", | ||||||||
| ) | ||||||||
| dispatch2 = replace( | ||||||||
| generator.generate_dispatch(), | ||||||||
| active=True, | ||||||||
| duration=timedelta(seconds=10), | ||||||||
| target=TargetIds(3, 4), | ||||||||
| start_time=_now() + timedelta(seconds=8), # overlaps with dispatch1 | ||||||||
| recurrence=RecurrenceRule(), | ||||||||
| type="TEST_TYPE", | ||||||||
| ) | ||||||||
| await client.create(**to_create_params(microgrid_id, dispatch1)) | ||||||||
|
|
||||||||
| timer = Timer(timedelta(seconds=100), SkipMissedAndResync(), auto_start=False) | ||||||||
| await service._fetch(timer) # pylint: disable=protected-access | ||||||||
|
|
||||||||
| await client.create(**to_create_params(microgrid_id, dispatch2)) | ||||||||
|
|
||||||||
| # Move time forward to start first | ||||||||
| fake_time.shift(timedelta(seconds=6)) | ||||||||
| await asyncio.sleep(1) | ||||||||
| import logging | ||||||||
|
|
||||||||
|
Comment on lines
+739
to
+740
|
||||||||
| import logging |
Copilot
AI
Jul 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Debug logging and protected member access should be removed from test code. This appears to be leftover debugging code.
| import logging | |
| logging.debug("We see: %s", service._dispatches) |
Copilot
AI
Jul 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Debug logging should be removed from test code. This appears to be leftover debugging code.
| logging.debug("Wait for now starts %s", _now()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Accessing protected methods in tests can make tests brittle. Consider exposing a public method for testing or using dependency injection to make the fetch operation testable.