File: spawn_manager_spec.rb

package info (click to toggle)
ruby-passenger 3.0.13debian-1%2Bdeb7u2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 15,920 kB
  • sloc: cpp: 99,104; ruby: 18,098; ansic: 9,846; sh: 8,632; python: 141; makefile: 30
file content (134 lines) | stat: -rw-r--r-- 3,871 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
require 'phusion_passenger/app_process'
require 'phusion_passenger/spawn_manager'

require 'ruby/shared/spawners/spawner_spec'
require 'ruby/shared/spawners/reload_single_spec'
require 'ruby/shared/spawners/reload_all_spec'
require 'ruby/shared/spawners/classic_rails/spawner_spec'
require 'ruby/shared/spawners/classic_rails/lack_of_rails_gem_version_spec'

# TODO: test whether SpawnManager restarts the subspawner if it crashed

module PhusionPassenger

describe SpawnManager do
	include SpawnerSpecHelper
	
	after :each do
		@spawner.cleanup if @spawner
	end
	
	describe_rails_versions('<= 2.3') do
		def spawner
			@spawner ||= SpawnManager.new
		end
		
		def spawn_stub_application(stub, extra_options = {})
			default_options = {
				"app_root"     => stub.app_root,
				"spawn_method" => @spawn_method,
				"default_user" => CONFIG['default_user']
			}
			options = default_options.merge(extra_options)
			app = spawner.spawn_application(options)
			return register_app(app)
		end
		
		def spawn_some_application(extra_options = {})
			stub = register_stub(RailsStub.new("#{rails_version}/empty"))
			yield stub if block_given?
			return spawn_stub_application(stub, extra_options)
		end
		
		def use_some_stub
			RailsStub.use("#{rails_version}/empty") do |stub|
				yield stub
			end
		end
		
		# def load_nonexistant_framework(extra_options = {})
		# 	# Prevent detect_framework_version from raising VersionNotFound
		# 	AppProcess.should_receive(:detect_framework_version).
		# 		at_least(:once).
		# 		with(an_instance_of(String)).
		# 		and_return("1.9.827")
		# 	stub = register_stub(RailsStub.new("#{rails_version}/empty"))
		# 	File.write(stub.environment_rb) do |content|
		# 		content.sub(/^RAILS_GEM_VERSION = .*$/, "RAILS_GEM_VERSION = '1.9.827'")
		# 	end
		# 	return spawn_stub_application(stub, extra_options)
		# end
		
		describe "smart spawning" do
			before :each do
				@spawn_method = "smart"
			end
			
			it_should_behave_like "a spawner"
			it_should_behave_like "a Rails spawner"
			it_should_behave_like "a Rails spawner that supports #reload(app_group_name)"
			it_should_behave_like "a Rails spawner that supports #reload()"
			include_shared_example_group "a Rails app that lacks RAILS_GEM_VERSION"
		end
		
		describe "smart-lv2 spawning" do
			before :each do
				@spawn_method = "smart-lv2"
			end
			
			it_should_behave_like "a spawner"
			it_should_behave_like "a Rails spawner"
			it_should_behave_like "a Rails spawner that supports #reload(app_group_name)"
			it_should_behave_like "a Rails spawner that supports #reload()"
			include_shared_example_group "a Rails app that lacks RAILS_GEM_VERSION"
		end
		
		describe "conservative spawning" do
			before :each do
				@spawn_method = "conservative"
			end
			
			it_should_behave_like "a spawner"
			it_should_behave_like "a Rails spawner"
			it_should_behave_like "a Rails spawner that supports #reload()"
			include_shared_example_group "a Rails app that lacks RAILS_GEM_VERSION"
		end
	end
	
	describe "Rack" do
		def spawn_some_application(extra_options = {})
			stub = register_stub(RackStub.new("rack"))
			yield stub if block_given?
			
			default_options = {
				"app_root"     => stub.app_root,
				"app_type"     => "rack",
				"spawn_method" => @spawn_method,
				"default_user" => CONFIG['default_user']
			}
			options = default_options.merge(extra_options)
			@spawner ||= SpawnManager.new
			app = @spawner.spawn_application(options)
			return register_app(app)
		end
		
		describe "smart spawning" do
			before :each do
				@spawn_method = "smart"
			end
			
			it_should_behave_like "a spawner"
		end
		
		describe "conservative spawning" do
			before :each do
				@spawn_method = "conservative"
			end
			
			it_should_behave_like "a spawner"
		end
	end
end

end # module PhusionPassenger