Ensure os_workers_large fact returns an Integer

Also make sure it returns at least 1.

Closes-bug: #1738082
Change-Id: I6b48842862a6860215ff774f73ae7224a34545e7
(cherry picked from commit e5005dc4ff)
This commit is contained in:
Mathieu Gagné 2017-12-13 16:29:56 -05:00 committed by Mathieu Gagné
parent 9ebb0e395f
commit 127cc458ef
5 changed files with 107 additions and 1 deletions

View File

@ -45,6 +45,6 @@ Facter.add(:os_workers_large) do
has_weight 100
setcode do
processors = Facter.value('processorcount')
[ (processors.to_i / 2) ]
[ (processors.to_i / 2), 1 ].max
end
end

View File

@ -0,0 +1,5 @@
---
fixes:
- |
The os_workers_large fact now returns an Integer instead of a Tuple.
It will also return a minimum value of 1.

View File

@ -0,0 +1,27 @@
require 'spec_helper'
describe 'os_workers_large' do
before { Facter.clear }
after { Facter.clear }
context 'with processorcount=1' do
before do
Facter.fact(:processorcount).stubs(:value).returns(1)
end
it 'returns a minimum of 1' do
expect(Facter.fact(:os_workers_large).value).to eq(1)
end
end
context 'with processorcount=8' do
before do
Facter.fact(:processorcount).stubs(:value).returns(8)
end
it 'returns processorcount/2' do
expect(Facter.fact(:os_workers_large).value).to eq(4)
end
end
end

View File

@ -0,0 +1,37 @@
require 'spec_helper'
describe 'os_workers_small' do
before { Facter.clear }
after { Facter.clear }
context 'with processorcount=1' do
before do
Facter.fact(:processorcount).stubs(:value).returns(1)
end
it 'returns a minimum of 2' do
expect(Facter.fact(:os_workers_small).value).to eq(2)
end
end
context 'with processorcount=16' do
before do
Facter.fact(:processorcount).stubs(:value).returns(16)
end
it 'returns processorcount/4' do
expect(Facter.fact(:os_workers_small).value).to eq(4)
end
end
context 'with processorcount=32' do
before do
Facter.fact(:processorcount).stubs(:value).returns(32)
end
it 'returns a maximum of 8' do
expect(Facter.fact(:os_workers_small).value).to eq(8)
end
end
end

View File

@ -0,0 +1,37 @@
require 'spec_helper'
describe 'os_workers' do
before { Facter.clear }
after { Facter.clear }
context 'with processorcount=1' do
before do
Facter.fact(:processorcount).stubs(:value).returns(1)
end
it 'returns a minimum of 2' do
expect(Facter.fact(:os_workers).value).to eq(2)
end
end
context 'with processorcount=8' do
before do
Facter.fact(:processorcount).stubs(:value).returns(8)
end
it 'returns processorcount/2' do
expect(Facter.fact(:os_workers).value).to eq(4)
end
end
context 'with processorcount=32' do
before do
Facter.fact(:processorcount).stubs(:value).returns(32)
end
it 'returns a maximum of 12' do
expect(Facter.fact(:os_workers).value).to eq(12)
end
end
end