diff options
-rw-r--r-- | lib/facter/kernelrelease.rb | 2 | ||||
-rw-r--r-- | lib/facter/puppetversion.rb | 2 | ||||
-rw-r--r-- | lib/facter/util/resolution.rb | 11 | ||||
-rwxr-xr-x | spec/unit/util/collection.rb | 6 | ||||
-rwxr-xr-x | spec/unit/util/resolution.rb | 18 |
5 files changed, 30 insertions, 9 deletions
diff --git a/lib/facter/kernelrelease.rb b/lib/facter/kernelrelease.rb index 07b65b5..0f8a643 100644 --- a/lib/facter/kernelrelease.rb +++ b/lib/facter/kernelrelease.rb @@ -2,7 +2,7 @@ Facter.add(:kernelrelease) do setcode 'uname -r' end -Facter.add(:kernelrelease, :limit => 5) do +Facter.add(:kernelrelease, :timeout => 5) do confine :kernel => :aix setcode 'oslevel -s' end diff --git a/lib/facter/puppetversion.rb b/lib/facter/puppetversion.rb index d16250c..16510c8 100644 --- a/lib/facter/puppetversion.rb +++ b/lib/facter/puppetversion.rb @@ -1,4 +1,4 @@ -Facter.add(:puppetversion, :limit => 1.5) do +Facter.add(:puppetversion, :timeout => 1.5) do setcode { begin require 'puppet' diff --git a/lib/facter/util/resolution.rb b/lib/facter/util/resolution.rb index bc9fdec..cc8c842 100644 --- a/lib/facter/util/resolution.rb +++ b/lib/facter/util/resolution.rb @@ -8,7 +8,7 @@ require 'facter/util/confine' require 'timeout' class Facter::Util::Resolution - attr_accessor :interpreter, :code, :name, :limit + attr_accessor :interpreter, :code, :name, :timeout def self.have_which if ! defined?(@have_which) or @have_which.nil? @@ -62,7 +62,7 @@ class Facter::Util::Resolution @name = name @confines = [] @value = nil - @limit = 0.5 + @timeout = 0.5 end # Return the number of confines. @@ -70,6 +70,13 @@ class Facter::Util::Resolution @confines.length end + # We need this as a getter for 'timeout', because some versions + # of ruby seem to already have a 'timeout' method and we can't + # seem to override the instance methods, somehow. + def limit + @timeout + end + # Set our code for returning a value. def setcode(string = nil, interp = nil, &block) if string diff --git a/spec/unit/util/collection.rb b/spec/unit/util/collection.rb index a526ed3..7585a52 100755 --- a/spec/unit/util/collection.rb +++ b/spec/unit/util/collection.rb @@ -64,7 +64,7 @@ describe Facter::Util::Collection do resolve = Facter::Util::Resolution.new(:myname) {} fact.expects(:add).returns resolve - @coll.add(:myname, :limit => "myval") {} + @coll.add(:myname, :timeout => "myval") {} end it "should not pass fact-specific options to resolutions" do @@ -75,9 +75,9 @@ describe Facter::Util::Collection do fact.expects(:add).returns resolve fact.expects(:ldapname=).with("foo") - resolve.expects(:limit=).with("myval") + resolve.expects(:timeout=).with("myval") - @coll.add(:myname, :limit => "myval", :ldapname => "foo") {} + @coll.add(:myname, :timeout => "myval", :ldapname => "foo") {} end it "should fail if invalid options are provided" do diff --git a/spec/unit/util/resolution.rb b/spec/unit/util/resolution.rb index 462bf17..617b4dc 100755 --- a/spec/unit/util/resolution.rb +++ b/spec/unit/util/resolution.rb @@ -18,13 +18,19 @@ describe Facter::Util::Resolution do end it "should support a timeout value" do - Facter::Util::Resolution.new("yay").should respond_to(:limit=) + Facter::Util::Resolution.new("yay").should respond_to(:timeout=) end it "should default to a timeout of 0.5 seconds" do Facter::Util::Resolution.new("yay").limit.should == 0.5 end + it "should provide a 'limit' method that returns the timeout" do + res = Facter::Util::Resolution.new("yay") + res.timeout = "testing" + res.limit.should == "testing" + end + describe "when setting the code" do before do @resolve = Facter::Util::Resolution.new("yay") @@ -91,9 +97,17 @@ describe Facter::Util::Resolution do @resolve.value.should be_nil end + it "should use its limit method to determine the timeout, to avoid conflict when a 'timeout' method exists for some other reason" do + @resolve.expects(:timeout).never + @resolve.expects(:limit).returns "foo" + Timeout.expects(:timeout).with("foo") + + @resolve.value + end + it "should timeout after the provided timeout" do @resolve.expects(:warn) - @resolve.limit = 0.1 + @resolve.timeout = 0.1 @resolve.setcode { sleep 2; raise "This is a test" } @resolve.value.should be_nil |