realweb 0.2.0 → 0.2.1

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