@@ -5,133 +5,145 @@ defmodule PhxExampleTest do
5
5
6
6
setup_all context , do: TestSupport . simulate_agent_enabled ( context )
7
7
8
- test "Phoenix metrics generated" do
9
- TestSupport . restart_harvest_cycle ( Collector.Metric.HarvestCycle )
10
- TestSupport . restart_harvest_cycle ( Collector.TransactionEvent.HarvestCycle )
8
+ for server <- [ :cowboy , :bandit ] do
9
+ describe "Testing #{ server } :" do
10
+ test "Phoenix metrics generated" do
11
+ TestSupport . restart_harvest_cycle ( Collector.Metric.HarvestCycle )
12
+ TestSupport . restart_harvest_cycle ( Collector.TransactionEvent.HarvestCycle )
11
13
12
- { :ok , % { body: body } } = request ( "/phx/bar" )
13
- assert body =~ "Welcome to Phoenix"
14
+ { :ok , % { body: body } } = request ( "/phx/bar" , unquote ( server ) )
15
+ assert body =~ "Welcome to Phoenix"
14
16
15
- metrics = TestSupport . gather_harvest ( Collector.Metric.Harvester )
17
+ metrics = TestSupport . gather_harvest ( Collector.Metric.Harvester )
16
18
17
- assert TestSupport . find_metric (
18
- metrics ,
19
- "WebTransaction/Phoenix/PhxExampleWeb.PageController/index"
20
- )
19
+ assert TestSupport . find_metric (
20
+ metrics ,
21
+ "WebTransaction/Phoenix/PhxExampleWeb.PageController/index"
22
+ )
21
23
22
- [ [ _ , event ] ] = TestSupport . gather_harvest ( Collector.TransactionEvent.Harvester )
24
+ [ [ _ , event ] ] = TestSupport . gather_harvest ( Collector.TransactionEvent.Harvester )
23
25
24
- assert event [ :"phoenix.endpoint" ] == "PhxExampleWeb.Endpoint "
25
- assert event [ :"phoenix.router" ] == "PhxExampleWeb.Router"
26
- assert event [ :"phoenix.controller" ] == "PhxExampleWeb.PageController"
27
- assert event [ :"phoenix.action" ] == "index"
28
- assert event [ :status ] == 200
29
- end
26
+ assert event [ :"phoenix.endpoint" ] =~ "PhxExampleWeb"
27
+ assert event [ :"phoenix.router" ] == "PhxExampleWeb.Router"
28
+ assert event [ :"phoenix.controller" ] == "PhxExampleWeb.PageController"
29
+ assert event [ :"phoenix.action" ] == "index"
30
+ assert event [ :status ] == 200
31
+ end
30
32
31
- test "Phoenix metrics generated for LiveView" do
32
- TestSupport . restart_harvest_cycle ( Collector.Metric.HarvestCycle )
33
- TestSupport . restart_harvest_cycle ( Collector.TransactionEvent.HarvestCycle )
33
+ test "Phoenix metrics generated for LiveView" do
34
+ TestSupport . restart_harvest_cycle ( Collector.Metric.HarvestCycle )
35
+ TestSupport . restart_harvest_cycle ( Collector.TransactionEvent.HarvestCycle )
34
36
35
- { :ok , % { body: body } } = request ( "/phx/home" )
36
- assert body =~ "Some content"
37
+ { :ok , % { body: body } } = request ( "/phx/home" , unquote ( server ) )
38
+ assert body =~ "Some content"
37
39
38
- metrics = TestSupport . gather_harvest ( Collector.Metric.Harvester )
40
+ metrics = TestSupport . gather_harvest ( Collector.Metric.Harvester )
39
41
40
- assert TestSupport . find_metric (
41
- metrics ,
42
- "WebTransaction/Phoenix/PhxExampleWeb.HomeLive/index"
43
- )
42
+ assert TestSupport . find_metric (
43
+ metrics ,
44
+ "WebTransaction/Phoenix/PhxExampleWeb.HomeLive/index"
45
+ )
44
46
45
- [ [ _ , event ] ] = TestSupport . gather_harvest ( Collector.TransactionEvent.Harvester )
47
+ [ [ _ , event ] ] = TestSupport . gather_harvest ( Collector.TransactionEvent.Harvester )
46
48
47
- assert event [ :"phoenix.endpoint" ] == "PhxExampleWeb.Endpoint "
48
- assert event [ :"phoenix.router" ] == "PhxExampleWeb.Router"
49
- assert event [ :"phoenix.controller" ] == "Phoenix.LiveView.Plug"
50
- assert event [ :"phoenix.action" ] == "index"
51
- assert event [ :status ] == 200
52
- end
49
+ assert event [ :"phoenix.endpoint" ] =~ "PhxExampleWeb"
50
+ assert event [ :"phoenix.router" ] == "PhxExampleWeb.Router"
51
+ assert event [ :"phoenix.controller" ] == "Phoenix.LiveView.Plug"
52
+ assert event [ :"phoenix.action" ] == "index"
53
+ assert event [ :status ] == 200
54
+ end
53
55
54
- @ tag :capture_log
55
- test "Phoenix error" do
56
- TestSupport . restart_harvest_cycle ( Collector.Metric.HarvestCycle )
57
- TestSupport . restart_harvest_cycle ( Collector.TransactionEvent.HarvestCycle )
56
+ @ tag :capture_log
57
+ test "Phoenix error" do
58
+ TestSupport . restart_harvest_cycle ( Collector.Metric.HarvestCycle )
59
+ TestSupport . restart_harvest_cycle ( Collector.TransactionEvent.HarvestCycle )
58
60
59
- { :ok , % { body: body , status_code: 500 } } = request ( "/phx/error" )
61
+ { :ok , % { body: body , status_code: 500 } } = request ( "/phx/error" , unquote ( server ) )
60
62
61
- assert body =~ "Oops, Internal Server Error"
63
+ assert body =~ "Oops, Internal Server Error"
62
64
63
- metrics = TestSupport . gather_harvest ( Collector.Metric.Harvester )
65
+ metrics = TestSupport . gather_harvest ( Collector.Metric.Harvester )
64
66
65
- assert TestSupport . find_metric (
66
- metrics ,
67
- "WebTransaction/Phoenix/PhxExampleWeb.PageController/error"
68
- )
67
+ assert TestSupport . find_metric (
68
+ metrics ,
69
+ "WebTransaction/Phoenix/PhxExampleWeb.PageController/error"
70
+ )
69
71
70
- [ [ _ , event ] ] = TestSupport . gather_harvest ( Collector.TransactionEvent.Harvester )
72
+ [ [ _ , event ] ] = TestSupport . gather_harvest ( Collector.TransactionEvent.Harvester )
71
73
72
- assert event [ :status ] == 500
73
- assert event [ :"phoenix.endpoint" ] == "PhxExampleWeb.Endpoint "
74
- assert event [ :"phoenix.router" ] == "PhxExampleWeb.Router"
75
- assert event [ :"phoenix.controller" ] == "PhxExampleWeb.PageController"
76
- assert event [ :"phoenix.action" ] == "error"
77
- assert event [ :error ]
78
- end
74
+ assert event [ :status ] == 500
75
+ assert event [ :"phoenix.endpoint" ] =~ "PhxExampleWeb"
76
+ assert event [ :"phoenix.router" ] == "PhxExampleWeb.Router"
77
+ assert event [ :"phoenix.controller" ] == "PhxExampleWeb.PageController"
78
+ assert event [ :"phoenix.action" ] == "error"
79
+ assert event [ :error ]
80
+ end
79
81
80
- @ tag :capture_log
81
- test "Phoenix LiveView error" do
82
- TestSupport . restart_harvest_cycle ( Collector.Metric.HarvestCycle )
83
- TestSupport . restart_harvest_cycle ( Collector.TransactionEvent.HarvestCycle )
82
+ @ tag :capture_log
83
+ test "Phoenix LiveView error" do
84
+ TestSupport . restart_harvest_cycle ( Collector.Metric.HarvestCycle )
85
+ TestSupport . restart_harvest_cycle ( Collector.TransactionEvent.HarvestCycle )
84
86
85
- { :ok , % { body: body , status_code: 500 } } = request ( "/phx/live_error" )
87
+ { :ok , % { body: body , status_code: 500 } } = request ( "/phx/live_error" , unquote ( server ) )
86
88
87
- assert body =~ "Oops, Internal Server Error"
89
+ assert body =~ "Oops, Internal Server Error"
88
90
89
- metrics = TestSupport . gather_harvest ( Collector.Metric.Harvester )
91
+ metrics = TestSupport . gather_harvest ( Collector.Metric.Harvester )
90
92
91
- assert TestSupport . find_metric (
92
- metrics ,
93
- "WebTransaction/Phoenix/PhxExampleWeb.ErrorLive/index"
94
- )
93
+ assert TestSupport . find_metric (
94
+ metrics ,
95
+ "WebTransaction/Phoenix/PhxExampleWeb.ErrorLive/index"
96
+ )
95
97
96
- [ [ _ , event ] ] = TestSupport . gather_harvest ( Collector.TransactionEvent.Harvester )
98
+ [ [ _ , event ] ] = TestSupport . gather_harvest ( Collector.TransactionEvent.Harvester )
97
99
98
- assert event [ :status ] == 500
99
- assert event [ :"phoenix.endpoint" ] == "PhxExampleWeb.Endpoint"
100
- assert event [ :"phoenix.router" ] == "PhxExampleWeb.Router"
101
- assert event [ :"phoenix.controller" ] == "Phoenix.LiveView.Plug"
102
- assert event [ :"phoenix.action" ] == "index"
103
- assert event [ :error ]
104
- end
100
+ assert event [ :status ] == 500
101
+ assert event [ :"phoenix.endpoint" ] =~ "PhxExampleWeb"
102
+ assert event [ :"phoenix.router" ] == "PhxExampleWeb.Router"
103
+ assert event [ :"phoenix.controller" ] == "Phoenix.LiveView.Plug"
104
+ assert event [ :"phoenix.action" ] == "index"
105
+ assert event [ :error ]
106
+ end
107
+
108
+ test "Phoenix route not found" do
109
+ TestSupport . restart_harvest_cycle ( Collector.Metric.HarvestCycle )
110
+ TestSupport . restart_harvest_cycle ( Collector.TransactionEvent.HarvestCycle )
111
+ TestSupport . restart_harvest_cycle ( Collector.ErrorTrace.HarvestCycle )
105
112
106
- test "Phoenix route not found" do
107
- TestSupport . restart_harvest_cycle ( Collector.Metric.HarvestCycle )
108
- TestSupport . restart_harvest_cycle ( Collector.TransactionEvent.HarvestCycle )
109
- TestSupport . restart_harvest_cycle ( Collector.ErrorTrace.HarvestCycle )
113
+ { :ok , % { body: body , status_code: 404 } } = request ( "/not_found" , unquote ( server ) )
114
+ assert body =~ "Not Found"
110
115
111
- { :ok , % { body: body , status_code: 404 } } = request ( "/not_found" )
112
- assert body =~ "Not Found"
116
+ metrics = TestSupport . gather_harvest ( Collector.Metric.Harvester )
113
117
114
- metrics = TestSupport . gather_harvest ( Collector.Metric.Harvester )
118
+ metric =
119
+ case unquote ( server ) do
120
+ :cowboy -> "WebTransaction/Phoenix/PhxExampleWeb.Endpoint/GET"
121
+ :bandit -> "WebTransaction/Phoenix/PhxExampleWeb.BanditEndpoint/GET"
122
+ end
115
123
116
- assert TestSupport . find_metric (
117
- metrics ,
118
- "WebTransaction/Phoenix/PhxExampleWeb.Endpoint/GET"
119
- )
124
+ assert TestSupport . find_metric ( metrics , metric )
120
125
121
- [ [ _ , event ] ] = TestSupport . gather_harvest ( Collector.TransactionEvent.Harvester )
126
+ [ [ _ , event ] ] = TestSupport . gather_harvest ( Collector.TransactionEvent.Harvester )
122
127
123
- assert event [ :status ] == 404
124
- assert event [ :"phoenix.endpoint" ] == "PhxExampleWeb.Endpoint "
125
- assert event [ :"phoenix.router" ] == "PhxExampleWeb.Router"
126
- refute event [ :"phoenix.controller" ]
127
- refute event [ :error ]
128
+ assert event [ :status ] == 404
129
+ assert event [ :"phoenix.endpoint" ] =~ "PhxExampleWeb"
130
+ assert event [ :"phoenix.router" ] == "PhxExampleWeb.Router"
131
+ refute event [ :"phoenix.controller" ]
132
+ refute event [ :error ]
128
133
129
- errors = TestSupport . gather_harvest ( Collector.ErrorTrace.Harvester )
130
- assert errors == [ ]
134
+ errors = TestSupport . gather_harvest ( Collector.ErrorTrace.Harvester )
135
+ assert errors == [ ]
136
+ end
137
+ end
131
138
end
132
139
133
- defp request ( path ) do
134
- config = Application . get_env ( :phx_example , PhxExampleWeb.Endpoint )
140
+ defp request ( path , server ) do
141
+ config =
142
+ case server do
143
+ :cowboy -> Application . get_env ( :phx_example , PhxExampleWeb.Endpoint )
144
+ :bandit -> Application . get_env ( :phx_example , PhxExampleWeb.BanditEndpoint )
145
+ end
146
+
135
147
NewRelic.Util.HTTP . get ( "http://localhost:#{ config [ :http ] [ :port ] } #{ path } " )
136
148
end
137
149
end
0 commit comments