summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorRick Bradley <rick@rickbradley.com>2008-03-12 22:26:12 -0500
committerLuke Kanies <luke@madstop.com>2008-04-11 13:10:33 -0500
commite86fde2facafd56ee12d7e748b1c8cad916253bf (patch)
tree2d7595566a3f36b5596430c492da3def1b507951 /spec
parentc2f8c69af368a8ba496da4ef0023ac5f0885e3c0 (diff)
This is the first version where mongrel and webrick are reliably startable and stoppable via Puppet::Network::Server.
Added a network/server integration spec, testing startup, shutdown, reachability, and collision of webrick and mongrel servers in the new network code. Converted Puppet::Network::HTTP::Handler class to a module, as mongrel Handler should be subclassed; converting subclasses to include the module instead. Mongrel will actually stop if you .stop it, graceful_shutdown didn't seem quite so reliable. Webrick requires running in its own Thread to avoid hanging the entire process; this requires introduction of a Mutex to make things safe. We're only supporting the REST protocol. Made this explicit. Fixed http server setup args, w/ specs, ah the glory of integration testing.
Diffstat (limited to 'spec')
-rw-r--r--spec/integration/network/server.rb85
-rw-r--r--spec/unit/network/http/mongrel.rb4
-rw-r--r--spec/unit/network/server.rb53
3 files changed, 131 insertions, 11 deletions
diff --git a/spec/integration/network/server.rb b/spec/integration/network/server.rb
new file mode 100644
index 000000000..932161b08
--- /dev/null
+++ b/spec/integration/network/server.rb
@@ -0,0 +1,85 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+require 'puppet/network/server'
+require 'socket'
+
+describe Puppet::Network::Server do
+ describe "when using webrick" do
+ before :each do
+ Puppet[:servertype] = 'webrick'
+ @params = { :address => "127.0.0.1", :port => 34343, :handlers => [ :node ] }
+ end
+
+ describe "before listening" do
+ it "should not be reachable at the specified address and port" do
+ lambda { TCPSocket.new('127.0.0.1', 34343) }.should raise_error
+ end
+ end
+
+ describe "when listening" do
+ it "should be reachable on the specified address and port" do
+ @server = Puppet::Network::Server.new(@params.merge(:port => 34343))
+ @server.listen
+ lambda { TCPSocket.new('127.0.0.1', 34343) }.should_not raise_error
+ end
+
+ it "should not allow multiple servers to listen on the same address and port" do
+ @server = Puppet::Network::Server.new(@params.merge(:port => 34343))
+ @server.listen
+ @server2 = Puppet::Network::Server.new(@params.merge(:port => 34343))
+ lambda { @server2.listen }.should raise_error
+ end
+
+ after :each do
+ @server.unlisten if @server.listening?
+ end
+ end
+
+ describe "after unlistening" do
+ it "should not be reachable on the port and address assigned" do
+ @server = Puppet::Network::Server.new(@params.merge(:port => 34343))
+ @server.listen
+ @server.unlisten
+ lambda { TCPSocket.new('127.0.0.1', 34343) }.should raise_error(Errno::ECONNREFUSED)
+ end
+ end
+ end
+
+ describe "when using mongrel" do
+ before :each do
+ Puppet[:servertype] = 'mongrel'
+ @params = { :address => "127.0.0.1", :port => 34346, :handlers => [ :node ] }
+ @server = Puppet::Network::Server.new(@params)
+ end
+
+ describe "before listening" do
+ it "should not be reachable at the specified address and port" do
+ lambda { TCPSocket.new('127.0.0.1', 34346) }.should raise_error(Errno::ECONNREFUSED)
+ end
+ end
+
+ describe "when listening" do
+ it "should be reachable on the specified address and port" do
+ @server.listen
+ lambda { TCPSocket.new('127.0.0.1', 34346) }.should_not raise_error
+ end
+
+ it "should not allow multiple servers to listen on the same address and port" do
+ @server.listen
+ @server2 = Puppet::Network::Server.new(@params)
+ lambda { @server2.listen }.should raise_error
+ end
+ end
+
+ describe "after unlistening" do
+ it "should not be reachable on the port and address assigned" do
+ @server.listen
+ @server.unlisten
+ lambda { TCPSocket.new('127.0.0.1', 34346) }.should raise_error(Errno::ECONNREFUSED)
+ end
+ end
+
+ after :each do
+ @server.unlisten if @server.listening?
+ end
+ end
+end \ No newline at end of file
diff --git a/spec/unit/network/http/mongrel.rb b/spec/unit/network/http/mongrel.rb
index a837c9daa..cd23ed9e1 100644
--- a/spec/unit/network/http/mongrel.rb
+++ b/spec/unit/network/http/mongrel.rb
@@ -106,13 +106,13 @@ describe Puppet::Network::HTTP::Mongrel, "when turning off listening" do
it "should order mongrel server to stop" do
@server.listen(@listen_params)
- @mock_mongrel.expects(:graceful_shutdown)
+ @mock_mongrel.expects(:stop)
@server.unlisten
end
it "should not be listening" do
@server.listen(@listen_params)
- @mock_mongrel.stubs(:graceful_shutdown)
+ @mock_mongrel.stubs(:stop)
@server.unlisten
@server.should_not be_listening
end
diff --git a/spec/unit/network/server.rb b/spec/unit/network/server.rb
index 3e29807ad..e4afbc3c2 100644
--- a/spec/unit/network/server.rb
+++ b/spec/unit/network/server.rb
@@ -161,8 +161,12 @@ describe Puppet::Network::Server, "in general" do
Proc.new { @server2.unregister(:bar) }.should raise_error(ArgumentError)
end
- it "should provide a means of determining which style of service is being offered to clients" do
- @server.protocols.should == []
+ it "should provide a means of determining which protocols are in use" do
+ @server.should respond_to(:protocols)
+ end
+
+ it "should only support the REST protocol at this time" do
+ @server.protocols.should == [ :rest ]
end
it "should provide a means of determining the listening address" do
@@ -230,23 +234,54 @@ describe Puppet::Network::Server, "when listening is being turned on" do
@mock_http_server_class = mock('http server class')
Puppet::Network::HTTP.stubs(:server_class_by_type).returns(@mock_http_server_class)
Puppet.stubs(:[]).with(:servertype).returns(:suparserver)
- @server = Puppet::Network::Server.new(:address => "127.0.0.1", :port => 31337)
+ @server = Puppet::Network::Server.new(:address => "127.0.0.1", :port => 31337, :handlers => [:node])
@mock_http_server = mock('http server')
@mock_http_server.stubs(:listen)
end
- it "should fetch an instance of an HTTP server when listening is turned on" do
- mock_http_server_class = mock('http server class')
- mock_http_server_class.expects(:new).returns(@mock_http_server)
- @server.expects(:http_server_class).returns(mock_http_server_class)
+ it "should fetch an instance of an HTTP server" do
+ @server.stubs(:http_server_class).returns(@mock_http_server_class)
+ @mock_http_server_class.expects(:new).returns(@mock_http_server)
@server.listen
end
- it "should cause the HTTP server to listen when listening is turned on" do
+ it "should cause the HTTP server to listen" do
+ @server.stubs(:http_server).returns(@mock_http_server)
@mock_http_server.expects(:listen)
- @server.expects(:http_server).returns(@mock_http_server)
@server.listen
end
+
+ it "should pass the listening address to the HTTP server" do
+ @server.stubs(:http_server).returns(@mock_http_server)
+ @mock_http_server.expects(:listen).with do |args|
+ args[:address] == '127.0.0.1'
+ end
+ @server.listen
+ end
+
+ it "should pass the listening port to the HTTP server" do
+ @server.stubs(:http_server).returns(@mock_http_server)
+ @mock_http_server.expects(:listen).with do |args|
+ args[:port] == 31337
+ end
+ @server.listen
+ end
+
+ it "should pass a list of handlers to the HTTP server" do
+ @server.stubs(:http_server).returns(@mock_http_server)
+ @mock_http_server.expects(:listen).with do |args|
+ args[:handlers] == [ :node ]
+ end
+ @server.listen
+ end
+
+ it "should pass a list of protocols to the HTTP server" do
+ @server.stubs(:http_server).returns(@mock_http_server)
+ @mock_http_server.expects(:listen).with do |args|
+ args[:protocols] == [ :rest ]
+ end
+ @server.listen
+ end
end
describe Puppet::Network::Server, "when listening is being turned off" do