2424 require 'racecar'
2525 module ElasticAPM
2626 RSpec . describe 'Spy: Racecar' , :intercept do
27+ let ( :instrumentation_payload ) {
28+ { consumer_class : 'SpecConsumer' ,
29+ topic : 'spec_topic' ,
30+ partition : '0' ,
31+ offset : '1' ,
32+ create_time : Time . now ,
33+ key : '1' ,
34+ value : { key : 'value' } ,
35+ headers : { key : 'value' } }
36+ }
2737 it 'captures the instrumentation' do
2838 with_agent do
29- instrumentation_payload = {
30- consumer_class : 'SpecConsumer' ,
31- topic : 'spec_topic' ,
32- partition : '0' ,
33- offset : '1' ,
34- create_time : Time . now ,
35- key : '1' ,
36- value : { key : 'value' } ,
37- headers : { key : 'value' }
38- }
3939 ActiveSupport ::Notifications . instrument ( 'start_process_message.racecar' , instrumentation_payload )
4040 ActiveSupport ::Notifications . instrument ( 'process_message.racecar' , instrumentation_payload ) do
4141 # this is the body of the racecar consumer #process method
@@ -47,6 +47,41 @@ module ElasticAPM
4747 expect ( first_transaction . context . service . framework . name ) . to eq ( 'racecar' )
4848 end
4949 end
50+
51+ describe 'transaction outcome' do
52+ it 'records success when no delivery error happen' do
53+ with_agent do
54+ ActiveSupport ::Notifications . instrument ( 'start_process_message.racecar' , instrumentation_payload )
55+ ActiveSupport ::Notifications . instrument ( 'process_message.racecar' , instrumentation_payload ) do
56+ # this is the body of the racecar consumer #process method
57+ end
58+ first_transaction = @intercepted . transactions . first
59+ expect ( first_transaction . outcome ) . to eq ( Transaction ::Outcome ::SUCCESS )
60+ end
61+ end
62+ it 'records failure when with a unrecoverable delivery error' do
63+ instrumentation_payload [ :unrecoverable_delivery_error ] = true
64+ with_agent do
65+ ActiveSupport ::Notifications . instrument ( 'start_process_message.racecar' , instrumentation_payload )
66+ ActiveSupport ::Notifications . instrument ( 'process_message.racecar' , instrumentation_payload ) do
67+ # this is the body of the racecar consumer #process method
68+ end
69+ first_transaction = @intercepted . transactions . first
70+ expect ( first_transaction . outcome ) . to eq ( Transaction ::Outcome ::FAILURE )
71+ end
72+ end
73+ it 'records failure when with a recoverable delivery error' do
74+ instrumentation_payload [ :unrecoverable_delivery_error ] = false
75+ with_agent do
76+ ActiveSupport ::Notifications . instrument ( 'start_process_message.racecar' , instrumentation_payload )
77+ ActiveSupport ::Notifications . instrument ( 'process_message.racecar' , instrumentation_payload ) do
78+ # this is the body of the racecar consumer #process method
79+ end
80+ first_transaction = @intercepted . transactions . first
81+ expect ( first_transaction . outcome ) . to eq ( Transaction ::Outcome ::FAILURE )
82+ end
83+ end
84+ end
5085 end
5186 end
5287
0 commit comments