From f1c2fb06c007d107fd396104a0455714bdec1742 Mon Sep 17 00:00:00 2001 From: Josh Cooper Date: Thu, 26 Sep 2024 15:07:45 -0700 Subject: [PATCH] (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. --- lib/puppet/daemon.rb | 2 ++ spec/unit/daemon_spec.rb | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/lib/puppet/daemon.rb b/lib/puppet/daemon.rb index 91267585e3c..bf743105a81 100644 --- a/lib/puppet/daemon.rb +++ b/lib/puppet/daemon.rb @@ -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 diff --git a/spec/unit/daemon_spec.rb b/spec/unit/daemon_spec.rb index 54f3887c085..89167ba3dd9 100644 --- a/spec/unit/daemon_spec.rb +++ b/spec/unit/daemon_spec.rb @@ -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