File: job_spec.rb

package info (click to toggle)
puppet 5.5.22-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 21,316 kB
  • sloc: ruby: 254,925; sh: 1,608; xml: 219; makefile: 153; sql: 103
file content (78 lines) | stat: -rw-r--r-- 2,124 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
require 'spec_helper'
require 'puppet/scheduler'

describe Puppet::Scheduler::Job do
  let(:run_interval) { 10 }
  let(:job) { described_class.new(run_interval) }

  it "has a minimum run interval of 0" do
    expect(Puppet::Scheduler::Job.new(-1).run_interval).to eq(0)
  end

  describe "when not run yet" do
    it "is ready" do
      expect(job.ready?(2)).to be
    end

    it "gives the time to next run as 0" do
      expect(job.interval_to_next_from(2)).to eq(0)
    end
  end

  describe "when run at least once" do
    let(:last_run) { 50 }

    before(:each) do
      job.run(last_run)
    end

    it "is ready when the time is greater than the last run plus the interval" do
      expect(job.ready?(last_run + run_interval + 1)).to be
    end

    it "is ready when the time is equal to the last run plus the interval" do
      expect(job.ready?(last_run + run_interval)).to be
    end

    it "is not ready when the time is less than the last run plus the interval" do
      expect(job.ready?(last_run + run_interval - 1)).not_to be
    end

    context "when calculating the next run" do
      it "returns the run interval if now == last run" do
        expect(job.interval_to_next_from(last_run)).to eq(run_interval)
      end

      it "when time is between the last and next runs gives the remaining portion of the run_interval" do
        time_since_last_run = 2
        now = last_run + time_since_last_run
        expect(job.interval_to_next_from(now)).to eq(run_interval - time_since_last_run)
      end

      it "when time is later than last+interval returns 0" do
        time_since_last_run = run_interval + 5
        now = last_run + time_since_last_run
        expect(job.interval_to_next_from(now)).to eq(0)
      end
    end
  end

  it "starts enabled" do
    expect(job.enabled?).to be
  end

  it "can be disabled" do
    job.disable
    expect(job.enabled?).not_to be
  end

  it "has the job instance as a parameter" do
    passed_job = nil
    job = Puppet::Scheduler::Job.new(run_interval) do |j|
      passed_job = j
    end
    job.run(5)

    expect(passed_job).to eql(job)
  end
end