Skip to content

Commit 3624548

Browse files
authored
Refactor: unify event updates to happen in one place (#297)
+ Test: a try that actually re-tries on `RSpec::Expectations::ExpectationNotMetError` + Test: re-try instead of relying on timeout
1 parent 9be8dc2 commit 3624548

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

lib/logstash/inputs/file.rb

+3-4
Original file line numberDiff line numberDiff line change
@@ -373,12 +373,11 @@ def run(queue)
373373
@completely_stopped.make_true
374374
end # def run
375375

376-
def post_process_this(event)
376+
def post_process_this(event, path)
377+
event.set("[@metadata][path]", path)
377378
event.set("[@metadata][host]", @host)
378379
attempt_set(event, @source_host_field, @host)
379-
380-
source_path = event.get('[@metadata][path]') and
381-
attempt_set(event, @source_path_field, source_path)
380+
attempt_set(event, @source_path_field, path) if path
382381

383382
decorate(event)
384383
@queue.get << event

lib/logstash/inputs/file_listener.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ def accept(data)
4040
end
4141

4242
def process_event(event)
43-
event.set("[@metadata][path]", path)
44-
input.post_process_this(event)
43+
input.post_process_this(event, path)
4544
end
4645

4746
end

spec/inputs/file_read_spec.rb

+6-3
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@
338338
sincedb_content = File.read(sincedb_path).strip
339339
expect( sincedb_content ).to_not be_empty
340340

341-
Stud.try(3.times) do
341+
try(3) do
342342
sleep(1.5) # > sincedb_clean_after
343343

344344
sincedb_content = File.read(sincedb_path).strip
@@ -363,7 +363,10 @@ def wait_for_start_processing(run_thread, timeout: 1.0)
363363
end
364364
end
365365

366-
def wait_for_file_removal(path, timeout: 3 * interval)
367-
wait(timeout).for { File.exist?(path) }.to be_falsey
366+
def wait_for_file_removal(path)
367+
timeout = interval
368+
try(5) do
369+
wait(timeout).for { File.exist?(path) }.to be_falsey
370+
end
368371
end
369372
end

0 commit comments

Comments
 (0)