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

Make usage of the new shutdown api + small rspec refactor #10

Closed
wants to merge 1 commit into from
Closed

Make usage of the new shutdown api + small rspec refactor #10

wants to merge 1 commit into from

Conversation

purbon
Copy link

@purbon purbon commented Sep 1, 2015

Implements stop to return from run according to elastic/logstash#3210

Depends on elastic/logstash-devutils#32 and elastic/logstash#3812

Fixes #11

@@ -1,43 +1,63 @@
# encoding: utf-8
require "logstash/devutils/rspec/spec_helper"
require_relative "../spec_helper"
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure this change feels right. It saves us one line of code here, but moves it to another file and requires a new file to be maintained. Can you tell me about the gain here?

Copy link
Author

Choose a reason for hiding this comment

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

Me having the old "automatic" behaviour of pointing everything to a single spec_helper per project, so there we can have specific helpers, mocks, etc. But I understand this does not provide much here 👍

@jordansissel
Copy link
Contributor

The pipe from echo test hangs for me, but may be unrelated to this change. I haven't investigated yet.

The new test doesn't pass for me:

⓿ crinkle(~/projects/logstash-input-pipe) pull/10 !1! 
% bundle exec rspec  -f d -e 'interruptible'
Run options:
  include {:full_description=>/interruptible/}
  exclude {:redis=>true, :socket=>true, :performance=>true, :couchdb=>true, :elasticsearch=>true, :elasticsearch_secure=>true, :export_cypher=>true, :integration=>true, :windows=>true}

LogStash::Inputs::Pipe
  behaves like an interruptible input plugin
    stop
      returns from run (FAILED - 1)

Failures:

  1) LogStash::Inputs::Pipe behaves like an interruptible input plugin stop returns from run
     Failure/Error: wait(1).for { thread }.to be_alive
       expected `#<Thread:0x132ddbab dead>.alive?` to return true, got false
     Shared Example Group: "an interruptible input plugin" called from ./spec/inputs/pipe_spec.rb:14

@jordansissel
Copy link
Contributor

(I have elastic/logstash#3812 and elastic/logstash-devutils#32 installed locally)

@purbon
Copy link
Author

purbon commented Sep 2, 2015

Thanks for your test @jordansissel I will investigate this.

@purbon
Copy link
Author

purbon commented Sep 2, 2015

If I understand your issue @jordansissel properly, this could happen because the plugin actually finished even before the first check for being alive. This makes me to have a question here, how do you guess this would have happen? might this be an error during the loop? Can you check if you see any kind of exception or logging message?

I will try to reproduce, but I think the situation you see if because I took away https://github.com/logstash-plugins/logstash-input-pipe/blob/master/lib/logstash/inputs/pipe.rb#L66 in this PR, I will bring it back and introduce a way to wakeup the thread if necessary. Hope this provide a solution to your issue.

@purbon
Copy link
Author

purbon commented Sep 2, 2015

@jordansissel, this test uses a unicode character, might be there is a problem regarding this?

@purbon
Copy link
Author

purbon commented Sep 2, 2015

My expectation is the new test added https://github.com/purbon/logstash-input-pipe/commit/88abb4836da765f6650560581611722d041908c9 should not be failing in your env, can you check that for me?

Thanks a lot.

rescue Exception => e
@logger.error("Exception while running command", :e => e, :backtrace => e.backtrace)
end

# Keep running the command forever.
sleep(10)
@sleep = true
Copy link
Contributor

Choose a reason for hiding this comment

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

what is the purpose of this? Should we be using a synchronization mechanism instead? I'm not sure I like sleep+wakeup, but wait+notify is more common (a ConditionVariable) and I feel more confident in its thread safety.

@jordansissel
Copy link
Contributor

Both @jsvd and @purbon report the interrupted tests passing for them, so I'm content to believe something is wrong with my environment.

I did a pass at code review. Overall looking good; had some questions about the @sleep stuff and locking and left inline comments.

@shutdown_requested = true
def stop
super
Stud.stop!
Copy link
Contributor

Choose a reason for hiding this comment

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

unless Stud.interval is used, Stud.stop! is not required.

Copy link
Author

Choose a reason for hiding this comment

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

cool, I got it, I thought it was necessary to stop stoppable_sleep too.

@purbon
Copy link
Author

purbon commented Sep 21, 2015

@talevy @jordansissel @colinsurprenant is this plugin ready to be merged?

@suyograo suyograo assigned jordansissel and unassigned suyograo Sep 21, 2015
@suyograo
Copy link
Contributor

@purbon can you rebase?

@talevy
Copy link

talevy commented Sep 22, 2015

pre-rebase: LGTM

refactor a bit the specs in order to include the new shared example to
track the shutdown plus make them more rspec friendly.
@elasticsearch-bot
Copy link

Merged sucessfully into master!

@purbon purbon closed this in dcbe175 Sep 22, 2015
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.

6 participants