3434 let ( :checker ) { described_class . new }
3535 let ( :exit_code ) { nil }
3636
37+ # Mock result handlers
3738 before ( :each ) do
3839 def checker . ok ( *_args )
39- exit 0
40+ exit
4041 end
4142
4243 def checker . warning ( *_args )
43- exit 1
44+ exit
4445 end
4546
4647 def checker . critical ( *_args )
47- exit 2
48+ exit
4849 end
4950 end
5051
5152 [
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' ] ,
53+ [ 'Yes' , 'Yes' , 0 , :ok ] ,
54+ [ 'No' , 'Yes' , nil , : critical] ,
55+ [ 'Yes' , 'No' , nil , : critical] ,
56+ [ 'No' , 'No' , nil , : critical] ,
57+ [ 'Yes' , 'Yes' , 900 , :ok ] ,
58+ [ 'Yes' , 'Yes' , 901 , : warning] ,
59+ [ 'Yes' , 'Yes' , 1800 , : warning] ,
60+ [ 'Yes' , 'Yes' , 1801 , : critical] ,
6061 ] . each do |testdata |
61- it "returns #{ testdata [ 4 ] } for default thresholds" do
62+ it "returns #{ testdata [ 3 ] } for default thresholds" do
6263 slave_status_row = {
6364 'Slave_IO_State' => '' ,
6465 'Slave_IO_Running' => testdata [ 0 ] ,
@@ -67,23 +68,22 @@ 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 [ 3 ] )
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
75- exit_code = e . status
7677 end
77- expect ( exit_code ) . to eq testdata [ 3 ]
7878 end
7979 end
8080
8181 [
82- [ 0 , :ok , 0 , 'ok ' ] ,
83- [ 99_999 , :ok , 2 , 'critical ' ] ,
84- [ 0 , :critical , 2 , 'critical ' ] ,
82+ [ 0 , :ok , :ok , 'slave running: true, replication delayed by 0, with max. outlier at 100000 ' ] ,
83+ [ 99_999 , :ok , :critical , 'replication delayed by 99999, with max. outlier at 100000 ' ] ,
84+ [ 0 , :critical , :critical , 'replication delayed by 0, with max. outlier at 100000 ' ] ,
8585 ] . each do |testdata |
86- it "sleeps with lag outlier protection and returns #{ testdata [ 3 ] } (using default threshold )" do
86+ it "sleeps with lag outlier protection and returns #{ testdata [ 2 ] } (using default thresholds )" do
8787 checker . config [ :lag_outlier_retry ] = 1
8888 checker . config [ :lag_outlier_sleep ] = 10
8989 checker . config [ :lag_outlier_report ] = testdata [ 1 ]
@@ -107,15 +107,14 @@ def checker.critical(*_args)
107107 }
108108 ]
109109
110+ allow ( checker ) . to receive ( :open_connection ) # do nothing
111+ allow ( checker ) . to receive ( :query_slave_status ) . and_return slave_status_row [ 0 ] , slave_status_row [ 1 ]
112+ expect ( checker ) . to receive ( :sleep ) . with ( 10 )
113+ expect ( checker ) . to receive ( testdata [ 2 ] ) . with ( testdata [ 3 ] ) . once
110114 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 )
114115 checker . run
115116 rescue SystemExit => e
116- exit_code = e . status
117117 end
118- expect ( exit_code ) . to eq testdata [ 2 ]
119118 end
120119 end
121120end
0 commit comments