Skip to content

Commit

Permalink
Log over max size as an error, rather than a warning
Browse files Browse the repository at this point in the history
  • Loading branch information
petergoldstein committed Mar 16, 2019
1 parent 3fb3f82 commit 0081fb0
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/dalli/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ def guard_max_value(key, value)
message = "Value for #{key} over max size: #{@options[:value_max_bytes]} <= #{value.bytesize}"
raise Dalli::ValueOverMaxSize, message if @options[:error_when_over_max_size]

Dalli.logger.warn message
Dalli.logger.error "#{message} - this value may be truncated by memcached"
false
end
end
Expand Down
10 changes: 10 additions & 0 deletions test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,14 @@ def with_connectionpool
require 'connection_pool'
yield
end

def with_nil_logger
old = Dalli.logger
Dalli.logger = Logger.new(nil)
begin
yield
ensure
Dalli.logger = old
end
end
end
14 changes: 7 additions & 7 deletions test/test_dalli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@
dc.flush

val1 = "1234567890"*105000
assert_equal false, dc.set('a', val1)
with_nil_logger do
assert_equal false, dc.set('a', val1)
end

val1 = "1234567890"*100000
dc.set('a', val1)
Expand Down Expand Up @@ -698,12 +700,8 @@

it "handle application marshalling issues" do
memcached_persistent do |dc|
old = Dalli.logger
Dalli.logger = Logger.new(nil)
begin
with_nil_logger do
assert_equal false, dc.set('a', Proc.new { true })
ensure
Dalli.logger = old
end
end
end
Expand All @@ -714,7 +712,9 @@
dalli = Dalli::Client.new(dc.instance_variable_get(:@servers), :compress => true)

value = "0"*1024*1024
assert_equal false, dc.set('verylarge', value)
with_nil_logger do
assert_equal false, dc.set('verylarge', value)
end
dalli.set('verylarge', value)
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/test_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
s = Dalli::Server.new('127.0.0.1')
value = OpenStruct.new(:bytesize => 1_048_577)

Dalli.logger.expects(:warn).once.with("Value for foo over max size: 1048576 <= 1048577")
Dalli.logger.expects(:error).once.with("Value for foo over max size: 1048576 <= 1048577 - this value may be truncated by memcached")

s.send(:guard_max_value, :foo, value)
end
Expand Down

0 comments on commit 0081fb0

Please sign in to comment.