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

Use dictionary config interfaces for publisher and subscriber creation #127

Merged
merged 9 commits into from
Sep 1, 2022

Conversation

pnuu
Copy link
Member

@pnuu pnuu commented Aug 31, 2022

This PR makes it possible to:

  • disable nameserver connections by defining nameservers = False (Client) or nameserver = False and addresses = srvr1:12345 srvr2:12345 (Server, when using posttroll notifier) in the configuration file
  • pass all the NSSubscriber parameters by defining them in the Server configuration file when using posttroll notifier

The default behavior isn't affected.

  • Tests adjusted
  • Fully documented

@pnuu pnuu self-assigned this Aug 31, 2022
@pnuu pnuu requested a review from mraspaud as a code owner August 31, 2022 10:29
@codecov
Copy link

codecov bot commented Aug 31, 2022

Codecov Report

Merging #127 (76ed902) into main (2d84dbb) will increase coverage by 1.27%.
The diff coverage is 95.40%.

@@            Coverage Diff             @@
##             main     #127      +/-   ##
==========================================
+ Coverage   76.57%   77.84%   +1.27%     
==========================================
  Files          18       18              
  Lines        3893     3990      +97     
==========================================
+ Hits         2981     3106     +125     
+ Misses        912      884      -28     
Flag Coverage Δ
unittests 77.84% <95.40%> (+1.27%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
trollmoves/__init__.py 100.00% <ø> (ø)
trollmoves/client.py 76.33% <88.88%> (+0.46%) ⬆️
trollmoves/tests/test_server.py 96.99% <90.69%> (-3.01%) ⬇️
trollmoves/server.py 39.42% <95.65%> (+6.86%) ⬆️
trollmoves/tests/test_client.py 99.57% <100.00%> (+0.01%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Member

@mraspaud mraspaud left a comment

Choose a reason for hiding this comment

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

The logic LGTM, some testing questions

@@ -428,7 +428,22 @@ def __init__(self, attrs, publisher):

def run(self):
"""Start listening to messages."""
with Subscribe('', topics=self.attrs['listen'], addr_listener=True) as sub:
nameserver = self.attrs.get('nameserver')
if nameserver in ('false', 'False'):
Copy link
Member

Choose a reason for hiding this comment

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

why not use FALSY here?

Copy link
Member Author

@pnuu pnuu Aug 31, 2022

Choose a reason for hiding this comment

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

I'll move FALSY and TRUTHY to __init__ and use them from there where needed.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

Comment on lines 438 to 446
with Subscribe(
services=self.attrs.get('services', ''),
topics=self.attrs.get('topics', self.attrs['listen']),
addr_listener=bool(self.attrs.get('addr_listener', True)),
addresses=addresses,
timeout=int(self.attrs.get('timeout')),
translate=bool(self.attrs.get('translate', False)),
nameserver=nameserver,
) as sub:
Copy link
Member

Choose a reason for hiding this comment

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

Is there a test to check at least that the old behaviour is unchanged given the same config?

Copy link
Member

Choose a reason for hiding this comment

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

Asking because codecov says that parts of this function are untested...

Copy link
Member Author

Choose a reason for hiding this comment

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

Seems that the posttroll notifier (trollmoves.server.Listener class) has no tests. I'll see if I can figure out enough of it to create a test to see the default usage hasn't changed.

Copy link
Member Author

Choose a reason for hiding this comment

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

I added the bare minimum test for this.

Comment on lines 714 to 715
if nameservers in FALSY:
nameservers = False
Copy link
Member

Choose a reason for hiding this comment

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

Codecov says this is not tested?

Copy link
Member Author

Choose a reason for hiding this comment

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

Test added.

@pnuu
Copy link
Member Author

pnuu commented Sep 1, 2022

I refactored the code and config reading a bit so that adding YAML config support would be a bit easier.

Copy link
Member

@mraspaud mraspaud left a comment

Choose a reason for hiding this comment

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

Looks good, just a couple of small test to exercise the two read_config functions and I'm happy 😄

Copy link
Member

@mraspaud mraspaud left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for taking the time to refactor the config parsing.

@mraspaud mraspaud merged commit bf83396 into pytroll:main Sep 1, 2022
@pnuu pnuu deleted the feature-configurable-pub-sub branch September 1, 2022 11:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants