Class: Excon::Test::Server
- Inherits:
-
Object
- Object
- Excon::Test::Server
- Defined in:
- lib/excon/test/server.rb
Constant Summary collapse
- INSTANCE_REQUIRES =
Methods that must be implemented by a plugin
[:start]
Instance Attribute Summary collapse
-
#app ⇒ Object
Returns the value of attribute app.
-
#bind ⇒ Object
Returns the value of attribute bind.
-
#error ⇒ Object
Returns the value of attribute error.
-
#pid ⇒ Object
Returns the value of attribute pid.
-
#read ⇒ Object
Returns the value of attribute read.
-
#server ⇒ Object
Returns the value of attribute server.
-
#started_at ⇒ Object
Returns the value of attribute started_at.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
-
#write ⇒ Object
Returns the value of attribute write.
Instance Method Summary collapse
- #dump_errors ⇒ Object
- #elapsed_time ⇒ Object
-
#initialize(args) ⇒ Server
constructor
A new instance of Server.
- #open_process(*args) ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(args) ⇒ Server
Returns a new instance of Server.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/excon/test/server.rb', line 22 def initialize(args) # TODO: Validate these args @server = args.keys.first @app = args[server] args[:bind] ||= 'tcp://127.0.0.1:9292' @bind = URI.parse(args[:bind]) @is_unix_socket = (@bind.scheme == 'unix') @bind.host = @bind.host.gsub(/[\[\]]/, '') unless @is_unix_socket if args[:timeout] @timeout = args[:timeout] else @timeout = 20 end name = @server.to_s.split('_').collect(&:capitalize).join plug = nested_const_get("Excon::Test::Plugin::Server::#{name}") self.extend plug check_implementation(plug) end |
Instance Attribute Details
#app ⇒ Object
Returns the value of attribute app.
12 13 14 |
# File 'lib/excon/test/server.rb', line 12 def app @app end |
#bind ⇒ Object
Returns the value of attribute bind.
12 13 14 |
# File 'lib/excon/test/server.rb', line 12 def bind @bind end |
#error ⇒ Object
Returns the value of attribute error.
12 13 14 |
# File 'lib/excon/test/server.rb', line 12 def error @error end |
#pid ⇒ Object
Returns the value of attribute pid.
12 13 14 |
# File 'lib/excon/test/server.rb', line 12 def pid @pid end |
#read ⇒ Object
Returns the value of attribute read.
12 13 14 |
# File 'lib/excon/test/server.rb', line 12 def read @read end |
#server ⇒ Object
Returns the value of attribute server.
12 13 14 |
# File 'lib/excon/test/server.rb', line 12 def server @server end |
#started_at ⇒ Object
Returns the value of attribute started_at.
12 13 14 |
# File 'lib/excon/test/server.rb', line 12 def started_at @started_at end |
#timeout ⇒ Object
Returns the value of attribute timeout.
12 13 14 |
# File 'lib/excon/test/server.rb', line 12 def timeout @timeout end |
#write ⇒ Object
Returns the value of attribute write.
12 13 14 |
# File 'lib/excon/test/server.rb', line 12 def write @write end |
Instance Method Details
#dump_errors ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/excon/test/server.rb', line 71 def dump_errors lines = error.read.split($/) while (line = lines.shift) case line when /(ERROR|Error)/ unless line =~ /(null cert chain|did not return a certificate|SSL_read:: internal error)/ in_err = true puts end when /^(127|localhost)/ in_err = false end puts line if in_err end end |
#elapsed_time ⇒ Object
50 51 52 |
# File 'lib/excon/test/server.rb', line 50 def elapsed_time Time.now - started_at end |
#open_process(*args) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/excon/test/server.rb', line 41 def open_process(*args) if RUBY_PLATFORM == 'java' @pid, @write, @read, @error = IO.popen4(*args) else @pid, @write, @read, @error = Open4.popen4(*args) end @started_at = Time.now end |
#stop ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/excon/test/server.rb', line 54 def stop if RUBY_PLATFORM == 'java' Process.kill('USR1', pid) else Process.kill(9, pid) Process.wait(pid) end if @is_unix_socket socket = @bind.path File.delete(socket) if File.exist?(socket) end # TODO: Ensure process is really dead dump_errors true end |