diff --git a/lib/live_debugger/services/trace_service.ex b/lib/live_debugger/services/trace_service.ex index 8432881a6..9588b5f71 100644 --- a/lib/live_debugger/services/trace_service.ex +++ b/lib/live_debugger/services/trace_service.ex @@ -140,42 +140,38 @@ defmodule LiveDebugger.Services.TraceService do ] end - def to_spec([], []), do: [{:"/=", :"$2", nil}] - def to_spec(functions, []) do - [{:andalso, List.first(functions_to_spec(functions)), {:"/=", :"$2", nil}}] - end - - def to_spec([], execution_times) do - [{:andalso, List.first(execution_times_to_spec(execution_times)), {:"/=", :"$2", nil}}] + [{:andalso, functions_to_spec(functions), {:"/=", :"$2", nil}}] end def to_spec(functions, execution_times) do [ {:andalso, - {:andalso, List.first(functions_to_spec(functions)), - List.first(execution_times_to_spec(execution_times))}, {:"/=", :"$2", nil}} + {:andalso, functions_to_spec(functions), execution_times_to_spec(execution_times)}, + {:"/=", :"$2", nil}} ] end - def functions_to_spec([single]), do: [{:"=:=", :"$1", single}] + def functions_to_spec([]), do: false + + def functions_to_spec([single]), do: {:"=:=", :"$1", single} def functions_to_spec([first, second | rest]) do initial_orelse = - {:orelse, List.first(functions_to_spec([first])), List.first(functions_to_spec([second]))} + {:orelse, functions_to_spec([first]), functions_to_spec([second])} result = Enum.reduce(rest, initial_orelse, fn x, acc -> - {:orelse, acc, List.first(functions_to_spec([x]))} + {:orelse, acc, functions_to_spec([x])} end) - [{:andalso, result, {:"/=", :"$2", nil}}] + {:andalso, result, {:"/=", :"$2", nil}} end def execution_times_to_spec(execution_times) do min_time = Keyword.get(execution_times, :exec_time_min, 0) max_time = Keyword.get(execution_times, :exec_time_max, :infinity) - [{:andalso, {:>=, :"$2", min_time}, {:"=<", :"$2", max_time}}] + {:andalso, {:>=, :"$2", min_time}, {:"=<", :"$2", max_time}} end @spec ets_table!(pid :: ets_table_id()) :: :ets.table() diff --git a/test/live_debugger/channel_dashboard_test.exs b/test/live_debugger/channel_dashboard_test.exs index d17f46145..2cef455b9 100644 --- a/test/live_debugger/channel_dashboard_test.exs +++ b/test/live_debugger/channel_dashboard_test.exs @@ -226,6 +226,18 @@ defmodule LiveDebugger.ChannelDashboardTest do "render/1", "mount/3" ]) + |> click(filters_button()) + |> click(checkbox("mount")) + |> click(checkbox("handle_params")) + |> click(checkbox("handle_info")) + |> click(checkbox("handle_call")) + |> click(checkbox("handle_cast")) + |> click(checkbox("terminate")) + |> click(checkbox("render")) + |> click(checkbox("handle_event")) + |> click(checkbox("handle_async")) + |> click(css("button", text: "Apply")) + |> assert_has(traces(count: 0)) end defp assert_traces(session, count, callback_names) do diff --git a/test/services/trace_service_test.exs b/test/services/trace_service_test.exs index 2ca59d659..ed672d8bf 100644 --- a/test/services/trace_service_test.exs +++ b/test/services/trace_service_test.exs @@ -7,6 +7,8 @@ defmodule Services.TraceServiceTest do alias LiveDebugger.Services.TraceService alias LiveDebugger.MockEtsTableServer + @all_functions LiveDebugger.Utils.Callbacks.callbacks_functions() + setup :verify_on_exit! setup_all do @@ -56,7 +58,8 @@ defmodule Services.TraceServiceTest do MockEtsTableServer |> expect(:table!, fn ^pid -> table end) - assert {[^trace1, ^trace2], _} = TraceService.existing_traces(pid) + assert {[^trace1, ^trace2], _} = + TraceService.existing_traces(pid, functions: @all_functions) end test "returns traces with limit and continuation", %{module: module, pid: pid, table: table} do @@ -71,12 +74,13 @@ defmodule Services.TraceServiceTest do MockEtsTableServer |> expect(:table!, fn ^pid -> table end) - {traces1, cont} = TraceService.existing_traces(pid, limit: 2) - {traces2, cont} = TraceService.existing_traces(pid, cont: cont) + {traces1, cont} = TraceService.existing_traces(pid, limit: 2, functions: @all_functions) + {traces2, cont} = TraceService.existing_traces(pid, cont: cont, functions: @all_functions) assert [trace1, trace2] == traces1 assert [trace3] == traces2 assert cont == :end_of_table + assert :end_of_table == TraceService.existing_traces(pid, cont: :end_of_table) end @@ -121,12 +125,14 @@ defmodule Services.TraceServiceTest do assert {[^trace2], _} = TraceService.existing_traces(pid, - execution_times: [exec_time_min: 15, exec_time_max: 50] + execution_times: [exec_time_min: 15, exec_time_max: 50], + functions: @all_functions ) assert {[^trace2, ^trace3], _} = TraceService.existing_traces(pid, - execution_times: [exec_time_min: 15, exec_time_max: :infinity] + execution_times: [exec_time_min: 15, exec_time_max: :infinity], + functions: @all_functions ) end @@ -173,8 +179,11 @@ defmodule Services.TraceServiceTest do MockEtsTableServer |> expect(:table!, 2, fn ^pid -> table end) - assert {[^trace1], _} = TraceService.existing_traces(pid, node_id: pid) - assert {[^trace2, ^trace3], _} = TraceService.existing_traces(pid, node_id: cid) + assert {[^trace1], _} = + TraceService.existing_traces(pid, node_id: pid, functions: @all_functions) + + assert {[^trace2, ^trace3], _} = + TraceService.existing_traces(pid, node_id: cid, functions: @all_functions) end test "returns :end_of_table when no traces match", %{module: module, pid: pid, table: table} do @@ -201,7 +210,7 @@ defmodule Services.TraceServiceTest do MockEtsTableServer |> expect(:table!, fn ^pid -> table end) - assert {[^trace1], _} = TraceService.existing_traces(pid) + assert {[^trace1], _} = TraceService.existing_traces(pid, functions: @all_functions) end end @@ -218,15 +227,16 @@ defmodule Services.TraceServiceTest do MockEtsTableServer |> expect(:table!, 5, fn ^pid -> table end) - assert {[^trace1, ^trace2], _} = TraceService.existing_traces(pid) + assert {[^trace1, ^trace2], _} = + TraceService.existing_traces(pid, functions: @all_functions) TraceService.clear_traces(pid, trace1.pid) - assert {[^trace2], _} = TraceService.existing_traces(pid) + assert {[^trace2], _} = TraceService.existing_traces(pid, functions: @all_functions) TraceService.clear_traces(pid, trace2.cid) - assert :end_of_table = TraceService.existing_traces(pid) + assert :end_of_table = TraceService.existing_traces(pid, functions: @all_functions) end end end