test/ruby/abstract_server_spec.rb in passenger-2.2.15 vs test/ruby/abstract_server_spec.rb in passenger-3.0.0.pre1

- old
+ new

@@ -1,29 +1,10 @@ -require 'support/config' - +require File.expand_path(File.dirname(__FILE__) + '/spec_helper') require 'phusion_passenger/abstract_server' -include PhusionPassenger +module PhusionPassenger -shared_examples_for "an AbstractServer" do - it "doesn't crash if it's started and stopped multiple times" do - 3.times do - # Give the server some time to install the - # signal handlers. If we don't give it enough - # time, it will raise an ugly exception when - # we send it a signal. - sleep 0.1 - @server.stop - @server.start - end - end - - it "raises a ServerAlreadyStarted if the server is already started" do - lambda { @server.start }.should raise_error(AbstractServer::ServerAlreadyStarted) - end -end - describe AbstractServer do before :each do @server = AbstractServer.new end @@ -31,21 +12,50 @@ @server.stop if @server.started? end it "reseeds the pseudo-random number generator after forking off a process" do @server.send(:define_message_handler, :random_number, :handle_random_number) - @server.stub!(:handle_random_number).and_return do - @server.send(:client).write(rand.to_s) + @server.stub!(:handle_random_number).and_return do |channel| + channel.write(rand.to_s) end + first_num = second_num = nil + @server.start - @server.send(:server).write("random_number") - first_num = @server.send(:server).read + @server.connect do |channel| + channel.write("random_number") + first_num = channel.read + end @server.stop @server.start - @server.send(:server).write("random_number") - second_num = @server.send(:server).read + @server.connect do |channel| + channel.write("random_number") + second_num = channel.read + end first_num.should_not == second_num end + + specify "its socket is password protected" do + @server.ignore_password_errors = true + @server.send(:define_message_handler, :number, :handle_number) + @server.stub!(:handle_number).and_return do |channel| + channel.write(1) + end + + @server.start + @server.instance_variable_set(:"@password", "1234") + + begin + @server.connect do |channel| + channel.write("number") + result = channel.read + result.should be_nil + end + rescue SystemCallError, IOError + # Success. + end + end end + +end # module PhusionPassenger