realweb 0.1.6 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,10 +1,10 @@
1
- require 'realweb/in_thread_server'
1
+ require 'realweb/thread_server'
2
2
  require 'realweb/forking_server'
3
3
 
4
4
  module RealWeb
5
5
  class << self
6
6
  def start_server_in_thread(*args)
7
- InThreadServer.new(*args) { |server| server.start }
7
+ ThreadServer.new(*args) { |server| server.start }
8
8
  end
9
9
 
10
10
  def start_server_in_fork(*args)
@@ -13,7 +13,7 @@ module RealWeb
13
13
  alias start_server start_server_in_fork
14
14
 
15
15
  def with_server_in_thread(*args, &block)
16
- InThreadServer.with_rackup(*args, &block)
16
+ ThreadServer.with_rackup(*args, &block)
17
17
  end
18
18
 
19
19
  def with_server_in_fork(*args, &block)
@@ -23,8 +23,8 @@ module RealWeb
23
23
 
24
24
  def spawn_server
25
25
  @pid ||= Process.fork do
26
- boot_rack_server do |webrick_server|
27
- trap(:TERM) { webrick_server.shutdown; exit!(0) }
26
+ boot_rack_server do |mongrel_server|
27
+ trap(:TERM) { mongrel_server.stop; exit!(0) }
28
28
  end
29
29
  end
30
30
  end
@@ -1,5 +1,4 @@
1
1
  require 'rack'
2
- require 'webrick'
3
2
  require 'stringio'
4
3
  require 'logger'
5
4
  require 'open-uri'
@@ -16,21 +15,23 @@ module RealWeb
16
15
  end
17
16
  end
18
17
 
19
- attr_reader :port
20
-
21
18
  def initialize(config_ru, pre_spawn_callback = nil, port_range = DEFAULT_PORT_RANGE)
22
19
  @config_ru, @pre_spawn_callback, @port_range = config_ru, pre_spawn_callback, port_range
23
20
  @running = false
24
21
  yield self if block_given?
25
22
  end
26
23
 
24
+ def port
25
+ @port ||= find_port
26
+ end
27
+
27
28
  def running?
28
29
  @running
29
30
  end
30
31
 
31
32
  def start
32
33
  return if running?
33
- find_port
34
+ port
34
35
  run_pre_spawn
35
36
  spawn_server
36
37
  at_exit { stop }
@@ -47,16 +48,16 @@ module RealWeb
47
48
  end
48
49
 
49
50
  def base_uri
50
- URI.parse("http://#{host}:#{@port}/")
51
+ URI.parse("http://#{host}:#{port}/")
51
52
  end
52
53
 
53
54
  protected
54
55
 
55
56
  def find_port
56
- return if @port
57
57
  begin
58
- @port = random_port
59
- end while system("lsof -i tcp:#{@port} > /dev/null")
58
+ port = random_port
59
+ end while system("lsof -i tcp:#{port} > /dev/null")
60
+ port
60
61
  end
61
62
 
62
63
  def random_port
@@ -75,15 +76,13 @@ module RealWeb
75
76
  def boot_rack_server(&block)
76
77
  begin
77
78
  rack_server = Rack::Server.new(
78
- :Port => @port,
79
+ :Port => port,
79
80
  :config => @config_ru,
80
- :server => 'webrick',
81
- :Logger => Logger.new(StringIO.new), # quiet webrick
82
- :AccessLog => [ StringIO.new, WEBrick::AccessLog::COMMON_LOG_FORMAT ]
81
+ :server => 'mongrel'
83
82
  )
84
- webrick_handler = rack_server.server
83
+ mongrel_handler = rack_server.server
85
84
  wrapped_app = rack_server.send(:wrapped_app)
86
- webrick_handler.run(wrapped_app, rack_server.options, &block)
85
+ mongrel_handler.run(wrapped_app, rack_server.options, &block)
87
86
  rescue
88
87
  $stderr.puts "Failed to start server"
89
88
  $stderr.puts $!.inspect
@@ -93,13 +92,14 @@ module RealWeb
93
92
  end
94
93
 
95
94
  def wait_for_server
96
- 10.times do
95
+ 20.times do
97
96
  begin
98
- sleep 0.5
99
97
  open(base_uri)
100
98
  return
101
- rescue Errno::ECONNREFUSED
102
- sleep 0.5
99
+ rescue OpenURI::HTTPError
100
+ return
101
+ rescue Errno::ECONNREFUSED => e
102
+ sleep 2
103
103
  end
104
104
  end
105
105
  abort "Unable to reach RealWeb server: Problem booting #{@config_ru}"
@@ -1,7 +1,7 @@
1
1
  require 'realweb/server'
2
2
 
3
3
  module RealWeb
4
- class InThreadServer < Server
4
+ class ThreadServer < Server
5
5
 
6
6
  def stop
7
7
  @thread[:kill_server].call
@@ -13,8 +13,8 @@ module RealWeb
13
13
 
14
14
  def spawn_server
15
15
  @thread ||= Thread.new do
16
- boot_rack_server do |webrick_server|
17
- Thread.current[:kill_server] = lambda { webrick_server.shutdown }
16
+ boot_rack_server do |mongrel_server|
17
+ Thread.current[:kill_server] = lambda { mongrel_server.stop }
18
18
  end
19
19
  end
20
20
  end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: realweb
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 23
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
- - 1
8
- - 6
9
- version: 0.1.6
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - Ben Burkert
@@ -16,23 +17,39 @@ autorequire:
16
17
  bindir: bin
17
18
  cert_chain: []
18
19
 
19
- date: 2010-06-02 00:00:00 -07:00
20
+ date: 2010-06-22 00:00:00 -07:00
20
21
  default_executable:
21
22
  dependencies:
22
23
  - !ruby/object:Gem::Dependency
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
+ version_requirements: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
27
  - - ">="
26
28
  - !ruby/object:Gem::Version
29
+ hash: 19
27
30
  segments:
28
31
  - 1
29
32
  - 1
30
33
  - 0
31
34
  version: 1.1.0
35
+ requirement: *id001
32
36
  name: rack
37
+ type: :runtime
33
38
  prerelease: false
39
+ - !ruby/object:Gem::Dependency
40
+ version_requirements: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 3
46
+ segments:
47
+ - 0
48
+ version: "0"
49
+ requirement: *id002
50
+ name: mongrel
34
51
  type: :runtime
35
- version_requirements: *id001
52
+ prerelease: false
36
53
  description: Easily runs a rack app for tests that hit web APIs
37
54
  email: cloud-engineering@engineyard.com
38
55
  executables: []
@@ -44,12 +61,12 @@ extra_rdoc_files:
44
61
  - LICENSE
45
62
  files:
46
63
  - lib/realweb/forking_server.rb
47
- - lib/realweb/in_thread_server.rb
48
64
  - lib/realweb/server.rb
65
+ - lib/realweb/thread_server.rb
49
66
  - lib/realweb.rb
50
67
  - README.rdoc
51
68
  - LICENSE
52
- has_rdoc: false
69
+ has_rdoc: true
53
70
  homepage: http://github.com/engineyard/realweb
54
71
  licenses: []
55
72
 
@@ -59,23 +76,27 @@ rdoc_options: []
59
76
  require_paths:
60
77
  - lib
61
78
  required_ruby_version: !ruby/object:Gem::Requirement
79
+ none: false
62
80
  requirements:
63
81
  - - ">="
64
82
  - !ruby/object:Gem::Version
83
+ hash: 3
65
84
  segments:
66
85
  - 0
67
86
  version: "0"
68
87
  required_rubygems_version: !ruby/object:Gem::Requirement
88
+ none: false
69
89
  requirements:
70
90
  - - ">="
71
91
  - !ruby/object:Gem::Version
92
+ hash: 3
72
93
  segments:
73
94
  - 0
74
95
  version: "0"
75
96
  requirements: []
76
97
 
77
98
  rubyforge_project:
78
- rubygems_version: 1.3.6
99
+ rubygems_version: 1.3.7
79
100
  signing_key:
80
101
  specification_version: 3
81
102
  summary: Easily runs a rack app for tests that hit web APIs