Are you sure this fixes the problem?

I thought I'd built splay so that it slept on every run, which would  
have this sleeping on the first run but not others.

It *does* make more sense to have the splay happen once, at startup,  
but I just want to make sure that's what's actually happening here.

On Sep 19, 2008, at 6:00 PM, Andrew Shafer wrote:

>
> Issue 1491
>
> Signed-off-by: Andrew Shafer <[EMAIL PROTECTED]>
> ---
> lib/puppet/network/client/master.rb |   16 ++++++------
> spec/unit/network/client/master.rb  |   42 ++++++++++++++++++++++++++ 
> +++++++++
> 2 files changed, 50 insertions(+), 8 deletions(-)
>
> diff --git a/lib/puppet/network/client/master.rb b/lib/puppet/ 
> network/client/master.rb
> index 6f8e277..5e9422b 100644
> --- a/lib/puppet/network/client/master.rb
> +++ b/lib/puppet/network/client/master.rb
> @@ -199,6 +199,7 @@ class Puppet::Network::Client::Master <  
> Puppet::Network::Client
>
>         self.class.instance = self
>         @running = false
> +        @splayed = false
>     end
>
>     # Mark that we should restart.  The Puppet module checks whether  
> we're running,
> @@ -478,20 +479,19 @@ class Puppet::Network::Client::Master <  
> Puppet::Network::Client
>         @lockfile
>     end
>
> +    def splayed?
> +        @splayed
> +    end
> +
>     # Sleep when splay is enabled; else just return.
>     def splay
>         return unless Puppet[:splay]
> +        return if splayed?
>
> -        limit = Integer(Puppet[:splaylimit])
> -
> -        # Pick a splay time and then cache it.
> -        unless time = Puppet::Util::Storage.cache(:configuration) 
> [:splay_time]
> -            time = rand(limit)
> -            Puppet::Util::Storage.cache(:configuration) 
> [:splay_time] = time
> -        end
> -
> +        time = rand(Integer(Puppet[:splaylimit]))
>         Puppet.info "Sleeping for %s seconds (splay is enabled)" %  
> time
>         sleep(time)
> +        @splayed = true
>     end
>
>     private
> diff --git a/spec/unit/network/client/master.rb b/spec/unit/network/ 
> client/master.rb
> index 754fd05..f55ba31 100755
> --- a/spec/unit/network/client/master.rb
> +++ b/spec/unit/network/client/master.rb
> @@ -397,4 +397,46 @@ describe Puppet::Network::Client::Master, "  
> when using the cached catalog" do
>
>         @client.catalog.should equal(ral_config)
>     end
> +
> +    describe "when calling splay" do
> +        it "should do nothing if splay is not enabled" do
> +            Puppet.stubs(:[]).with(:splay).returns(false)
> +            @client.expects(:rand).never
> +            @client.send(:splay)
> +        end
> +
> +        describe "when splay is enabled" do
> +            before do
> +                Puppet.stubs(:[]).with(:splay).returns(true)
> +                Puppet.stubs(:[]).with(:splaylimit).returns(42)
> +            end
> +
> +            it "should sleep for a random time" do
> +                @client.expects(:rand).with(42).returns(42)
> +                @client.expects(:sleep).with(42)
> +                @client.send(:splay)
> +            end
> +
> +            it "should inform that it is splayed" do
> +                @client.stubs(:rand).with(42).returns(42)
> +                @client.stubs(:sleep).with(42)
> +                Puppet.expects(:info)
> +                @client.send(:splay)
> +            end
> +
> +            it "should set splay = true" do
> +                @client.stubs(:rand).with(42).returns(42)
> +                @client.stubs(:sleep).with(42)
> +                @client.send(:splay)
> +                @client.send(:splayed?).should == true
> +            end
> +
> +            it "should do nothing if already splayed" do
> +                 
> @client.stubs(:rand).with(42).returns(42).at_most_once
> +                @client.stubs(:sleep).with(42).at_most_once
> +                @client.send(:splay)
> +                @client.send(:splay)
> +            end
> +        end
> +    end
> end
> -- 
> 1.5.3.7
>
>
> >


-- 
Kai's Example Dilemma:
     A good analogy is like a diagonal frog.
---------------------------------------------------------------------
Luke Kanies | http://reductivelabs.com | http://madstop.com


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to