spec/inputs/file_spec.rb in logstash-input-file-1.0.1 vs spec/inputs/file_spec.rb in logstash-input-file-1.0.2
- old
+ new
@@ -4,11 +4,19 @@
require "tempfile"
require "stud/temporary"
require "logstash/inputs/file"
describe "inputs/file" do
+ before(:all) do
+ @abort_on_exception = Thread.abort_on_exception
+ Thread.abort_on_exception = true
+ end
+ after(:all) do
+ Thread.abort_on_exception = @abort_on_exception
+ end
+
delimiter = (LogStash::Environment.windows? ? "\r\n" : "\n")
it "should starts at the end of an existing file" do
tmpfile_path = Stud::Temporary.pathname
sincedb_path = Stud::Temporary.pathname
@@ -176,8 +184,49 @@
FileUtils.rm_rf(sincedb_path)
end
it "should raise exception" do
expect { subject.register }.to raise_error(ArgumentError)
+ end
+ end
+
+ context "when #run is called multiple times", :unix => true do
+ let(:tmpdir_path) { Stud::Temporary.directory }
+ let(:sincedb_path) { Stud::Temporary.pathname }
+ let(:file_path) { "#{tmpdir_path}/a.log" }
+ let(:buffer) { [] }
+ let(:lsof) { [] }
+ let(:stop_proc) do
+ lambda do |input, arr|
+ Thread.new(input, arr) do |i, a|
+ sleep 0.5
+ a << `lsof -p #{Process.pid} | grep "a.log"`
+ i.teardown
+ end
+ end
+ end
+
+ subject { LogStash::Inputs::File.new("path" => tmpdir_path + "/*.log", "start_position" => "beginning", "sincedb_path" => sincedb_path) }
+
+ after :each do
+ FileUtils.rm_rf(tmpdir_path)
+ FileUtils.rm_rf(sincedb_path)
+ end
+ before do
+ File.open(file_path, "w") do |fd|
+ fd.puts('foo')
+ fd.puts('bar')
+ end
+ end
+ it "should only have one set of files open" do
+ subject.register
+ lsof_before = `lsof -p #{Process.pid} | grep #{file_path}`
+ expect(lsof_before).to eq("")
+ stop_proc.call(subject, lsof)
+ subject.run(buffer)
+ expect(lsof.first).not_to eq("")
+ stop_proc.call(subject, lsof)
+ subject.run(buffer)
+ expect(lsof.last).to eq(lsof.first)
end
end
end