-
Notifications
You must be signed in to change notification settings - Fork 139
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
Fixing priority of channel commands in model #190
Conversation
…irst, before other "cmd" commands
Thanks for submitting this @PhilippPlank! |
@@ -419,7 +419,8 @@ def add_ports_for_polling(self): | |||
if isinstance(csp_port, CspRecvPort): | |||
def func(fvar_port=var_port): | |||
return lambda: fvar_port | |||
self._channel_actions.append((csp_port, func(var_port))) | |||
self._channel_actions.insert(0, |
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.
So rather than appending to the _channel_actions
list
self._channel_actions: ty.List[ty.Tuple[ty.Union[CspSendPort, CspRecvPort], ty.Callable]]
we are overwriting idx 0.
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.
We are prepending an element rather than appending.
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.
Yes, insert is not overwriting existing elements.
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.
My mistake. 👍🏾
Appending.
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.
Admittedly, I don't understand the context of this issue. But the change seems minimal. So if it works - great.
@@ -419,7 +419,8 @@ def add_ports_for_polling(self): | |||
if isinstance(csp_port, CspRecvPort): | |||
def func(fvar_port=var_port): | |||
return lambda: fvar_port | |||
self._channel_actions.append((csp_port, func(var_port))) | |||
self._channel_actions.insert(0, |
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.
We are prepending an element rather than appending.
To give context. If we have VarPorts in a ProcessModel and we are in management phase, the channel action of each VarPort gets added to the list of possible channel actions to listen if anyone sent something to a VarPort. In this unit test which failed sometimes, the list of channel actions is [default "cmd" channel, first_var_port, second_var_port] This list is then given to the select function, which picks an action as soon as something arrives on any channel. The problem now was, that when entering the management phase we had data on both VarPort, select picks the first one to service. After that the loop starts from the beginning and it services the first VarPort. Now in some cases the STOP command was sent, before we reach the select again after being done with the first VarPort. Now the select has 2 channel actions to pick from, and picked the default "cmd" channel, since it comes first in the list. This stopped the execution before we had a chance to service the second VarPort and hence the unit test failed. Solution: order the channel command list so that VarPorts come first, so we can only listen to other commands when they all have been serviced (if needed). |
Ah yes. Prepending rather than replacing. OK. Makes sense to me. |
* - fixed priority of channel commands -> var_ports should be handled first, before other "cmd" commands
Issue Number: #186
Objective of pull request: Fixing errors in unit tests with Ref-/VarPort interaction
Pull request checklist
Your PR fulfills the following requirements:
pyb
) passes locallypyb -E unit
) or (python -m unittest
) passes locallyPull request type
Please check your PR type:
What is the current behavior?
What is the new behavior?
Does this introduce a breaking change?
Supplemental information