File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed
helpers/sql-obfuscation/test/helpers/query_summary Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -17,4 +17,39 @@ def test_fetch_returns_value_when_key_exists
1717
1818 assert_equal 'value1' , result
1919 end
20+
21+ def test_eviction_when_cache_size_exceeded
22+ small_cache = OpenTelemetry ::Helpers ::QuerySummary ::Cache . new ( size : 2 )
23+
24+ small_cache . fetch ( 'key1' ) { 'value1' }
25+ small_cache . fetch ( 'key2' ) { 'value2' }
26+ small_cache . fetch ( 'key3' ) { 'value3' }
27+
28+ result = small_cache . fetch ( 'key1' ) { 'new_value1' }
29+ assert_equal 'new_value1' , result
30+ end
31+
32+ def test_cache_thread_safety
33+ threads = Array . new ( 10 ) do |i |
34+ Thread . new do
35+ @cache . fetch ( 'shared_key' ) { "thread_#{ i } _value" }
36+ end
37+ end
38+
39+ results = threads . map ( &:value )
40+
41+ assert_equal 1 , results . uniq . size
42+ end
43+
44+ def test_empty_string
45+ @cache . fetch ( '' ) { 'empty_string_value' }
46+
47+ assert_equal 'empty_string_value' , @cache . fetch ( '' )
48+ end
49+
50+ def test_nil
51+ @cache . fetch ( nil ) { 'nil_value' }
52+
53+ assert_equal 'nil_value' , @cache . fetch ( nil )
54+ end
2055end
You can’t perform that action at this time.
0 commit comments