spec/inputs/elasticsearch_spec.rb in logstash-input-elasticsearch-4.12.2 vs spec/inputs/elasticsearch_spec.rb in logstash-input-elasticsearch-4.12.3

- old
+ new

@@ -45,30 +45,30 @@ end end end it_behaves_like "an interruptible input plugin" do - let(:esclient) { double("elasticsearch-client") } let(:config) do { "schedule" => "* * * * * UTC" } end before :each do - allow(Elasticsearch::Client).to receive(:new).and_return(esclient) + @esclient = double("elasticsearch-client") + allow(Elasticsearch::Client).to receive(:new).and_return(@esclient) hit = { "_index" => "logstash-2014.10.12", "_type" => "logs", "_id" => "C5b2xLQwTZa76jBmHIbwHQ", "_score" => 1.0, "_source" => { "message" => ["ohayo"] } } - allow(esclient).to receive(:search) { { "hits" => { "hits" => [hit] } } } - allow(esclient).to receive(:scroll) { { "hits" => { "hits" => [hit] } } } - allow(esclient).to receive(:clear_scroll).and_return(nil) - allow(esclient).to receive(:ping) + allow(@esclient).to receive(:search) { { "hits" => { "hits" => [hit] } } } + allow(@esclient).to receive(:scroll) { { "hits" => { "hits" => [hit] } } } + allow(@esclient).to receive(:clear_scroll).and_return(nil) + allow(@esclient).to receive(:ping) end end ecs_compatibility_matrix(:disabled, :v1, :v8) do |ecs_select| @@ -931,33 +931,26 @@ context "when scheduling" do let(:config) do { "hosts" => ["localhost"], "query" => '{ "query": { "match": { "city_name": "Okinawa" } }, "fields": ["message"] }', - "schedule" => "* * * * * UTC" + "schedule" => "* * * * * * UTC" # every second } end before do plugin.register end it "should properly schedule" do - Timecop.travel(Time.new(2000)) - Timecop.scale(60) - runner = Thread.new do - expect(plugin).to receive(:do_run) { - queue << LogStash::Event.new({}) - }.at_least(:twice) - - plugin.run(queue) - end - sleep 3 + expect(plugin).to receive(:do_run) { + queue << LogStash::Event.new({}) + }.at_least(:twice) + runner = Thread.start { plugin.run(queue) } + sleep 3.0 plugin.stop - runner.kill runner.join - expect(queue.size).to eq(2) - Timecop.return + expect(queue.size).to be >= 2 end end # @note can be removed once we depends on elasticsearch gem >= 6.x