summaryrefslogtreecommitdiff
path: root/code/spyglass/test/timeout_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'code/spyglass/test/timeout_test.rb')
-rw-r--r--code/spyglass/test/timeout_test.rb51
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