@@ -49,14 +49,15 @@ def checker.critical(*_args)
49
49
end
50
50
51
51
[
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 ] ,
60
61
] . each do |testdata |
61
62
it "returns #{ testdata [ 4 ] } for default thresholds" do
62
63
slave_status_row = {
@@ -67,9 +68,10 @@ def checker.critical(*_args)
67
68
'Last_SQL_Error' => '' ,
68
69
'Seconds_Behind_Master' => testdata [ 2 ]
69
70
}
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
70
74
begin
71
- allow ( checker ) . to receive ( :open_connection ) # do nothing
72
- allow ( checker ) . to receive ( :query_slave_status ) . and_return slave_status_row
73
75
checker . run
74
76
rescue SystemExit => e
75
77
exit_code = e . status
@@ -79,11 +81,12 @@ def checker.critical(*_args)
79
81
end
80
82
81
83
[
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' ] ,
85
88
] . 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
87
90
checker . config [ :lag_outlier_retry ] = 1
88
91
checker . config [ :lag_outlier_sleep ] = 10
89
92
checker . config [ :lag_outlier_report ] = testdata [ 1 ]
@@ -107,10 +110,11 @@ def checker.critical(*_args)
107
110
}
108
111
]
109
112
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
110
117
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 )
114
118
checker . run
115
119
rescue SystemExit => e
116
120
exit_code = e . status
0 commit comments