Skip to content

Commit

Permalink
Fix bug causing crash when 'every' is set (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
jordansissel committed Nov 30, 2016
1 parent f56f2bf commit 1b3f415
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 3.0.3
- Fix bug causing crash when `every` is set. (#5)

## 3.0.2
- Relax constraint on logstash-core-plugin-api to >= 1.60 <= 2.99

Expand Down
2 changes: 1 addition & 1 deletion lib/logstash/filters/sleep.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def filter(event)
end
@last_clock = clock
else
if @count >= @every
if @count >= @every.to_f
@count = 0
@logger.debug? && @logger.debug("Sleeping", :delay => time)
sleep(time)
Expand Down
2 changes: 1 addition & 1 deletion logstash-filter-sleep.gemspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Gem::Specification.new do |s|

s.name = 'logstash-filter-sleep'
s.version = '3.0.2'
s.version = '3.0.3'
s.licenses = ['Apache License (2.0)']
s.summary = "Sleep a given amount of time"
s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"
Expand Down
11 changes: 9 additions & 2 deletions spec/filters/sleep_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
describe "sleep for a given time" do

let(:time) { 5 }

before(:each) do
subject.register
end
Expand All @@ -30,7 +29,6 @@
end

context "when using every N events" do

let(:messages) { 20 }
let(:every) { 5 }
subject { LogStash::Filters::Sleep.new("time" => time, "every" => every ) }
Expand All @@ -46,6 +44,15 @@
end
end

context "and `every` is given as a string" do
let(:every) { "5" }
it "should sleep for N seconds and continue" do
expect(subject).to receive(:sleep).with(5).exactly(4).times
messages.times do
subject.filter(event)
end
end
end
end
end
end

0 comments on commit 1b3f415

Please sign in to comment.