Skip to content

Conversation

@CyberDem0n
Copy link
Contributor

Extract parts of the Utility class responsible for network communications into the TcpUtility, so other parties could easily reuse it.

Extract parts the `Utility` class responsible for network communications
into the `TcpUtility`, so other parties could easily reuse it.
@coveralls
Copy link

coveralls commented Oct 26, 2020

Coverage Status

Coverage increased (+0.1%) to 86.239% when pulling 515b84a on CyberDem0n:feature/syncobj-admin-utility into 48780d8 on bakwc:master.

self.__result = None
self.__error = None

def sendMessage(self, node, message):
Copy link
Owner

Choose a reason for hiding this comment

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

I suggest to rename it into 'executeCommand' and make it return result / error. Otherwise it's not obvious why sendMessage run polling loop inside and wait for disconnect.

return False


def syncobjAdmin(args):
Copy link
Owner

Choose a reason for hiding this comment

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

executeAdminCommand

if time.time() > deadline:
self.__connection.disconnect()

return self.getResult() or self.getError()
Copy link
Owner

Choose a reason for hiding this comment

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

May be at least return tuple / dict? How can we distinguish errors from non-errors? (this is optional, if you don't think it's a good idea or don't have time - I'll merge as is)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, yeah, this is the issue.
That's why in the original code I was explicitly checking if the result is None and returning the error.
Unfortunately, I don't have a better interface for that, except maybe raising an exception.

Copy link
Owner

Choose a reason for hiding this comment

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

What about return (self.getResult(), self.getError()) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it would be more appropriate to raise an exception.
After all, this is what exceptions are useful for :)

Copy link
Owner

Choose a reason for hiding this comment

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

Ok

result = util.executeCommand(data.connection, message)

if isinstance(result, str):
return result
Copy link
Owner

Choose a reason for hiding this comment

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

May be use only dict everywhere, and put "error" inside dict with error text for error handling?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, the result could be anything (whatever the server returned).
I just "replicated" the original code.

Copy link
Owner

Choose a reason for hiding this comment

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

Ok, can merge it but looks not so cool. May be a separate issue for refactor?

@bakwc bakwc merged commit f266a97 into bakwc:master Oct 26, 2020
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.

3 participants