11
11
let ( :response ) { nil }
12
12
let ( :log_stream ) { StringIO . new }
13
13
let ( :log ) { log_contents ( log_stream ) }
14
+ let ( :event_handler_instance ) { described_class . new }
14
15
before do
15
16
start_agent
16
17
Appsignal . internal_logger = test_logger ( log_stream )
17
18
end
18
19
around { |example | keep_transactions { example . run } }
19
20
20
21
def on_start
21
- described_class . new . on_start ( request , response )
22
+ event_handler_instance . on_start ( request , response )
22
23
end
23
24
24
25
describe "#on_start" do
@@ -34,6 +35,14 @@ def on_start
34
35
expect ( Appsignal ::Transaction . current ) . to eq ( last_transaction )
35
36
end
36
37
38
+ context "when the handler is nested in another EventHandler" do
39
+ it "does not create a new transaction in the nested EventHandler" do
40
+ on_start
41
+ expect { described_class . new . on_start ( request , response ) }
42
+ . to_not ( change { created_transactions . length } )
43
+ end
44
+ end
45
+
37
46
it "registers transaction on the request environment" do
38
47
on_start
39
48
@@ -87,7 +96,7 @@ def on_start
87
96
88
97
describe "#on_error" do
89
98
def on_error ( error )
90
- described_class . new . on_error ( request , response , error )
99
+ event_handler_instance . on_error ( request , response , error )
91
100
end
92
101
93
102
it "reports the error" do
@@ -103,6 +112,15 @@ def on_error(error)
103
112
)
104
113
end
105
114
115
+ context "when the handler is nested in another EventHandler" do
116
+ it "does not report the error on the transaction" do
117
+ on_start
118
+ described_class . new . on_error ( request , response , ExampleStandardError . new ( "the error" ) )
119
+
120
+ expect ( last_transaction . to_h ) . to include ( "error" => nil )
121
+ end
122
+ end
123
+
106
124
it "logs an error in case of an internal error" do
107
125
on_start
108
126
@@ -122,7 +140,7 @@ def on_error(error)
122
140
let ( :response ) { Rack ::Events ::BufferedResponse . new ( 200 , { } , [ "body" ] ) }
123
141
124
142
def on_finish
125
- described_class . new . on_finish ( request , response )
143
+ event_handler_instance . on_finish ( request , response )
126
144
end
127
145
128
146
it "doesn't do anything without a transaction" do
@@ -155,6 +173,22 @@ def on_finish
155
173
)
156
174
)
157
175
expect ( last_transaction . ext . queue_start ) . to eq ( queue_start_time )
176
+ expect ( last_transaction ) . to be_completed
177
+ end
178
+
179
+ context "when the handler is nested in another EventHandler" do
180
+ it "does not complete the transaction" do
181
+ on_start
182
+ described_class . new . on_finish ( request , response )
183
+
184
+ expect ( last_transaction . to_h ) . to include (
185
+ "action" => nil ,
186
+ "metadata" => { } ,
187
+ "sample_data" => { } ,
188
+ "events" => [ ]
189
+ )
190
+ expect ( last_transaction ) . to_not be_completed
191
+ end
158
192
end
159
193
160
194
it "doesn't set the action name if already set" do
0 commit comments