spec/inputs/exec_spec.rb in logstash-input-exec-3.4.0 vs spec/inputs/exec_spec.rb in logstash-input-exec-3.6.0

- old
+ new

@@ -44,10 +44,27 @@ expect(queue.size).not_to be_zero end end + context "when command fails" do + let(:input) { described_class.new("command" => "invalid_command 1 2 3", "interval" => 0) } + let(:queue) { [] } + + before :each do + input.register + end + + it "does not enqueue an event (in a non-Docker env)" do + expect(input.logger).to receive(:error).and_call_original + + input.execute(queue) + + expect(queue.map(&:to_hash)).to be_empty + end + end + context "when a command runs normally" do let(:command) { "/bin/sh -c 'sleep 1; /bin/echo -n two; exit 3'" } let(:input) { described_class.new("command" => command, "interval" => 0) } let(:queue) { [] } @@ -71,11 +88,11 @@ elapsed_time = queue.pop.get('[@metadata][input][exec][process][elapsed_time]') expect(elapsed_time).to be_a Integer expect(elapsed_time).to be > 1 * 1_000_000 expect(elapsed_time).to be < 3 * 1_000_000 end if ecs_select.active_mode != :disabled - + it "has output as expected" do expect(queue.pop.get('message')).to eq "two" end it "reports process command_line " do @@ -97,28 +114,31 @@ end end context "when scheduling" do - let(:input) { described_class.new("command" => "ls --help", "schedule" => "* * * * * UTC") } + let(:input) { described_class.new("command" => "ls --help", "schedule" => "5-6 * * * * UTC") } let(:queue) { [] } before do + Timecop.travel(Time.new(2000)) + Timecop.scale(60) input.register end + after do + Timecop.return + end + it "should properly schedule" do - Timecop.travel(Time.new(2000)) - Timecop.scale(60) runner = Thread.new do input.run(queue) end - sleep 3 + sleep 10 input.stop runner.kill runner.join expect(queue.size).to eq(2) - Timecop.return end end context "when interrupting the plugin" do