Skip to content

Commit c226182

Browse files
authored
Bug: All traces are loaded when no callback name is checked in filters (#432)
* fix * Update tests * Add e2e test
1 parent b1ddada commit c226182

3 files changed

Lines changed: 43 additions & 25 deletions

File tree

lib/live_debugger/services/trace_service.ex

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -140,42 +140,38 @@ defmodule LiveDebugger.Services.TraceService do
140140
]
141141
end
142142

143-
def to_spec([], []), do: [{:"/=", :"$2", nil}]
144-
145143
def to_spec(functions, []) do
146-
[{:andalso, List.first(functions_to_spec(functions)), {:"/=", :"$2", nil}}]
147-
end
148-
149-
def to_spec([], execution_times) do
150-
[{:andalso, List.first(execution_times_to_spec(execution_times)), {:"/=", :"$2", nil}}]
144+
[{:andalso, functions_to_spec(functions), {:"/=", :"$2", nil}}]
151145
end
152146

153147
def to_spec(functions, execution_times) do
154148
[
155149
{:andalso,
156-
{:andalso, List.first(functions_to_spec(functions)),
157-
List.first(execution_times_to_spec(execution_times))}, {:"/=", :"$2", nil}}
150+
{:andalso, functions_to_spec(functions), execution_times_to_spec(execution_times)},
151+
{:"/=", :"$2", nil}}
158152
]
159153
end
160154

161-
def functions_to_spec([single]), do: [{:"=:=", :"$1", single}]
155+
def functions_to_spec([]), do: false
156+
157+
def functions_to_spec([single]), do: {:"=:=", :"$1", single}
162158

163159
def functions_to_spec([first, second | rest]) do
164160
initial_orelse =
165-
{:orelse, List.first(functions_to_spec([first])), List.first(functions_to_spec([second]))}
161+
{:orelse, functions_to_spec([first]), functions_to_spec([second])}
166162

167163
result =
168164
Enum.reduce(rest, initial_orelse, fn x, acc ->
169-
{:orelse, acc, List.first(functions_to_spec([x]))}
165+
{:orelse, acc, functions_to_spec([x])}
170166
end)
171167

172-
[{:andalso, result, {:"/=", :"$2", nil}}]
168+
{:andalso, result, {:"/=", :"$2", nil}}
173169
end
174170

175171
def execution_times_to_spec(execution_times) do
176172
min_time = Keyword.get(execution_times, :exec_time_min, 0)
177173
max_time = Keyword.get(execution_times, :exec_time_max, :infinity)
178-
[{:andalso, {:>=, :"$2", min_time}, {:"=<", :"$2", max_time}}]
174+
{:andalso, {:>=, :"$2", min_time}, {:"=<", :"$2", max_time}}
179175
end
180176

181177
@spec ets_table(pid :: ets_table_id()) :: :ets.table()

test/live_debugger/channel_dashboard_test.exs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,18 @@ defmodule LiveDebugger.ChannelDashboardTest do
280280
"render/1",
281281
"mount/3"
282282
])
283+
|> click(filters_button())
284+
|> click(checkbox("mount"))
285+
|> click(checkbox("handle_params"))
286+
|> click(checkbox("handle_info"))
287+
|> click(checkbox("handle_call"))
288+
|> click(checkbox("handle_cast"))
289+
|> click(checkbox("terminate"))
290+
|> click(checkbox("render"))
291+
|> click(checkbox("handle_event"))
292+
|> click(checkbox("handle_async"))
293+
|> click(css("button", text: "Apply"))
294+
|> assert_has(traces(count: 0))
283295
end
284296

285297
defp assert_traces(session, count, callback_names) do

test/services/trace_service_test.exs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ defmodule Services.TraceServiceTest do
77
alias LiveDebugger.Services.TraceService
88
alias LiveDebugger.MockEtsTableServer
99

10+
@all_functions LiveDebugger.Utils.Callbacks.callbacks_functions()
11+
1012
setup :verify_on_exit!
1113

1214
setup_all do
@@ -56,7 +58,8 @@ defmodule Services.TraceServiceTest do
5658
MockEtsTableServer
5759
|> expect(:table, fn ^pid -> table end)
5860

59-
assert {[^trace1, ^trace2], _} = TraceService.existing_traces(pid)
61+
assert {[^trace1, ^trace2], _} =
62+
TraceService.existing_traces(pid, functions: @all_functions)
6063
end
6164

6265
test "returns traces with limit and continuation", %{module: module, pid: pid, table: table} do
@@ -71,12 +74,13 @@ defmodule Services.TraceServiceTest do
7174
MockEtsTableServer
7275
|> expect(:table, fn ^pid -> table end)
7376

74-
{traces1, cont} = TraceService.existing_traces(pid, limit: 2)
75-
{traces2, cont} = TraceService.existing_traces(pid, cont: cont)
77+
{traces1, cont} = TraceService.existing_traces(pid, limit: 2, functions: @all_functions)
78+
{traces2, cont} = TraceService.existing_traces(pid, cont: cont, functions: @all_functions)
7679

7780
assert [trace1, trace2] == traces1
7881
assert [trace3] == traces2
7982
assert cont == :end_of_table
83+
8084
assert :end_of_table == TraceService.existing_traces(pid, cont: :end_of_table)
8185
end
8286

@@ -121,12 +125,14 @@ defmodule Services.TraceServiceTest do
121125

122126
assert {[^trace2], _} =
123127
TraceService.existing_traces(pid,
124-
execution_times: [exec_time_min: 15, exec_time_max: 50]
128+
execution_times: [exec_time_min: 15, exec_time_max: 50],
129+
functions: @all_functions
125130
)
126131

127132
assert {[^trace2, ^trace3], _} =
128133
TraceService.existing_traces(pid,
129-
execution_times: [exec_time_min: 15, exec_time_max: :infinity]
134+
execution_times: [exec_time_min: 15, exec_time_max: :infinity],
135+
functions: @all_functions
130136
)
131137
end
132138

@@ -173,8 +179,11 @@ defmodule Services.TraceServiceTest do
173179
MockEtsTableServer
174180
|> expect(:table, 2, fn ^pid -> table end)
175181

176-
assert {[^trace1], _} = TraceService.existing_traces(pid, node_id: pid)
177-
assert {[^trace2, ^trace3], _} = TraceService.existing_traces(pid, node_id: cid)
182+
assert {[^trace1], _} =
183+
TraceService.existing_traces(pid, node_id: pid, functions: @all_functions)
184+
185+
assert {[^trace2, ^trace3], _} =
186+
TraceService.existing_traces(pid, node_id: cid, functions: @all_functions)
178187
end
179188

180189
test "returns :end_of_table when no traces match", %{module: module, pid: pid, table: table} do
@@ -201,7 +210,7 @@ defmodule Services.TraceServiceTest do
201210
MockEtsTableServer
202211
|> expect(:table, fn ^pid -> table end)
203212

204-
assert {[^trace1], _} = TraceService.existing_traces(pid)
213+
assert {[^trace1], _} = TraceService.existing_traces(pid, functions: @all_functions)
205214
end
206215
end
207216

@@ -218,15 +227,16 @@ defmodule Services.TraceServiceTest do
218227
MockEtsTableServer
219228
|> expect(:table, 5, fn ^pid -> table end)
220229

221-
assert {[^trace1, ^trace2], _} = TraceService.existing_traces(pid)
230+
assert {[^trace1, ^trace2], _} =
231+
TraceService.existing_traces(pid, functions: @all_functions)
222232

223233
TraceService.clear_traces(pid, trace1.pid)
224234

225-
assert {[^trace2], _} = TraceService.existing_traces(pid)
235+
assert {[^trace2], _} = TraceService.existing_traces(pid, functions: @all_functions)
226236

227237
TraceService.clear_traces(pid, trace2.cid)
228238

229-
assert :end_of_table = TraceService.existing_traces(pid)
239+
assert :end_of_table = TraceService.existing_traces(pid, functions: @all_functions)
230240
end
231241
end
232242
end

0 commit comments

Comments
 (0)