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

refactoring in port availability check function, added one more function get common formatted error which can be printed on console #79

Merged
merged 16 commits into from
Mar 17, 2017

Conversation

rajeshkalaria80
Copy link
Contributor

No description provided.

…ion get common formatted error which can be printed on console
"got error: {}".format(str(e))
logging.warning(erroMsg)
raise e

Copy link
Contributor

Choose a reason for hiding this comment

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

This does not separate concerns. checkPortAvailable should not be concerned with logging at all. Raise an exception and let application fault barriers handle logging.

@jasonalaw
Copy link
Contributor

See comment in commit. Can't accept this code as is.

@devin-fisher
Copy link
Contributor

Were we working from a broken tests? If not, I would like to see a test with this check in proving this behavior.

@jasonalaw jasonalaw closed this Mar 6, 2017
@jasonalaw jasonalaw reopened this Mar 6, 2017
@jasonalaw
Copy link
Contributor

+1 to @devin-fisher comment. We need a failing test that is resolved with this change.

Also, it doesn't appear any changes have happened since my comments yesterday.

@@ -0,0 +1 @@
SOCKET_BIND_ERROR_ALREADY_IN_USE = 98
Copy link
Contributor

Choose a reason for hiding this comment

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

Lets separate constants by their purpose, at least the ones which indicate error codes, so lets have a module called error_codes with such constants, later we can have error messages with a map with keys as above constants



class PortNotAvailable(Exception):
def __init__(self, port):
Copy link
Contributor

Choose a reason for hiding this comment

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

port should be part of exception args

@@ -599,3 +603,9 @@ def check_endpoint_valid(endpoint, required: bool=True):
raise InvalidEndpointIpAddress(endpoint) from exc
if not (port.isdigit() and int(port) in range(1, 65536)):
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you make a method called valid port which covers these cases, this method can be useful at other places too.


def getFormattedErrorMsg(msg):
msgHalfLength = int(len(msg) / 2)
errorLine = "-" * msgHalfLength + "ERROR" + "-" * msgHalfLength
Copy link
Contributor

Choose a reason for hiding this comment

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

Why half length, whats wrong with a fixed number of characters or some percentage of screen width. It would look odd when you print 2 error messages one below the other where one of them is significantly different in size

@@ -534,15 +534,20 @@ def stopNodes(nodes: List[TestNode], looper=None, ensurePortsFreedUp=True):
assert looper, 'Need a looper to make sure ports are freed up'
for node in nodes:
node.stop()

ports = [[n.nodestack.ha[1], n.clientstack.ha[1]] for n in nodes]
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do this computation before you know that "port freeness" needs to be ensured? And why burden waitUntillPortIsAvailable with the concern that it has to flatten the list of ports, lets keep it simple and do the flattening here

@rajeshkalaria80 rajeshkalaria80 merged commit 8304117 into master Mar 17, 2017
@ghost ghost unassigned jasonalaw Jun 29, 2017
@ashcherbakov ashcherbakov deleted the agent-startup-refactoring branch December 21, 2017 08:46
Toktar pushed a commit to Toktar/indy-plenum that referenced this pull request May 8, 2018
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.

4 participants