Skip to content

Commit

Permalink
make usage of stop new semantics of LS
Browse files Browse the repository at this point in the history
make usage of proper stud:interval stop by introducing the version .22 code of it with the stop! method

Fixes #9
  • Loading branch information
Pere Urbon-Bayes authored and jordansissel committed Sep 21, 2015
1 parent 7f2222c commit 0379974
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
7 changes: 4 additions & 3 deletions lib/logstash/inputs/imap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def connect
end

def run(queue)
@run_thread = Thread.current
Stud.interval(@check_interval) do
check_mail(queue)
end
Expand Down Expand Up @@ -143,10 +144,10 @@ def parse_mail(mail)
end # def handle

public
def teardown
def stop
Stud.stop!(@run_thread)
$stdin.close
finished
end # def teardown
end

private

Expand Down
3 changes: 1 addition & 2 deletions logstash-input-imap.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ Gem::Specification.new do |s|

# Gem dependencies
s.add_runtime_dependency "logstash-core", '>= 1.4.0', '< 2.0.0'

s.add_runtime_dependency 'logstash-codec-plain'
s.add_runtime_dependency 'mail'
s.add_runtime_dependency 'stud'
s.add_runtime_dependency 'stud', '~> 0.0.22'

s.add_development_dependency 'logstash-devutils'
end
Expand Down
31 changes: 30 additions & 1 deletion spec/inputs/imap_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,37 @@
# encoding: utf-8
#
require "logstash/devutils/rspec/spec_helper"
require "logstash/inputs/imap"
require "mail"
require "net/imap"


describe LogStash::Inputs::IMAP do

context "when interrupting the plugin" do
it_behaves_like "an interruptible input plugin" do
let(:config) do
{ "type" => "imap",
"host" => "localhost",
"user" => "logstash",
"password" => "secret" }
end
let(:imap) { double("imap") }
let(:ids) { double("ids") }
before(:each) do
allow(imap).to receive(:login)
allow(imap).to receive(:select)
allow(imap).to receive(:close)
allow(imap).to receive(:disconnect)
allow(imap).to receive(:store)
allow(ids).to receive(:each_slice).and_return([])

allow(imap).to receive(:search).with("NOT SEEN").and_return(ids)
allow(Net::IMAP).to receive(:new).and_return(imap)
end
end
end

end

describe LogStash::Inputs::IMAP do
user = "logstash"
Expand Down

0 comments on commit 0379974

Please sign in to comment.