C0 code coverage information

Generated on Sat Feb 02 17:44:24 +0100 2008 with rcov 0.8.1.2


Code reported as executed by Ruby looks like this...
and this: this line is also marked as covered.
Lines considered as run by rcov, but not reported by Ruby, look like this,
and this: these lines were inferred by rcov (using simple heuristics).
Finally, here's a line marked as not executed.
Name Total lines Lines of code Total coverage Code coverage
lib/ramaze/adapter.rb 122 72
77.9% 
65.3% 
  1 #          Copyright (c) 2008 Michael Fellinger m.fellinger@gmail.com
  2 # All files in this distribution are subject to the terms of the Ruby license.
  3 
  4 require 'socket'
  5 require 'timeout'
  6 require 'benchmark'
  7 
  8 require 'rack'
  9 require 'rack/utils'
 10 
 11 require 'ramaze/trinity'
 12 require 'ramaze/tool/record'
 13 require 'ramaze/adapter/base'
 14 
 15 # for OSX compatibility
 16 Socket.do_not_reverse_lookup = true
 17 
 18 module Ramaze
 19 
 20   # Shortcut to the HTTP_STATUS_CODES of Rack::Utils
 21   # inverted for easier access
 22 
 23   STATUS_CODE = Rack::Utils::HTTP_STATUS_CODES.invert
 24 
 25   # This module holds all classes and methods related to the adapters like
 26   # webrick or mongrel.
 27   # It's responsible for starting and stopping them.
 28 
 29   module Adapter
 30     class << self
 31 
 32       # Is called by Ramaze.startup and will first call start_adapter and wait
 33       # up to 3 seconds for an adapter to appear.
 34       # It will then wait for the adapters to finish If Global.run_loose is
 35       # set or otherwise pass you on control which is useful for testing or IRB
 36       # sessions.
 37 
 38       def startup options = {}
 39         start_adapter
 40 
 41         Timeout.timeout(3) do
 42           sleep 0.01 until Global.adapters.any?
 43         end
 44 
 45         Global.adapters.each{|a| a.join} unless Global.run_loose
 46 
 47       rescue SystemExit
 48         Ramaze.shutdown
 49       rescue Object => ex
 50         Inform.error(ex)
 51         Ramaze.shutdown
 52       end
 53 
 54       # Takes Global.adapter and starts if test_connections is positive that
 55       # connections can be made to the specified host and ports.
 56       # If you set Global.adapter to false it won't start any but deploy a
 57       # dummy which is useful for testing purposes where you just send fake
 58       # requests to Dispatcher.
 59 
 60       def start_adapter
 61         if adapter = Global.adapter
 62           host, ports = Global.host, Global.ports
 63 
 64           Inform.info("Adapter: #{adapter}, testing connection to #{host}:#{ports}")
 65           test_connections(host, ports)
 66 
 67           Inform.info("and we're running: #{host}:#{ports}")
 68           adapter.start(host, ports)
 69         else # run dummy
 70           Global.adapters.add Thread.new{ sleep }
 71           Inform.warn("Seems like Global.adapter is turned off", "Continue without adapter.")
 72         end
 73       rescue LoadError => ex
 74         Inform.warn(ex, "Continue without adapter.")
 75       end
 76 
 77       # Calls ::shutdown on all running adapters and waits up to 1 second for
 78       # them to finish, then goes on to kill them and exit still.
 79 
 80       def shutdown
 81         Timeout.timeout(1) do
 82           Global.adapters.each do |adapter|
 83             a = adapter[:adapter]
 84             a.shutdown if a.respond_to?(:shutdown)
 85           end
 86         end
 87       rescue Timeout::Error
 88         Global.adapters.each{|a| a.kill! }
 89         # Hard exit! because it won't be able to kill Webrick otherwise
 90         exit!
 91       end
 92 
 93       # check the given host and ports via test_connection.
 94       # Shuts down if no connection is possible.
 95 
 96       def test_connections host, ports
 97         return unless Global.test_connections
 98 
 99         ports.each do |port|
100           unless test_connection(host, port)
101             Inform.error("Cannot open connection on #{host}:#{port}")
102             Ramaze.shutdown
103           end
104         end
105       end
106 
107       # Opens a TCPServer temporarily and returns true if a connection is
108       # possible and false if none can be made
109 
110       def test_connection host, port
111         Timeout.timeout(1) do
112           testsock = TCPServer.new(host, port)
113           testsock.close
114           true
115         end
116       rescue => ex
117         Inform.error(ex)
118         false
119       end
120     end
121   end
122 end

Generated using the rcov code coverage analysis tool for Ruby version 0.8.1.2.

Valid XHTML 1.0! Valid CSS!