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

PR for Refactor shutdown sequence to use plugin.stop #4

Closed
wants to merge 1 commit into from

Conversation

guyboertje
Copy link
Contributor

Shutdown semantics: Add stop method and shared_example
Add general tests (none before)
slight refactor
tests pass

Notes for Reviewers:

  • This is a mixed PR, it contains code changes for the fix and general refactoring, because this plugin is very distant from core, the codebase has changed little since 2012 and there were no tests.
  • The requires are not lazy loaded.
  • Following our change in understanding about ivars and concurrency, I moved the ivar creation into the initialize method.
  • I feared that when multiple rooms were specified, all but the last MUC client might be GC'd so I stored them in an array.
  • I made the client and muc_clients available as attr readers so the tests could mimic the block call action when receiving messages.
  • The tests use Mock classes that provide the same API as the Jabber Client and MUCSimpleClient. Normally a test purist would say this is wrong because the API could change etc. I considered this and figured that as the xmpp4r gem development has essentially stopped the risk was v low.
  • The Mock classes are inline and not in a separate file so others can read them easily. I suspect, beyond bug fixes in this PR, this plugin will probably not see any more changes for some time.

Closes #3

end # def register

public
# for testing access
attr_reader :client, :muc_clients
Copy link

Choose a reason for hiding this comment

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

should we move this to the top or bottom of the file for easy finding?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My thinking: as its used in methods from register downwards it should be above def register.

We don't really enforce the classic ruby file layout and for plugins I think the config DSL should standout at the top. My 2c.

end # def run

def stop
super
Copy link
Member

Choose a reason for hiding this comment

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

super is no longer needed

require "logstash/devutils/rspec/spec_helper"
require 'logstash/inputs/xmpp'

module Jabber
Copy link

Choose a reason for hiding this comment

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

I would move this mocks to an spec_helper.rb file or other kind of support helper concept.

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 considered this and made a point about it in the Reviewers Notes above. What rule of thumb should we apply here? On the one hand it is tidy to move the mocks to their own file and on the other hand, moving them will make it less easy to read and follow the whole spec suite in one go.

I cannot find any solid guidance in the Internet about extract or not wrt helpers. Even the Rspec style guide is silent on this.

The only RSpec convention is to put them in /support and they get auto-loaded but then the same people that don't know what described_class means will not know about this RSpec convention either.

Copy link

Choose a reason for hiding this comment

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

Hi,
as there no official logstash style guide about it, it end up very personal. But in my experience, keeping the test without the definition of mocks and other support classes makes sense as code is simpler and easier to understand then.

I would strongly recommend you to do it as will keep things easy to understand and manage in the long term. But again this is my opinion, i tend to like everything in their place, and for this example mocks belong to their definition files and test belong here, mixing them confuses the read, and somehow makes stuff tied up.

On the other side, even if not official this is a pattern I'm trying to enforce in the hole code base, so it would be nice to have mocks defined in helper files that then gets used in the examples.

Again, is the same example as having smoller methods as possible, we're humans and to understand big pieces of code it gets error prone.

@purbon
Copy link

purbon commented Sep 23, 2015

LGTM, keep in mind to squash the commits before merging 👍

@purbon purbon self-assigned this Sep 23, 2015
Add general tests (none before)
slight refactor
tests pass

oops uncomment (was troubleshooting)

move attr_reader up and actually use them in this class

fix typo in test context string

remove call to super in `stop` method

use Stub.stoppable_sleep(Float::INFINITY){ stop? }, remove own thread ivar

move mocks to own file + DRY up specs.

closes 3
@elasticsearch-bot
Copy link

Merged sucessfully into master!

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.

refactor shutdown sequence to use plugin.stop
6 participants