Skip to content
Prev Previous commit
Next Next commit
Test: a naive test for timeout kickin
  • Loading branch information
kares committed Nov 22, 2021
commit 22f13fe175cc8bc5faeb6a308cee72ebbd6fcec3
25 changes: 23 additions & 2 deletions spec/inputs/unix_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,29 @@
end

context "when the unix socket has no data to be read" do
it_behaves_like "an interruptible input plugin" do
let(:run_forever) { false }

let(:run_forever) { false }

it_behaves_like "an interruptible input plugin"

context 'with timeout' do

let(:config) { super().merge "data_timeout" => 1.0 }

let(:queue) { SizedQueue.new(10) }
before(:each) { subject.register }
after(:each) { subject.do_stop }

it "closes socket after timeout" do
plugin_thread = Thread.new(subject, queue) { |subject, queue| subject.run(queue) }
sleep 0.5
client_socket = subject.instance_variable_get :@client_socket
expect( client_socket.closed? ).to be false
sleep 1.0 # allow timeout to kick in
expect( client_socket.closed? ).to be true
expect( plugin_thread ).to be_alive
end

end
end

Expand Down