test/proxymachine_test.rb in fizx-proxymachine-1.3.0 vs test/proxymachine_test.rb in fizx-proxymachine-1.4.0

- old
+ new

@@ -6,10 +6,18 @@ assert_equal recv, sock.read sock.close end class ProxymachineTest < Test::Unit::TestCase + def setup + @proxy_error_file = "#{File.dirname(__FILE__)}/proxy_error" + end + + def teardown + File.unlink(@proxy_error_file) rescue nil + end + should "handle simple routing" do assert_proxy('localhost', 9990, 'a', '9980:a') assert_proxy('localhost', 9990, 'b', '9981:b') end @@ -41,7 +49,35 @@ sock.close end should "execute a callback" do assert_proxy('localhost', 9990, 'h', '9980:h:callback') + end + + should "call proxy_connect_error when a connection is rejected" do + sock = TCPSocket.new('localhost', 9990) + sock.write('connect reject') + sock.flush + assert_equal "", sock.read + sock.close + assert_equal "connect error: localhost:9989", File.read(@proxy_error_file) + end + + should "call proxy_inactivity_error when initial read times out" do + sock = TCPSocket.new('localhost', 9990) + sent = Time.now + sock.write('inactivity') + sock.flush + assert_equal "", sock.read + assert_operator Time.now - sent, :>=, 1.0 + assert_equal "activity error: localhost:9980", File.read(@proxy_error_file) + sock.close + end + + should "not consider client disconnect a server error" do + sock = TCPSocket.new('localhost', 9990) + sock.write('inactivity') + sock.close + sleep 3.1 + assert !File.exist?(@proxy_error_file) end end