diff options
| author | mo khan <mo@mokhan.ca> | 2013-08-28 07:20:13 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2013-08-28 07:20:13 -0600 |
| commit | db1191ec0e7305d684383f8974e2fa437f77ad5a (patch) | |
| tree | 5e27b197dff849d22d8e1f50eb75aa499b16bd06 /code/spyglass/test/timeout_test.rb | |
Diffstat (limited to 'code/spyglass/test/timeout_test.rb')
| -rw-r--r-- | code/spyglass/test/timeout_test.rb | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/code/spyglass/test/timeout_test.rb b/code/spyglass/test/timeout_test.rb new file mode 100644 index 0000000..9cbe134 --- /dev/null +++ b/code/spyglass/test/timeout_test.rb @@ -0,0 +1,51 @@ +require 'helper' +require 'excon' +require 'tempfile' + +class TimeoutTest < MiniTest::Unit::TestCase + def setup + @lifeline = Tempfile.open('lifeline') + @uri = "http://0.0.0.0:#{PORT}/zing" + + config_ru <<-RU + require 'sinatra' + + get '/zing' do + redirect 'http://example.com' + end + + at_exit { File.unlink('#{@lifeline.path}') rescue nil } + + run Sinatra::Application + RU + spyglass :timeout => 3 + end + + def test_times_out_after_timeout_has_expired + Excon.get(@uri) + sleep 3.5 + + # When the Master process loads the Sinatra it will set up the at_exit + # hook defined above. That process should exit after 3 seconds, removing + # our @lifeline file. If the file still exists at this point then the + # timeout didn't happen properly. + refute File.file?(@lifeline.path), "Spyglass didn't time out properly" + end + + def test_doesnt_time_out_if_requests_keep_coming + Excon.get(@uri) + sleep 1 + Excon.get(@uri) + sleep 1 + + Excon.get(@uri) + sleep 1.5 + Excon.get(@uri) + + # When the Master process loads the Sinatra it will set up the at_exit + # hook defined above. Since we're keeping the server saturated with + # requests, definitely not letting it sit idle for 3 seconds, the @lifeline + # file should still exist when we get here. + assert File.file?(@lifeline.path), "Spyglass didn't time out properly" + end +end |
