Skip to content

Commit 89bda96

Browse files
Updating test cases
Signed-off-by: paragchak-sumo <[email protected]>
1 parent be30d05 commit 89bda96

File tree

5 files changed

+29
-0
lines changed

5 files changed

+29
-0
lines changed

spec/acceptance/00_backend_spec.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ class { 'sensu::backend':
3030
it { should be_enabled }
3131
it { should be_running }
3232
end
33+
it 'waits for backend to be healthy' do
34+
expect(wait_for_backend(node)).to eq(true)
35+
end
3336
describe package('sensu-go-agent'), :node => node do
3437
it { should_not be_installed }
3538
end

spec/acceptance/01_agent_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ class { 'sensu::agent':
7777
it { should be_listening }
7878
end
7979

80+
it 'waits for backend before inspecting entity' do
81+
expect(wait_for_backend(backend)).to eq(true)
82+
end
83+
8084
it 'should create an entity' do
8185
on backend, "sensuctl entity info sensu-agent --format json" do
8286
data = JSON.parse(stdout)

spec/acceptance/03_no_ssl_spec.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ class { 'sensu::backend': }
3939
describe command('sensuctl entity list'), :node => backend do
4040
its(:exit_status) { should eq 0 }
4141
end
42+
it 'waits for backend to be healthy' do
43+
expect(wait_for_backend(backend)).to eq(true)
44+
end
4245
end
4346

4447
context 'agent' do

spec/acceptance/07_cli_spec.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class { 'sensu::backend': }
4141
end
4242

4343
it 'should have working sensuctl' do
44+
expect(wait_for_backend(backend)).to eq(true)
4445
exit_code = on(node, 'sensuctl cluster health').exit_code
4546
expect(exit_code).to eq(0)
4647
end
@@ -80,6 +81,7 @@ class { 'sensu::backend': }
8081
end
8182

8283
it 'should have working sensuctl' do
84+
expect(wait_for_backend(backend)).to eq(true)
8385
exit_code = on(node, 'sensuctl cluster health').exit_code
8486
expect(exit_code).to eq(0)
8587
end
@@ -121,6 +123,7 @@ class { 'sensu::backend': }
121123
end
122124

123125
it 'should have working sensuctl' do
126+
expect(wait_for_backend(backend)).to eq(true)
124127
exit_code = on(node, 'sensuctl cluster health').exit_code
125128
expect(exit_code).to eq(0)
126129
end

spec/spec_helper_acceptance.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,22 @@
1111
collection = ENV['BEAKER_PUPPET_COLLECTION'] || 'puppet6'
1212
project_dir = File.absolute_path(File.join(File.dirname(__FILE__), '..'))
1313

14+
# Wait helpers to accommodate slower startup on newer Sensu versions
15+
def wait_for_command(host, command, max_retries = 30, sleep_seconds = 5)
16+
retries = 0
17+
until retries >= max_retries
18+
result = on(host, command, acceptable_exit_codes: [0,1,2,3,4,5,6], silent: true) rescue nil
19+
return true if result && result.exit_code == 0
20+
sleep sleep_seconds
21+
retries += 1
22+
end
23+
false
24+
end
25+
26+
def wait_for_backend(host)
27+
wait_for_command(host, 'sensuctl cluster health')
28+
end
29+
1430
RSpec.configure do |c|
1531
c.add_setting :sensu_mode, default: 'base'
1632
c.add_setting :sensu_enterprise_file, default: nil

0 commit comments

Comments
 (0)