GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: Phusion Passenger (mod_rails)
Homepage: http://www.modrails.com/
Clone URL: git://github.com/FooBarWidget/passenger.git
Click here to lend your support to: passenger and make a donation at www.pledgie.com !
passenger / test / spawn_manager_spec.rb
100644 108 lines (93 sloc) 2.693 kb
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
require 'support/config'
require 'passenger/spawn_manager'
require 'passenger/message_channel'
require 'passenger/utils'
require 'abstract_server_spec'
require 'minimal_spawner_spec'
require 'spawner_privilege_lowering_spec'
require 'spawner_error_handling_spec'
include Passenger
include Passenger::Utils
 
# TODO: test whether SpawnManager restarts FrameworkSpawner if it crashed
 
describe SpawnManager do
  before :each do
    @manager = SpawnManager.new
  end
  
  after :each do
    @manager.cleanup
  end
  
  describe "AbstractServer-like behavior" do
    before :each do
      @server = @manager
      @server.start
    end
    
    it_should_behave_like "AbstractServer"
  end
  
  it_should_behave_like "a minimal spawner"
  
  it "should not crash on spawning when running asynchronously" do
    app = @manager.spawn_application('stub/railsapp')
    app.close
  end
  
  it "should not crash on spawning when running synchronously" do
    a, b = UNIXSocket.pair
    pid = fork do
      begin
        a.close
        sleep(1) # Give @manager the chance to start.
        channel = MessageChannel.new(b)
        channel.write("spawn_application", "stub/minimal-railsapp", "true", "nobody")
        channel.read
        pid, listen_socket = channel.read
        channel.recv_io.close
        channel.close
      rescue Exception => e
        print_exception("child", e)
      ensure
        exit!
      end
    end
    b.close
    @manager.start_synchronously(a)
    a.close
    Process.waitpid(pid) rescue nil
  end
  
  it "should not crash upon spawning an application that doesn't specify its Rails version" do
    @manager.spawn_application('stub/railsapp-without-version-spec').close
  end
  
  it "should properly reload applications that do not specify a Rails version" do
    @manager.spawn_application('stub/railsapp-without-version-spec').close
    @manager.reload('stub/railsapp-without-version-spec')
    spawners = @manager.instance_eval { @spawners }
    spawners.should be_empty
  end
  
  def spawn_application
    @manager.spawn_application('stub/minimal-railsapp')
  end
end
 
describe SpawnManager do
  it_should_behave_like "handling errors in application initialization"
  it_should_behave_like "handling errors in framework initialization"
  
  def spawn_application(app_root)
    spawner = SpawnManager.new
    begin
      return spawner.spawn_application(app_root)
    ensure
      spawner.cleanup
    end
  end
  
  def load_nonexistant_framework
    Application.instance_eval do
      alias orig_detect_framework_version detect_framework_version
      def detect_framework_version(app_root)
        return "1.9.827"
      end
    end
    begin
      return spawn_application('stub/broken-railsapp4')
    ensure
      Application.instance_eval do
        alias detect_framework_version orig_detect_framework_version
      end
    end
  end
end