0

I am trying to write server spec code for some service. I want to add the timeout so that if within given time, command doesn't responds, the test case should fail.

When tried for timeout(0), test was passing. Does this mean that there is no timeout?

Code:

Timeout.timeout(0) do
  describe 'Check' do
    describe command('echo xxxx | nc localhost xxxx') do
      its(:stdout) { should contain('xxxx') }
      its(:stderr) { should match '' }
    end
  end
end

Generally timeout(0) or timeout(-1) will indicate that there is no timeout. Is it same with serverspec also. Please help.

Matthew Schuchard
  • 25,172
  • 3
  • 47
  • 67

2 Answers2

1

From Timeout docs:

Number of seconds to wait for the block to terminate. Any number may be used, including Floats to specify fractional seconds. A value of 0 or nil will execute the block without any timeout.

Emphasis is mine.

Aleksei Matiushkin
  • 119,336
  • 10
  • 100
  • 160
0

It means literally nothing. The other answer is more correct in showing you why, but the tl;dr is that code is useless, probably used to be non-zero when someone was incorrectly trying to make a test with a timeout.

coderanger
  • 52,400
  • 4
  • 52
  • 75