Skip to content

Commit f1c2fb0

Browse files
committed
(PUP-12061) Add test cases for runinterval and splaylimit interaction
Since splaylimit defaults to runinterval, changes to runinterval affect splay. Add tests covering cases where runinterval is increased and decreased. It's important to recalculate splay to reduce thundering herds. For example, if runinterval is changed from 30 mins to 60 mins, we want the compute a new slot in the 60 min interval to decrease server load.
1 parent f35b6d5 commit f1c2fb0

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

lib/puppet/daemon.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ def run_event_loop
173173
reparse_run = Puppet::Scheduler.create_job(Puppet[:filetimeout]) do
174174
Puppet.settings.reparse_config_files
175175
agent_run.run_interval = Puppet[:runinterval]
176+
# Puppet[:splaylimit] defaults to Puppet[:runinterval] so if runinterval
177+
# changes, but splaylimit doesn't, we'll still recalculate splay
176178
agent_run.splay_limit = Puppet[:splay] ? Puppet[:splaylimit] : 0
177179
if Puppet[:filetimeout] == 0
178180
reparse_run.disable

spec/unit/daemon_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,30 @@ def run_loop(jobs)
135135

136136
expect(agent_run.splay).to eq(0)
137137
end
138+
139+
it "recalculates splay when runinterval is decreased" do
140+
Puppet[:runinterval] = 60
141+
daemon.start
142+
143+
Puppet[:runinterval] = Puppet[:runinterval] - 30
144+
new_splay = agent_run.splay + 1
145+
allow(agent_run).to receive(:rand).and_return(new_splay)
146+
reparse_run.run(Time.now)
147+
148+
expect(agent_run.splay).to eq(new_splay)
149+
end
150+
151+
it "recalculates splay when runinterval is increased" do
152+
Puppet[:runinterval] = 60
153+
daemon.start
154+
155+
Puppet[:runinterval] = Puppet[:runinterval] + 30
156+
new_splay = agent_run.splay - 1
157+
allow(agent_run).to receive(:rand).and_return(new_splay)
158+
reparse_run.run(Time.now)
159+
160+
expect(agent_run.splay).to eq(new_splay)
161+
end
138162
end
139163
end
140164

0 commit comments

Comments
 (0)