Skip to content

Commit 9392dde

Browse files
authored
chore: fix dalli tests to account for upstream changes to Dalli:DalliError handling (#1041)
* chore: fix tests to account for sock nil check * chore: fix tests so that retry behavior is supported for different versions
1 parent 2ac008e commit 9392dde

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

instrumentation/dalli/test/opentelemetry/instrumentation/dalli/instrumentation_test.rb

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,16 @@
8080
dalli.set('foo', 'bar')
8181
exporter.reset
8282

83-
dalli.instance_variable_get(:@ring).servers.first.stub(:write, ->(_bytes) { raise Dalli::DalliError }) do
83+
dalli.instance_variable_get(:@ring).servers.first.stub(:write, ->(_bytes) { raise Dalli::NetworkError }) do
8484
dalli.get_multi('foo', 'bar')
8585
end
8686

87-
_(exporter.finished_spans.size).must_equal 1
87+
if supports_retry_on_network_errors?
88+
_(exporter.finished_spans.size).must_equal 2
89+
else
90+
_(exporter.finished_spans.size).must_equal 1
91+
end
92+
8893
_(span.name).must_equal 'getkq'
8994
_(span.attributes['db.system']).must_equal 'memcached'
9095
_(span.attributes['db.statement']).must_equal 'getkq foo bar'
@@ -93,8 +98,8 @@
9398

9499
span_event = span.events.first
95100
_(span_event.name).must_equal 'exception'
96-
_(span_event.attributes['exception.type']).must_equal 'Dalli::DalliError'
97-
_(span_event.attributes['exception.message']).must_equal 'Dalli::DalliError'
101+
_(span_event.attributes['exception.type']).must_equal 'Dalli::NetworkError'
102+
_(span_event.attributes['exception.message']).must_equal 'Dalli::NetworkError'
98103
end
99104

100105
it 'omits db.statement' do
@@ -119,4 +124,10 @@
119124
_(span.attributes['db.statement']).must_equal 'set ?'
120125
end
121126
end
127+
128+
# Dalli 3.x has different behavior than 2.x versions and attempts to retry on network errors
129+
# https://github.com/petergoldstein/dalli/pull/754
130+
def supports_retry_on_network_errors?
131+
Gem.loaded_specs['dalli'].version >= Gem::Version.new('3.0.0')
132+
end
122133
end unless ENV['OMIT_SERVICES']

0 commit comments

Comments
 (0)