Skip to content

Commit d39205c

Browse files
committed
Rewrite a spec to avoid agent block and complex pipeline configs.
This now invokes the plugin directly via `receive` method before the test is run. The randomized values are now generated with Flores::Random and also use `let` instead of local variables. This test is currently passing at time of writing. Fixes #24
1 parent 8293f46 commit d39205c

File tree

1 file changed

+26
-29
lines changed

1 file changed

+26
-29
lines changed

spec/outputs/redis_spec.rb

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
require "logstash/outputs/redis"
33
require "logstash/json"
44
require "redis"
5+
require "flores/random"
56

67
describe LogStash::Outputs::Redis, :redis => true do
78

@@ -48,37 +49,33 @@
4849
end
4950

5051
describe "batch mode" do
51-
key = 10.times.collect { rand(10).to_s }.join("")
52-
event_count = 200000
52+
let(:key) { 10.times.collect { rand(10).to_s }.join("") }
53+
let(:event_count) { Flores::Random.integer(0..10000) }
54+
let(:message) { Flores::Random.text(0..100) }
5355

54-
config <<-CONFIG
55-
input {
56-
generator {
57-
message => "hello world"
58-
count => #{event_count}
59-
type => "generator"
60-
}
61-
}
62-
output {
63-
redis {
64-
host => "127.0.0.1"
65-
key => "#{key}"
66-
data_type => list
67-
batch => true
68-
batch_timeout => 5
69-
timeout => 5
70-
}
71-
}
72-
CONFIG
56+
let(:redis_output) {
57+
LogStash::Plugin.lookup("output", "redis").new(
58+
"host" => "127.0.0.1",
59+
"key" => key,
60+
"data_type" => "list",
61+
"batch" => true,
62+
"batch_timeout" => 5,
63+
"timeout" => 5
64+
)
65+
}
7366

74-
agent do
75-
# we have to wait for close to execute & flush the last batch.
76-
# otherwise we might start doing assertions before everything has been
77-
# sent out to redis.
78-
sleep 2
67+
before do
68+
redis_output.register
69+
event_count.times do |i|
70+
event = LogStash::Event.new("sequence" => i, "message" => message)
71+
redis_output.receive(event)
72+
end
73+
redis_output.close
74+
end
7975

76+
it "should successfully send all events to redis" do
8077
redis = Redis.new(:host => "127.0.0.1")
81-
78+
8279
# The list should contain the number of elements our agent pushed up.
8380
insist { redis.llen(key) } == event_count
8481

@@ -87,12 +84,12 @@
8784
id, element = redis.blpop(key, 0)
8885
event = LogStash::Event.new(LogStash::Json.load(element))
8986
insist { event["sequence"] } == value
90-
insist { event["message"] } == "hello world"
87+
insist { event["message"] } == message
9188
end
9289

9390
# The list should now be empty
9491
insist { redis.llen(key) } == 0
95-
end # agent
92+
end
9693
end
9794
end
9895

0 commit comments

Comments
 (0)