Skip to content

Commit 67c3823

Browse files
author
Jan Kunzmann
committed
check-mysql-replication-status: improve rspec test
1 parent 86d7e0f commit 67c3823

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

test/check-mysql-replication-status_spec.rb

+21-17
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,15 @@ def checker.critical(*_args)
4949
end
5050

5151
[
52-
['Yes', 'Yes', 0, 0, 'ok'],
53-
['No', 'Yes', nil, 2, 'critical'],
54-
['Yes', 'No', nil, 2, 'critical'],
55-
['No', 'No', nil, 2, 'critical'],
56-
['Yes', 'Yes', 900, 0, 'ok'],
57-
['Yes', 'Yes', 901, 1, 'warning'],
58-
['Yes', 'Yes', 1800, 1, 'warning'],
59-
['Yes', 'Yes', 1801, 2, 'critical'],
52+
# IO Thread status | SQL Thread status | Lag | Expected exit code | Expected reporting level
53+
['Yes', 'Yes', 0, 0, :ok],
54+
['No', 'Yes', nil, 2, :critical],
55+
['Yes', 'No', nil, 2, :critical],
56+
['No', 'No', nil, 2, :critical],
57+
['Yes', 'Yes', 900, 0, :ok],
58+
['Yes', 'Yes', 901, 1, :warning],
59+
['Yes', 'Yes', 1800, 1, :warning],
60+
['Yes', 'Yes', 1801, 2, :critical],
6061
].each do |testdata|
6162
it "returns #{testdata[4]} for default thresholds" do
6263
slave_status_row = {
@@ -67,9 +68,10 @@ def checker.critical(*_args)
6768
'Last_SQL_Error' => '',
6869
'Seconds_Behind_Master' => testdata[2]
6970
}
71+
allow(checker).to receive(:open_connection) # do nothing
72+
allow(checker).to receive(:query_slave_status).and_return slave_status_row
73+
expect(checker).to receive(testdata[4]).once.and_call_original
7074
begin
71-
allow(checker).to receive(:open_connection) # do nothing
72-
allow(checker).to receive(:query_slave_status).and_return slave_status_row
7375
checker.run
7476
rescue SystemExit => e
7577
exit_code = e.status
@@ -79,11 +81,12 @@ def checker.critical(*_args)
7981
end
8082

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

113+
allow(checker).to receive(:open_connection) # do nothing
114+
allow(checker).to receive(:query_slave_status).and_return slave_status_row[0], slave_status_row[1]
115+
expect(checker).to receive(:sleep).with(10)
116+
expect(checker).to receive(testdata[3]).with(testdata[4]).once.and_call_original
110117
begin
111-
allow(checker).to receive(:open_connection) # do nothing
112-
allow(checker).to receive(:query_slave_status).and_return slave_status_row[0], slave_status_row[1]
113-
expect(checker).to receive(:sleep).with(10)
114118
checker.run
115119
rescue SystemExit => e
116120
exit_code = e.status

0 commit comments

Comments
 (0)