-
Notifications
You must be signed in to change notification settings - Fork 22
Don't sleep on PowerDistributor startup #971
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
Changes from all commits
695bb91
0359bac
b45a810
2337228
f791f4f
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 |
|---|---|---|
|
|
@@ -89,6 +89,11 @@ async def _patch_battery_pool_status( | |
| If `battery_ids` is not None, the mock will always return `battery_ids`. | ||
| Otherwise, it will return the requested batteries. | ||
| """ | ||
| mocker.patch.object( | ||
| timeseries.battery_pool._methods, # pylint: disable=protected-access | ||
| "WAIT_FOR_COMPONENT_DATA_SEC", | ||
| 0.1, | ||
| ) | ||
|
Comment on lines
+92
to
+96
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we still have some other waiting for data as a simple sleep? Shouldn't that wait be removed too?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is for the metric streaming in the battery pool. It won't stream any metrics until it has data for all the batteries, etc. So we don't send a new value for capacity or soc as we get data from more and more batteries. This is independent of the power distributor. |
||
| if battery_ids: | ||
| mock = MagicMock(spec=ComponentPoolStatusTracker) | ||
| mock.get_working_components.return_value = battery_ids | ||
|
|
||
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.
Is this PR just moving the issue elsewhere instead? Or is this synchronization only needed for the tests but when actually used one shouldn't care when there is data and when there isn't?
In any case, having tests depend on random
sleepmakes me sad (as I see the flakiness coming to bite us eventually). 😢 😞If we can really really get rid of the need for synchronization, then I completely agree we shouldn't provide any way to synchronize, but otherwise I think having a way to explicitly synchronize that is it not a flaky sleep it is a better approach. In terms of performance, even if it is a hot path, it is just one extra boolean evaluation and branch, which modern CPUs probably won´t even care about because they will do branch prediction so the performance might not even be affected at all after the initialization.
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.
As I mentioned in the commit message, these are needed only in tests where we control the PowerDistributor directly.
And they are needed only for those tests that need component data, so that PowerDistributor can return
Success. Else it will returnError("No data"), but that's not the case we're testing.It is only a testing problem, not with behaviour in production.
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.
OK, I'm still not happy about potential flaky tests, but this is still an improvement over what we had before, so approving 👍