@@ -94,15 +94,24 @@ def test_nullable_integer_coercion
9494
9595 def test_sample_rate_coercion
9696 coercion = ScoutApm ::Config ::SampleRateCoercion . new
97+ # Preserves nil and empty strings
98+ assert_nil coercion . coerce ( nil )
99+ assert_nil coercion . coerce ( "" )
100+ assert_nil coercion . coerce ( " " )
101+ # Float strings work
97102 assert_in_delta 1.0 , coercion . coerce ( "1" )
98103 assert_in_delta 0.015 , coercion . coerce ( "1.5" )
104+ assert_in_delta 0.5 , coercion . coerce ( "0.5" )
105+ assert_in_delta 0.01 , coercion . coerce ( "0.01" )
106+ # Numbers work
99107 assert_in_delta 1.0 , coercion . coerce ( 1 )
100108 assert_in_delta 0.015 , coercion . coerce ( 1.5 )
101109 assert_in_delta 0.0 , coercion . coerce ( "0" )
102110 assert_in_delta 0.0 , coercion . coerce ( 0 )
103- assert_in_delta 0.0 , coercion . coerce ( "" )
104- assert_in_delta 0.0 , coercion . coerce ( nil )
105- assert_in_delta 0.5 , coercion . coerce ( "0.5" )
111+ # Backwards compatibility: values > 1 treated as percentages
112+ assert_in_delta 0.15 , coercion . coerce ( "15" )
113+ assert_in_delta 0.15 , coercion . coerce ( 15 )
114+ # Clamping
106115 assert_in_delta 0 , coercion . coerce ( "-2.5" )
107116 end
108117
@@ -150,4 +159,18 @@ def test_job_sample_rate_backwards_compat_with_percentage
150159 ensure
151160 ENV . delete ( 'SCOUT_JOB_SAMPLE_RATE' )
152161 end
162+
163+ def test_endpoint_sample_rate_nil_when_not_set
164+ # Nil allows sampling to fall through to global sample_rate
165+ ENV . delete ( 'SCOUT_ENDPOINT_SAMPLE_RATE' )
166+ conf = ScoutApm ::Config . without_file ( @context )
167+ assert_nil conf . value ( 'endpoint_sample_rate' )
168+ end
169+
170+ def test_job_sample_rate_nil_when_not_set
171+ # Nil allows sampling to fall through to global sample_rate
172+ ENV . delete ( 'SCOUT_JOB_SAMPLE_RATE' )
173+ conf = ScoutApm ::Config . without_file ( @context )
174+ assert_nil conf . value ( 'job_sample_rate' )
175+ end
153176end
0 commit comments