Skip to content

Commit

Permalink
(PUP-12061) Add test cases for runinterval and splaylimit interaction
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
joshcooper committed Sep 26, 2024
1 parent f35b6d5 commit f1c2fb0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/puppet/daemon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ def run_event_loop
reparse_run = Puppet::Scheduler.create_job(Puppet[:filetimeout]) do
Puppet.settings.reparse_config_files
agent_run.run_interval = Puppet[:runinterval]
# Puppet[:splaylimit] defaults to Puppet[:runinterval] so if runinterval
# changes, but splaylimit doesn't, we'll still recalculate splay
agent_run.splay_limit = Puppet[:splay] ? Puppet[:splaylimit] : 0
if Puppet[:filetimeout] == 0
reparse_run.disable
Expand Down
24 changes: 24 additions & 0 deletions spec/unit/daemon_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,30 @@ def run_loop(jobs)

expect(agent_run.splay).to eq(0)
end

it "recalculates splay when runinterval is decreased" do
Puppet[:runinterval] = 60
daemon.start

Puppet[:runinterval] = Puppet[:runinterval] - 30
new_splay = agent_run.splay + 1
allow(agent_run).to receive(:rand).and_return(new_splay)
reparse_run.run(Time.now)

expect(agent_run.splay).to eq(new_splay)
end

it "recalculates splay when runinterval is increased" do
Puppet[:runinterval] = 60
daemon.start

Puppet[:runinterval] = Puppet[:runinterval] + 30
new_splay = agent_run.splay - 1
allow(agent_run).to receive(:rand).and_return(new_splay)
reparse_run.run(Time.now)

expect(agent_run.splay).to eq(new_splay)
end
end
end

Expand Down

0 comments on commit f1c2fb0

Please sign in to comment.