Skip to content

Commit

Permalink
check-mysql-replication-status: improve rspec test
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Kunzmann committed Jun 17, 2019
1 parent 86d7e0f commit 67c3823
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions test/check-mysql-replication-status_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@ def checker.critical(*_args)
end

[
['Yes', 'Yes', 0, 0, 'ok'],
['No', 'Yes', nil, 2, 'critical'],
['Yes', 'No', nil, 2, 'critical'],
['No', 'No', nil, 2, 'critical'],
['Yes', 'Yes', 900, 0, 'ok'],
['Yes', 'Yes', 901, 1, 'warning'],
['Yes', 'Yes', 1800, 1, 'warning'],
['Yes', 'Yes', 1801, 2, 'critical'],
# IO Thread status | SQL Thread status | Lag | Expected exit code | Expected reporting level
['Yes', 'Yes', 0, 0, :ok],
['No', 'Yes', nil, 2, :critical],
['Yes', 'No', nil, 2, :critical],
['No', 'No', nil, 2, :critical],
['Yes', 'Yes', 900, 0, :ok],
['Yes', 'Yes', 901, 1, :warning],
['Yes', 'Yes', 1800, 1, :warning],
['Yes', 'Yes', 1801, 2, :critical],
].each do |testdata|
it "returns #{testdata[4]} for default thresholds" do
slave_status_row = {
Expand All @@ -67,9 +68,10 @@ def checker.critical(*_args)
'Last_SQL_Error' => '',
'Seconds_Behind_Master' => testdata[2]
}
allow(checker).to receive(:open_connection) # do nothing
allow(checker).to receive(:query_slave_status).and_return slave_status_row
expect(checker).to receive(testdata[4]).once.and_call_original
begin
allow(checker).to receive(:open_connection) # do nothing
allow(checker).to receive(:query_slave_status).and_return slave_status_row
checker.run
rescue SystemExit => e
exit_code = e.status
Expand All @@ -79,11 +81,12 @@ def checker.critical(*_args)
end

[
[0, :ok, 0, 'ok'],
[99_999, :ok, 2, 'critical'],
[0, :critical, 2, 'critical'],
# Lag after outlier | Configured reporting level | Exit code | Expected reporting level | Expected message
[0, :ok, 0, :ok, 'slave running: true, replication delayed by 0, with max. outlier at 100000'],
[99_999, :ok, 2, :critical, 'replication delayed by 99999, with max. outlier at 100000'],
[0, :critical, 2, :critical, 'replication delayed by 0, with max. outlier at 100000'],
].each do |testdata|
it "sleeps with lag outlier protection and returns #{testdata[3]} (using default threshold)" do
it "sleeps with lag outlier protection and returns #{testdata[3]} (using default thresholds)" do
checker.config[:lag_outlier_retry] = 1
checker.config[:lag_outlier_sleep] = 10
checker.config[:lag_outlier_report] = testdata[1]
Expand All @@ -107,10 +110,11 @@ def checker.critical(*_args)
}
]

allow(checker).to receive(:open_connection) # do nothing
allow(checker).to receive(:query_slave_status).and_return slave_status_row[0], slave_status_row[1]
expect(checker).to receive(:sleep).with(10)
expect(checker).to receive(testdata[3]).with(testdata[4]).once.and_call_original
begin
allow(checker).to receive(:open_connection) # do nothing
allow(checker).to receive(:query_slave_status).and_return slave_status_row[0], slave_status_row[1]
expect(checker).to receive(:sleep).with(10)
checker.run
rescue SystemExit => e
exit_code = e.status
Expand Down

0 comments on commit 67c3823

Please sign in to comment.