@@ -261,6 +261,34 @@ def redis_slowlog(index, time, microseconds, command='eval')
261261 it { is_expected . to eq ( result ) }
262262 end
263263
264+ describe '#pad_results_with_zero' do
265+ let ( :report ) {
266+ {
267+ Time . utc ( 2020 , 4 , 20 , 4 , 16 ) => { "a" => { } } ,
268+ Time . utc ( 2020 , 4 , 20 , 4 , 17 ) => { "b" => { } } ,
269+ Time . utc ( 2020 , 4 , 20 , 4 , 18 ) => { } ,
270+ Time . utc ( 2020 , 4 , 20 , 4 , 19 ) => { "a" => { } } ,
271+ }
272+
273+ }
274+ subject { slowlog_check . pad_results_with_zero ( report ) }
275+ it { is_expected . to eq (
276+ {
277+ Time . utc ( 2020 , 4 , 20 , 4 , 16 ) => { "a" => { } } ,
278+ Time . utc ( 2020 , 4 , 20 , 4 , 17 ) => { "b" => { } , "a" => slowlog_check . empty_values } ,
279+ Time . utc ( 2020 , 4 , 20 , 4 , 18 ) => { "b" => slowlog_check . empty_values } ,
280+ Time . utc ( 2020 , 4 , 20 , 4 , 19 ) => { "a" => { } } ,
281+
282+ }
283+ )
284+ }
285+
286+ describe '#new_commands' do
287+ subject { slowlog_check . new_commands ( Time . utc ( 2020 , 4 , 20 , 4 , 16 ) , { "a" => { } } ) }
288+ it { is_expected . to eq ( { "a" => Time . utc ( 2020 , 4 , 20 , 4 , 16 ) . localtime } ) }
289+ end
290+ end
291+
264292 describe '#slowlogs_by_flush_interval' do
265293 subject { slowlog_check . slowlogs_by_flush_interval }
266294 let ( :bucket18 ) {
@@ -302,6 +330,51 @@ def redis_slowlog(index, time, microseconds, command='eval')
302330 }
303331 )
304332 }
333+
334+ describe 'remembers commands it has seen' do
335+ def example_bucket ( index )
336+ value = index + 1000
337+ collector = {
338+ index . to_s =>
339+ {
340+ _95percentile : value ,
341+ avg : value ,
342+ count : value == 0 ? value : 1 ,
343+ max : value ,
344+ median : value ,
345+ min : value ,
346+ sum : value ,
347+ values : value == 0 ? [ ] : [ value ]
348+ }
349+ }
350+ if index > 0
351+ collector . merge! ( { ( index -1 ) . to_s => slowlog_check . empty_values } )
352+ end
353+ collector
354+ end
355+
356+ before ( :example ) {
357+ allow ( redis ) . to receive ( :slowlog ) . with ( 'get' , 128 ) {
358+ Array . new ( 5 ) { |x |
359+ redis_slowlog ( x , Time . utc ( 2020 , 04 , 20 , 04 , 15 , 10 ) + ( x * 60 ) , x + 1000 , x . to_s )
360+ } . reverse
361+ }
362+
363+ allow ( slowlog_check ) . to receive ( :last_time_submitted ) { Time . utc ( 2020 , 4 , 20 , 4 , 14 ) }
364+ }
365+
366+ it { is_expected . to eq (
367+ {
368+ Time . utc ( 2020 , 4 , 20 , 4 , 15 ) . localtime => example_bucket ( 0 ) ,
369+ Time . utc ( 2020 , 4 , 20 , 4 , 16 ) . localtime => example_bucket ( 1 ) ,
370+ Time . utc ( 2020 , 4 , 20 , 4 , 17 ) . localtime => example_bucket ( 2 ) ,
371+ Time . utc ( 2020 , 4 , 20 , 4 , 18 ) . localtime => example_bucket ( 3 ) ,
372+ Time . utc ( 2020 , 4 , 20 , 4 , 19 ) . localtime => example_bucket ( 4 ) ,
373+ }
374+ )
375+ }
376+
377+ end
305378 end
306379
307380 describe '#default_tags' do
0 commit comments