@@ -140,17 +140,65 @@ def test_send_compressed_message
140140 assert_equal ( TestData ::ProtocolBuffers ::LOGS , decompress ( server_request . body ) . force_encoding ( Encoding ::ASCII_8BIT ) )
141141 end
142142
143- def test_illigal
143+ def test_unrecoverable_error
144144 set_server_response_code ( 500 )
145145 event = { "type" => "otlp_logs" , "message" => TestData ::JSON ::LOGS }
146146
147147 d = create_driver
148- d . run ( default_tag : "otlp.test" ) do
148+ d . run ( default_tag : "otlp.test" , shutdown : false ) do
149149 d . feed ( event )
150150 end
151+
152+ assert_match ( %r{got unrecoverable error response from 'http://127.0.0.1:4318/v1/logs', response code is 500} ,
153+ d . instance . log . out . logs . join )
154+
155+ d . instance_shutdown
151156 end
152157
158+ def test_error_with_disabled_unrecoverable
159+ set_server_response_code ( 500 )
160+ event = { "type" => "otlp_logs" , "message" => TestData ::JSON ::LOGS }
161+
162+ d = create_driver ( <<~CONFIG )
163+ <http>
164+ endpoint "http://127.0.0.1:4318"
165+ error_response_as_unrecoverable false
166+ </http>
167+ CONFIG
168+ d . run ( default_tag : "otlp.test" , shutdown : false ) do
169+ d . feed ( event )
170+ end
171+
172+ assert_match ( %r{got error response from 'http://127.0.0.1:4318/v1/logs', response code is 500} ,
173+ d . instance . log . out . logs . join )
153174
175+ d . instance_shutdown
176+ end
177+
178+ def test_write_with_retryable_response
179+ old_report_on_exception = Thread . report_on_exception
180+ Thread . report_on_exception = false # thread finished as invalid state since RetryableResponse raises.
181+
182+ set_server_response_code ( 503 )
183+ event = { "type" => "otlp_logs" , "message" => TestData ::JSON ::LOGS }
184+
185+ d = create_driver ( <<~CONFIG )
186+ <http>
187+ endpoint "http://127.0.0.1:4318"
188+ retryable_response_codes [503]
189+ </http>
190+ CONFIG
191+
192+ assert_raise ( Fluent ::Plugin ::OtlpOutput ::RetryableResponse ) do
193+ d . run ( default_tag : "otlp.test" , shutdown : false ) do
194+ d . feed ( event )
195+ end
196+ end
197+
198+ d . instance_shutdown ( log : $log)
199+ ensure
200+ Thread . report_on_exception = old_report_on_exception
201+ end
154202
155203 def decompress ( data )
156204 Zlib ::GzipReader . new ( StringIO . new ( data ) ) . read
0 commit comments