|
17 | 17 | let(:frozen_time) { Time.utc(2020,4,20,4,20,45) }
|
18 | 18 | let(:ddog_time) { Time.utc(2020,4,20,4,16).to_i * 1000.0 }
|
19 | 19 |
|
| 20 | + def redis_slowlog(index, time, microseconds) |
| 21 | + [ |
| 22 | + index, |
| 23 | + time.to_i, |
| 24 | + microseconds, |
| 25 | + [ |
| 26 | + "eval", |
| 27 | + "", |
| 28 | + "0" |
| 29 | + ], |
| 30 | + "192.0.2.40:55700", |
| 31 | + "" |
| 32 | + ] |
| 33 | + end |
| 34 | + |
20 | 35 | before(:example) do
|
21 | 36 | ##
|
22 | 37 | # redis mock
|
23 | 38 | allow(redis).to receive(:connection) { {host: 'master.replicationgroup.abcde.use2.cache.amazonaws.com' } }
|
24 |
| - allow(redis).to receive(:slowlog).with('get') { |
| 39 | + allow(redis).to receive(:slowlog).with('get', 128) { |
25 | 40 | [
|
26 |
| - [ |
27 |
| - 3, |
28 |
| - Time.utc(2020,04,20,04,19,45).to_i, |
29 |
| - 400000, |
30 |
| - [ |
31 |
| - "eval", |
32 |
| - "", |
33 |
| - "0" |
34 |
| - ], |
35 |
| - "192.0.2.40:55700", |
36 |
| - "" |
37 |
| - ], |
38 |
| - [ |
39 |
| - 2, |
40 |
| - Time.utc(2020,04,20,04,19,15).to_i, |
41 |
| - 100000, |
42 |
| - [ |
43 |
| - "eval", |
44 |
| - "", |
45 |
| - "0" |
46 |
| - ], |
47 |
| - "192.0.2.40:55700", |
48 |
| - "" |
49 |
| - ], |
50 |
| - [ |
51 |
| - 1, |
52 |
| - Time.utc(2020,04,20,04,18,45).to_i, |
53 |
| - 100000, |
54 |
| - [ |
55 |
| - "eval", |
56 |
| - "", |
57 |
| - "0" |
58 |
| - ], |
59 |
| - "192.0.2.40:55700", |
60 |
| - "" |
61 |
| - ], |
62 |
| - [ |
63 |
| - 0, |
64 |
| - Time.utc(2020,04,20,04,18,15).to_i, |
65 |
| - 200000, |
66 |
| - [ |
67 |
| - "eval", |
68 |
| - "", |
69 |
| - "0" |
70 |
| - ], |
71 |
| - "192.0.2.40:55700", |
72 |
| - "" |
73 |
| - ] |
| 41 | + redis_slowlog( 3, Time.utc(2020,04,20,04,19,45), 400000 ), |
| 42 | + redis_slowlog( 2, Time.utc(2020,04,20,04,19,15), 100000 ), |
| 43 | + redis_slowlog( 1, Time.utc(2020,04,20,04,18,45), 100000 ), |
| 44 | + redis_slowlog( 0, Time.utc(2020,04,20,04,18,15), 200000 ), |
74 | 45 | ]
|
75 | 46 | }
|
76 | 47 |
|
|
120 | 91 | allow_any_instance_of(Logger).to receive(:info) {}
|
121 | 92 | end
|
122 | 93 |
|
| 94 | + describe '#redis_slowlog.length' do |
| 95 | + context 'redis has 4 entries' do |
| 96 | + before(:each) do |
| 97 | + allow(redis).to receive(:slowlog).with('get', 128) { |
| 98 | + [ |
| 99 | + redis_slowlog( 3, Time.utc(2020,04,20,04,19,45), 400000 ), |
| 100 | + redis_slowlog( 2, Time.utc(2020,04,20,04,19,15), 100000 ), |
| 101 | + redis_slowlog( 1, Time.utc(2020,04,20,04,18,45), 100000 ), |
| 102 | + redis_slowlog( 0, Time.utc(2020,04,20,04,18,15), 200000 ), |
| 103 | + ] |
| 104 | + } |
| 105 | + end |
| 106 | + |
| 107 | + subject { slowlog_check.redis_slowlog.length } |
| 108 | + it { is_expected.to eq(4) } |
| 109 | + end |
| 110 | + |
| 111 | + context 'redis has 129 entries and a zeroeth entry' do |
| 112 | + before(:each) do |
| 113 | + allow(redis).to receive(:slowlog).with('get', 128) { |
| 114 | + Array.new(129) { |x| |
| 115 | + redis_slowlog(x, Time.utc(2020,04,20,04,00,00) + x, x * 1000) |
| 116 | + }.reverse[0..127] |
| 117 | + } |
| 118 | + |
| 119 | + allow(redis).to receive(:slowlog).with('get', 256) { |
| 120 | + Array.new(129) { |x| |
| 121 | + redis_slowlog(x, Time.utc(2020,04,20,04,00,00) + x, x * 1000) |
| 122 | + }.reverse |
| 123 | + } |
| 124 | + |
| 125 | + end |
| 126 | + |
| 127 | + subject { slowlog_check.redis_slowlog.length } |
| 128 | + it { is_expected.to eq(129) } |
| 129 | + end |
| 130 | + |
| 131 | + context 'redis has 1048576 * 2 + 1 entries and a zeroeth entry' do |
| 132 | + let(:sauce) { |
| 133 | + Array.new(1048576 * 2 + 1) { |x| |
| 134 | + redis_slowlog(x, 1587352800, x) #lettuce not create so many unnecessary Time objects |
| 135 | + }.reverse |
| 136 | + } |
| 137 | + before(:each) do |
| 138 | + allow(redis).to receive(:slowlog) { |_,number| |
| 139 | + sauce[0..number-1] |
| 140 | + } |
| 141 | + end |
| 142 | + |
| 143 | + subject { slowlog_check.redis_slowlog.length } |
| 144 | + it { is_expected.to eq(1048576 * 2) } # with the last entry dropped |
| 145 | + end |
| 146 | + |
| 147 | + context 'redis has 567 entries and no zeroeth entry' do |
| 148 | + let(:sauce) { |
| 149 | + Array.new(567) { |x| |
| 150 | + redis_slowlog(x, Time.utc(2020,04,20,03,20,00) + x, x) |
| 151 | + }.reverse |
| 152 | + } |
| 153 | + before(:each) do |
| 154 | + allow(redis).to receive(:slowlog) { |_,number| |
| 155 | + sauce[0..number-1] |
| 156 | + } |
| 157 | + end |
| 158 | + |
| 159 | + subject { slowlog_check.redis_slowlog.length } |
| 160 | + it { is_expected.to eq(567) } |
| 161 | + |
| 162 | + end |
| 163 | + end |
123 | 164 |
|
124 | 165 | describe '#replication_group' do
|
125 | 166 | subject { slowlog_check.replication_group }
|
|
0 commit comments