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

Issue1036 - Add unit tests for AM code #1044

Merged
merged 4 commits into from
May 15, 2024
Merged

Conversation

andreleblanc11
Copy link
Member

These unit tests are mostly based off of the errors that were found under #980, adding also testing for regular bulletins and errors from personal observations noted when monitoring logs.

Suggestions are welcome for adding more tests to the repertoire.

Copy link

Test Results

220 tests   212 ✅  17s ⏱️
  1 suites    8 💤
  1 files      0 ❌

Results for commit 57f1f57.

@gcglinton
Copy link
Contributor

This looks great! Lots of good testing here for individual cases you've seen; not something I've been able to do thus far.

Only observations I'd make are...
1 - Perhaps the test names should reflect the method being evaluated. These, at their core, all seem to be testing correctContents, so maybe prefix them all with correctContents__ (test_bulletin_wrong_station => test_correctContents__bulletin_wrong_station), to group them, or identify what method you're testing. Alternatively, putting them in a class (like here) to do grouping would work too. Ultimately, it doesn't matter, as they still work, and are still testing things, but defining as a project how you want to structure your tests means it's easier to debug or write them down the road.

2 - You're building an options class from scratch, which is something I had done initially as well. Until I realized I could just instantiate a sarracenia.config, and modify things as needed. I think that ends up being a much better way, as you're not having to emulate what config is doing. It's actually doing it, so any changes upstream will break the CBs too. Again, at the end of the day, it all works.

Comment on lines +19 to +39
class Options:
def __init__(self):
# self.o = sarracenia.config.default_config()
self.logLevel = "DEBUG"
self.logFormat = ""
self.queueName = "TEST_QUEUE_NAME"
self.component = "flow"
self.config = "foobar_am.conf"
self.sendTo = "am://127.0.0.1:5005"
self.pid_filename = "/tmp/sarracenia/am_test/pid_filename"
self.directory = "/tmp/test/directory"
self.housekeeping = float(39)
self.fileAgeMin = 0
self.fileAgeMax = 0
self.post_baseUrl = "http://localhost/"
self.post_format = "v02"

def add_option(self, option, type, default = None):
if not hasattr(self, option):
setattr(self, option, default)
pass
Copy link
Contributor

Choose a reason for hiding this comment

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

This should probably be replaced by importing sarracenia.config, and then instantiating that on a per-test bassis, setting the options needed.
If you're going to be re-using the same set of options universally, then you can create a fixture, or method for it.

from base64 import b64encode

BaseOptions = Options()
renamer = Raw2bulletin(BaseOptions)
Copy link
Contributor

Choose a reason for hiding this comment

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

Since you're calling this external method, it might be good to add a dependency for it above these tests, but that would mean writing unit tests for that other method.

Alternatively, re-scope your tests here to only cover what gather/am is doing.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hm.. I see Raw2Bulletin, and Bulletin are getting used in __init__ as well, so maybe we ignore these dependencies until tests are written for those modules.

Copy link
Member Author

@andreleblanc11 andreleblanc11 May 14, 2024

Choose a reason for hiding this comment

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

Yeah. Unfortunately, we need both Bulletin and Raw2Bulletin for a lot of the tests. The scope of these unit tests are mostly for the "bulletin processing and renaming" functionality

But you're right we'll need unit tests for these classes as well. I'll make sure to take note of that.

Copy link
Contributor

Choose a reason for hiding this comment

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

you just end up with unit tests for Bulletin and Raw2Bulletin... still a good thing.
I mean most of the problems you ran into were bulletins with unexpected content, so those tests are doing useful stuff. It's at worst slightly mislabelled.

Copy link
Contributor

@petersilva petersilva left a comment

Choose a reason for hiding this comment

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

Greg's comments are great. You can keep working on the branch to use the sarracenia classes, or we can merge first, and do that work subsequently. It's a good idea either way.

more tests is more better, as we clearly don't have enough right now.

from base64 import b64encode

BaseOptions = Options()
renamer = Raw2bulletin(BaseOptions)
Copy link
Contributor

Choose a reason for hiding this comment

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

you just end up with unit tests for Bulletin and Raw2Bulletin... still a good thing.
I mean most of the problems you ran into were bulletins with unexpected content, so those tests are doing useful stuff. It's at worst slightly mislabelled.

@andreleblanc11
Copy link
Member Author

I think it'd be better to merge now, so at least we'll have something for future PRs

@petersilva petersilva self-requested a review May 15, 2024 11:45
Copy link
Contributor

@petersilva petersilva left a comment

Choose a reason for hiding this comment

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

ok... approving on that basis...

@andreleblanc11 andreleblanc11 merged commit 9f61e90 into development May 15, 2024
28 of 35 checks passed
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