Skip to content
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

Only on master #296

Merged
merged 5 commits into from Jun 7, 2015
Merged

Only on master #296

merged 5 commits into from Jun 7, 2015

Conversation

KennethNielsen
Copy link
Member

This is my attempt to solve the problem of calling master-only methods on a slave. It fixes this along the lines of option 2 as discussed here #138 (comment) by @lawrenceakka (Raises SoCoSlaveException when calling a master command on a slave). It is implemented as a decorator should be used to decorate all the master only methods in SoCo (of course it might it might turn out to be better to reverse the logic if there are many more master-only than master-and-slave method).

Right now it is only implemented on the play and pause method, because I wanted to get some input about whether you like this approach or not, before I start testing all the methods in SoCo for whether they can be called on a slave.

Please also have a look at the test modifications. This is my first run-in with mock (I spent about twice the time on the test modifications as I did on the implementation), so I'm very curious if there is a better way to adapt the tests for this change.

EDIT: I improved the test modifications, so that they actually are still unit tests, so it should be better now, but still could use a review.

@KennethNielsen
Copy link
Member Author

I improved the test changes, so that they actually are still unit tests.

I'd like some feedback on this, if anyone has a little time (I know it can be tight).

@KennethNielsen KennethNielsen mentioned this pull request May 25, 2015
@stefankoegl
Copy link
Member

I like the approach! From my perspective we can continue like this.

@KennethNielsen
Copy link
Member Author

Ok, I have now applied the decorator to all the methods that I think it should be used on. Please test it and let me know what you think.

A few specifics of the application of the decorator below:

For cross_fade the getter works and returns the value for the slave, but the setter fails. Since it would be required to apply the decorator to the setter I decided to also apply it to the getter to not break the symmetry.

play_uri will add the uri to the slave and then break the group and ultimately fail because we cannot call play, therefore mark the entire method as only_on_master

stop, stops playback on the slave, but without breaking the group and the master still plays?!?, also mark that as only_on_master

I think the above cases of somewhat inconsistent or unexpected behavior seems to me to support our idea of trying to catch this incorrect use before it is sent to the player.

When methods calls other methods for the actual interaction, I have chosen to mark both (e.g. add_uri_to_queue and add_to_queue) because the implementation is hidden from normal use and the error message will then mention another method, which will be confusing (and if the implementation is changed later, the information from my testing will not be lost).

add_item_to_queueable_item seems to have been forgotten in the data structures restructuring, at least it tries to form metadata in the old way. Since it is broken I cannot test it. I will open a separate issue for that.

@stefankoegl
Copy link
Member

I think the above cases of somewhat inconsistent or unexpected behavior seems to me
to support our idea of trying to catch this incorrect use before it is sent to the player.

Agreed

Good catch regarding add_item_to_queueable_item (#308)!

+1 to the whole PR -- nice work :)

@KennethNielsen
Copy link
Member Author

I seem to have messed up the rebase, please hold

@stefankoegl
Copy link
Member

Seems to be fixed now, right?

@KennethNielsen
Copy link
Member Author

Yes. I'll merge.

KennethNielsen pushed a commit that referenced this pull request Jun 7, 2015
Add only_on_master decorator, which when applied to methods, will raise a SoCoSlaveException when the method is called on a zone that is not the master
@KennethNielsen KennethNielsen merged commit 85c6b0b into SoCo:master Jun 7, 2015
@stefankoegl stefankoegl added this to the 0.11 milestone Jun 7, 2015
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.

None yet

2 participants