File tree Expand file tree Collapse file tree 3 files changed +22
-0
lines changed Expand file tree Collapse file tree 3 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -161,6 +161,7 @@ def run_event_loop
161161 reparse_run = Puppet ::Scheduler . create_job ( Puppet [ :filetimeout ] ) do
162162 Puppet . settings . reparse_config_files
163163 agent_run . run_interval = Puppet [ :runinterval ]
164+ agent_run . splay_limit = Puppet [ :splaylimit ] if Puppet [ :splay ]
164165 if Puppet [ :filetimeout ] == 0
165166 reparse_run . disable
166167 else
Original file line number Diff line number Diff line change @@ -23,6 +23,15 @@ def ready?(time)
2323 end
2424 end
2525
26+ # Recalculates splay.
27+ #
28+ # @param splay_limit [Integer] the maximum time (in seconds) to delay before an agent's first run.
29+ # @return @splay [Integer] a random integer less than or equal to the splay limit that represents the seconds to
30+ # delay before next agent run.
31+ def splay_limit = ( splay_limit )
32+ @splay = calculate_splay ( splay_limit )
33+ end
34+
2635 private
2736
2837 def calculate_splay ( limit )
Original file line number Diff line number Diff line change @@ -86,6 +86,18 @@ def run_loop(jobs)
8686 daemon . start
8787 expect ( scheduler . jobs [ 0 ] ) . not_to be_enabled
8888 end
89+
90+ it "recalculates splay if splaylimit changes" do
91+ # Set file timeout so the daemon reparses
92+ Puppet [ :filetimeout ] = 1
93+ Puppet [ :splay ] = true
94+ allow ( agent ) . to receive ( :run )
95+ daemon . start
96+ first_splay = scheduler . jobs [ 1 ] . splay
97+ allow ( Kernel ) . to receive ( :rand ) . and_return ( 1738 )
98+ scheduler . jobs [ 0 ] . run ( Time . now )
99+ expect ( scheduler . jobs [ 1 ] . splay ) . to_not eq ( first_splay )
100+ end
89101 end
90102
91103 describe "when stopping" do
You can’t perform that action at this time.
0 commit comments