diff options
| author | Matt Robinson <matt@puppetlabs.com> | 2011-02-15 17:10:42 -0800 |
|---|---|---|
| committer | Matt Robinson <matt@puppetlabs.com> | 2011-02-16 15:13:31 -0800 |
| commit | 7cb884e44db412ed4cc19d9eb3e07d4b5b17f6b3 (patch) | |
| tree | 783ca4c23a65eef0201e08925221f63458a0c31c /spec | |
| parent | 9b7b0f3ad87abc3a6fbb7ad128e942571cd3e71a (diff) | |
(#6346) Move the trap calls onto Signal so they're easier to stub
Once you stub signal traps in tests, you can hit ctrl+c in the middle of
a spec run and it will stop the run instead of puppet catching the
SIGINT.
I had trouble easily tracking down all the places to stub traps when the
trap was being called as a private method on applications and daemons,
but calling trap on Signal is equivalent since Kernel calls Signal.trap
and Object mixes in Kernel to provide trap as a private method on all
objects.
A bigger solution would be to refactor everywhere we call trap into a
method that's called consistently since right now we sprinkle SIGINT and
SIGTERM trap handling over applications and daemons in inconsistent
ways, returning different error codes and using different messages.
I've captured this info in ticket #6345.
Reviewed-by: Jacob Helwig <jacob@puppetlabs.com>
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/spec_helper.rb | 1 | ||||
| -rwxr-xr-x | spec/unit/application/agent_spec.rb | 6 | ||||
| -rwxr-xr-x | spec/unit/application/apply_spec.rb | 3 | ||||
| -rw-r--r-- | spec/unit/application/filebucket_spec.rb | 2 | ||||
| -rwxr-xr-x | spec/unit/application/queue_spec.rb | 6 | ||||
| -rwxr-xr-x | spec/unit/daemon_spec.rb | 6 |
6 files changed, 6 insertions, 18 deletions
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ed4e826c9..a374fb008 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -64,6 +64,7 @@ RSpec.configure do |config| # these globals are set by Application $puppet_application_mode = nil $puppet_application_name = nil + Signal.stubs(:trap) # Set the confdir and vardir to gibberish so that tests # have to be correctly mocked. diff --git a/spec/unit/application/agent_spec.rb b/spec/unit/application/agent_spec.rb index ff504eedf..9fc7879c9 100755 --- a/spec/unit/application/agent_spec.rb +++ b/spec/unit/application/agent_spec.rb @@ -50,12 +50,8 @@ describe Puppet::Application::Agent do end describe "in preinit" do - before :each do - @puppetd.stubs(:trap) - end - it "should catch INT" do - @puppetd.expects(:trap).with { |arg,block| arg == :INT } + Signal.expects(:trap).with { |arg,block| arg == :INT } @puppetd.preinit end diff --git a/spec/unit/application/apply_spec.rb b/spec/unit/application/apply_spec.rb index 4e1744206..ceba4a333 100755 --- a/spec/unit/application/apply_spec.rb +++ b/spec/unit/application/apply_spec.rb @@ -52,7 +52,6 @@ describe Puppet::Application::Apply do before :each do Puppet::Log.stubs(:newdestination) - Puppet.stubs(:trap) Puppet::Log.stubs(:level=) Puppet.stubs(:parse_config) Puppet::FileBucket::Dipper.stubs(:new) @@ -78,7 +77,7 @@ describe Puppet::Application::Apply do end it "should set INT trap" do - @apply.expects(:trap).with(:INT) + Signal.expects(:trap).with(:INT) @apply.setup end diff --git a/spec/unit/application/filebucket_spec.rb b/spec/unit/application/filebucket_spec.rb index e6272f179..95135c7eb 100644 --- a/spec/unit/application/filebucket_spec.rb +++ b/spec/unit/application/filebucket_spec.rb @@ -56,7 +56,7 @@ describe Puppet::Application::Filebucket do end it "should trap INT" do - @filebucket.expects(:trap).with(:INT) + Signal.expects(:trap).with(:INT) @filebucket.setup end diff --git a/spec/unit/application/queue_spec.rb b/spec/unit/application/queue_spec.rb index bd0d53ab1..f8ebbd0b4 100755 --- a/spec/unit/application/queue_spec.rb +++ b/spec/unit/application/queue_spec.rb @@ -29,12 +29,8 @@ describe Puppet::Application::Queue do end describe "in preinit" do - before :each do - @queue.stubs(:trap) - end - it "should catch INT" do - @queue.expects(:trap).with { |arg,block| arg == :INT } + Signal.expects(:trap).with { |arg,block| arg == :INT } @queue.preinit end diff --git a/spec/unit/daemon_spec.rb b/spec/unit/daemon_spec.rb index e24db7881..39592b7c9 100755 --- a/spec/unit/daemon_spec.rb +++ b/spec/unit/daemon_spec.rb @@ -29,13 +29,9 @@ describe Puppet::Daemon do end describe "when setting signal traps" do - before do - @daemon.stubs(:trap) - end - {:INT => :stop, :TERM => :stop, :HUP => :restart, :USR1 => :reload, :USR2 => :reopen_logs}.each do |signal, method| it "should log and call #{method} when it receives #{signal}" do - @daemon.expects(:trap).with(signal).yields + Signal.expects(:trap).with(signal).yields Puppet.expects(:notice) |
