Skip to content

Commit

Permalink
Code review
Browse files Browse the repository at this point in the history
Fixes #7
  • Loading branch information
ph authored and jordansissel committed Aug 19, 2015
1 parent c228dae commit 133d6a6
Showing 1 changed file with 6 additions and 17 deletions.
23 changes: 6 additions & 17 deletions spec/outputs/lumberjack_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# encoding: utf-8
require "logstash/outputs/Lumberjack"
require "logstash/outputs/lumberjack"
require "logstash/event"
require "logstash/devutils/rspec/spec_helper"
require "lumberjack/server"
Expand All @@ -10,14 +10,10 @@
describe "Sending events" do
let(:batch_size) { Flores::Random.integer(20..100) }
let(:batch_payload) do
batch = []
batch_size.times do |n|
batch << LogStash::Event.new({ "message" => "foobar #{n}" })
end
batch
batch_size.times.collect { |n| LogStash::Event.new({ "message" => "foobar #{n}" }) }
end

let(:number_of_crash) { Flores::Random.integer(1..3) }
let(:number_of_crash) { Flores::Random.integer(1..10) }
let(:certificate) { Flores::PKI.generate }
let(:certificate_file_crt) { Stud::Temporary.pathname }
let(:certificate_file_key) { Stud::Temporary.pathname }
Expand All @@ -30,7 +26,7 @@
"hosts" => [host],
"port" => port,
"ssl_certificate" => certificate_file_crt,
"flush_size" => 10#batch_size # flush at the end of the payload
"flush_size" => batch_size
}
}
let(:input) { LogStash::Outputs::Lumberjack.new(client_options) }
Expand All @@ -49,19 +45,14 @@
@server = Thread.new do
begin
server.run do |data|
crashed_count += 1

# make the client crash, forcing a retransmit.
# send his payload.
if crashed_count < number_of_crash && Random.rand >= 0.5
if crashed_count < number_of_crash
crashed_count += 1
raise "crashed"
end

queue << data
end
rescue
puts "CRASHED ONCEEEEE"
end
end

Expand All @@ -80,9 +71,7 @@
input.receive(event)
end

sleep(3) # backoff a bit, mocking the socket would fix this kind of issues?

expect(queue.size).to be >= batch_size
try(10) { expect(queue.size).to be >= batch_size }
expect(queue.map { |e| e["line"] }).to include(*batch_payload.map(&:to_s))
end
end
Expand Down

0 comments on commit 133d6a6

Please sign in to comment.