Skip to content

Commit b7ec2a6

Browse files
Pere Urbon-Bayesjordansissel
authored andcommitted
add some cleanup testing
Fixes elastic#2
1 parent b3cb12b commit b7ec2a6

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

lib/lsit/run.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
require 'lsit/stats'
66

7-
INITIAL_MESSAGE = ">>> lorem ipsum start".freeze
8-
LAST_MESSAGE = ">>> lorem ipsum stop".freeze
9-
107
Thread.abort_on_exception = true
118

129
class Runner
1310
LOGSTASH_BIN = File.join("bin", "logstash").freeze
11+
12+
INITIAL_MESSAGE = ">>> lorem ipsum start".freeze
13+
LAST_MESSAGE = ">>> lorem ipsum stop".freeze
1414
REFRESH_COUNT = 100
1515

1616
attr_reader :command
@@ -62,11 +62,8 @@ def read_input_file(file_path)
6262
IO.readlines(file_path).map(&:chomp)
6363
end
6464

65-
private
66-
6765
def feed_input_events(io, events_count, lines, last_message)
6866
loop_count = (events_count / lines.size).ceil # how many time we send the input file over
69-
7067
(1..loop_count).each{lines.each {|line| io.puts(line)}}
7168

7269
io.puts(last_message)
@@ -75,6 +72,8 @@ def feed_input_events(io, events_count, lines, last_message)
7572
loop_count * lines.size
7673
end
7774

75+
private
76+
7877
def feed_input_interval(io, seconds, lines, last_message)
7978
loop_count = (2000 / lines.size).ceil # check time every ~2000(ceil) input lines
8079
lines_per_iteration = loop_count * lines.size

spec/lib/runner_spec.rb

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,32 @@
33
describe Runner do
44

55
let(:config) { 'spec/fixtures/simple.conf' }
6-
let(:lines) { load_fixture 'simple_10.txt' }
6+
let(:lines) { load_fixture('simple_10.txt').split("\n") }
77

88
let(:events) { 30 }
99
let(:time) { 10 }
1010

1111
subject (:runner) { Runner.new(config) }
1212

13+
let(:command) { [Runner::LOGSTASH_BIN, "-f", "spec/fixtures/simple.conf"]}
14+
15+
it "invokes the logstash command" do
16+
Open3.should_receive(:popen3).with(*command).and_return(true)
17+
runner.run(events, 0, lines)
18+
end
19+
1320
context "#execution with number of events" do
1421

15-
let(:command) { [Runner::LOGSTASH_BIN, "-f", "spec/fixtures/simple.conf"]}
22+
let(:io) { double("io", :puts => true, :flush => true) }
23+
subject(:feed) { runner.feed_input_with(events, 0, lines, io) }
24+
25+
it "feeds in terms of events" do
26+
expect(runner).to receive(:feed_input_events).with(io, events, lines, Runner::LAST_MESSAGE)
27+
runner.feed_input_with(events, 0, lines, io)
28+
end
1629

17-
it "should invoke the logstash command" do
18-
Open3.should_receive(:popen3).with(*command).and_return(true)
19-
runner.run(events, 0, lines)
30+
it "feed the input stream with events.size+1 events" do
31+
expect(feed).to eq(events.to_i)
2032
end
2133

2234
end

0 commit comments

Comments
 (0)