Repository navigation
add test enforcing adapter interface #1040
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
base: master
Are you sure you want to change the base?
Changes from all commits
9c823ac
a0ca023
5784cad
49de542
645025c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -107,7 +107,7 @@ def info_all(attrs: nil, host: nil) | |
| # @param owner [#to_s, Array<#to_s>] the owner(s) of the jobs | ||
| # @raise [JobAdapterError] if something goes wrong getting job info | ||
| # @return [Array<Info>] information describing submitted jobs | ||
| def info_where_owner(_, attrs: nil) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't a linter say this is correct?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I could have gone either way on this, so I will update to not check names of positional args and revert this change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe check with rubocop - I'm only saying that from memory. Maybe it'll say |
||
| def info_where_owner(owner, attrs: nil) | ||
| info_all | ||
| end | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| require 'test_helper' | ||
| require 'ood_core/job/adapter.rb' | ||
|
|
||
| ADAPTER_FILES = Dir[File.join('ood_core', 'job', 'adapters', '*.rb')] | ||
| ADAPTER_FILES.each { |file| require file } | ||
|
|
||
| class AdapterTest < Minitest::Test | ||
| BASE = OodCore::Job::Adapter | ||
|
|
||
| # Every concrete class descending from the base adapter | ||
| def adapters | ||
| ObjectSpace.each_object(Class).select { |klass| klass < BASE } | ||
| end | ||
|
|
||
| # Public methods defined by the base class itself (not inherited from Object) | ||
| def base_methods | ||
| BASE.public_instance_methods(false) | ||
| end | ||
|
|
||
| def test_adapters_were_found | ||
| refute_empty adapters, 'No subclasses of OodCore::Job::Adapter were found' | ||
| end | ||
|
|
||
| def test_adapter_interfaces_match_base_class | ||
| adapters.each do |adapter| | ||
| base_methods.each do |name| | ||
| impl = adapter.instance_method(name) | ||
|
|
||
| # If the method is not overridden, the base class method runs | ||
| next if impl.owner == BASE | ||
|
|
||
| # If it is overridden, the signature must match the base exactly | ||
| expected = BASE.instance_method(name).parameters | ||
| actual = impl.parameters | ||
|
|
||
| assert_equal expected, actual, | ||
| "#{adapter}##{name} (defined in #{impl.owner}) has parameters " \ | ||
| "#{actual.inspect}, but #{BASE}##{name} defines #{expected.inspect}" | ||
| end | ||
| end | ||
| end | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parent class doesn't have the host keyword. Not sure why it was implemented in
linux_host- I can't find it being used in OnDemand.ood_core/lib/ood_core/job/adapter.rb
Lines 56 to 58 in 8c5ca82
If anything we can open the interface to
attrsand**kwargsbut it seems unnecessary.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't scroll down far enough - you add it to the parent class.
In any case the comment I think still stands - open it up to
**kwargsor remove it from the child clasess. I would probably vote for the latter as I don't see it actually being used in OnDemand.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I might have to sit with this for a bit as I'm not sure I like either route very much. It seems kinda wrong to rip the host filtering feature out of LinuxHost and Systemd altogether when it has been there for 7ish years, but if we aren't using it then maybe nobody would care. On the flip side, a blanket
**kwargsfeels like it adds margin for error here, when the intent of the ticket was making the adapter interface more consistent to reduce confusion caused downstream.Looking back, it would have been nice if it had originally been added as a separate method, like
info_where_host(, but this far along I bet its about the same impact to change it as it is to rip it out altogether, the impact being that older unmaintained stuff could break