Skip to content

Commit ff199c7

Browse files
authored
Test: refactor potential stub leak from example (#169)
1 parent 8385b2e commit ff199c7

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

spec/inputs/elasticsearch_spec.rb

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ def wait_receive_request
933933
{
934934
"hosts" => ["localhost"],
935935
"query" => '{ "query": { "match": { "city_name": "Okinawa" } }, "fields": ["message"] }',
936-
"schedule" => "* * * * * UTC"
936+
"schedule" => "* * * * * * UTC" # every second
937937
}
938938
end
939939

@@ -942,21 +942,14 @@ def wait_receive_request
942942
end
943943

944944
it "should properly schedule" do
945-
Timecop.travel(Time.new(2000))
946-
Timecop.scale(60)
947-
runner = Thread.new do
948-
expect(plugin).to receive(:do_run) {
949-
queue << LogStash::Event.new({})
950-
}.at_least(:twice)
951-
952-
plugin.run(queue)
953-
end
954-
sleep 3
945+
expect(plugin).to receive(:do_run) {
946+
queue << LogStash::Event.new({})
947+
}.at_least(:twice)
948+
runner = Thread.start { plugin.run(queue) }
949+
sleep 3.0
955950
plugin.stop
956-
runner.kill
957951
runner.join
958-
expect(queue.size).to eq(2)
959-
Timecop.return
952+
expect(queue.size).to be >= 2
960953
end
961954

962955
end

0 commit comments

Comments
 (0)