@@ -25,6 +25,7 @@ defmodule LiveDebugger.Services.GarbageCollector.Actions.GarbageCollectingTest d
2525 alive_pids = MapSet . new ( [ pid2 ] )
2626 table1 = make_ref ( )
2727 table2 = make_ref ( )
28+ state = % { to_remove: MapSet . new ( ) }
2829
2930 max_table_size_watched = 50 * @ megabyte_unit
3031 max_table_size_non_watched = 5 * @ megabyte_unit
@@ -39,7 +40,8 @@ defmodule LiveDebugger.Services.GarbageCollector.Actions.GarbageCollectingTest d
3940 MockBus
4041 |> expect ( :broadcast_event! , 2 , fn % TableTrimmed { } -> :ok end )
4142
42- assert true == GarbageCollectingActions . garbage_collect_traces! ( watched_pids , alive_pids )
43+ assert MapSet . new ( ) ==
44+ GarbageCollectingActions . garbage_collect_traces! ( state , watched_pids , alive_pids )
4345 end
4446
4547 test "does not collect garbage if max size not exceeded" do
@@ -49,6 +51,7 @@ defmodule LiveDebugger.Services.GarbageCollector.Actions.GarbageCollectingTest d
4951 alive_pids = MapSet . new ( [ pid2 ] )
5052 table1 = make_ref ( )
5153 table2 = make_ref ( )
54+ state = % { to_remove: MapSet . new ( ) }
5255
5356 MockAPITracesStorage
5457 |> expect ( :get_all_tables , fn -> [ { pid1 , table1 } , { pid2 , table2 } ] end )
@@ -59,44 +62,75 @@ defmodule LiveDebugger.Services.GarbageCollector.Actions.GarbageCollectingTest d
5962 MockBus
6063 |> deny ( :broadcast_event! , 2 )
6164
62- assert false == GarbageCollectingActions . garbage_collect_traces! ( watched_pids , alive_pids )
65+ assert MapSet . new ( ) ==
66+ GarbageCollectingActions . garbage_collect_traces! ( state , watched_pids , alive_pids )
6367 end
6468
65- test "deletes table if not watched and no alive" do
69+ test "marks for removal if not watched and not alive" do
6670 watched_pids = MapSet . new ( )
6771 alive_pids = MapSet . new ( )
6872 pid1 = :c . pid ( 0 , 11 , 0 )
6973 table1 = make_ref ( )
74+ state = % { to_remove: MapSet . new ( [ ] ) }
75+
76+ expect ( MockAPITracesStorage , :get_all_tables , fn -> [ { pid1 , table1 } ] end )
77+
78+ assert MapSet . new ( [ pid1 ] ) ==
79+ GarbageCollectingActions . garbage_collect_traces! ( state , watched_pids , alive_pids )
80+ end
81+
82+ test "deletes table if not watched, not alive and marked to remove" do
83+ watched_pids = MapSet . new ( )
84+ alive_pids = MapSet . new ( )
85+ pid1 = :c . pid ( 0 , 11 , 0 )
86+ table1 = make_ref ( )
87+ state = % { to_remove: MapSet . new ( [ pid1 ] ) }
7088
7189 expect ( MockAPITracesStorage , :get_all_tables , fn -> [ { pid1 , table1 } ] end )
7290 expect ( MockAPITracesStorage , :delete_table! , fn ^ table1 -> :ok end )
7391 expect ( MockBus , :broadcast_event! , fn % TableDeleted { } -> :ok end )
7492
75- assert true == GarbageCollectingActions . garbage_collect_traces! ( watched_pids , alive_pids )
93+ assert MapSet . new ( ) ==
94+ GarbageCollectingActions . garbage_collect_traces! ( state , watched_pids , alive_pids )
7695 end
7796 end
7897
7998 describe "garbage_collect_states!/1" do
80- test "collects garbage for states if pids are not watched and not alive" do
99+ test "marks for removal if not watched and not alive" do
81100 pid1 = :c . pid ( 0 , 12 , 0 )
82101 watched_pids = MapSet . new ( [ :c . pid ( 0 , 11 , 0 ) ] )
83102 alive_pids = MapSet . new ( [ :c . pid ( 0 , 13 , 0 ) ] )
103+ state = % { to_remove: MapSet . new ( ) }
104+
105+ MockAPIStatesStorage
106+ |> expect ( :get_all_states , fn -> [ { pid1 , :some_state } ] end )
107+
108+ assert MapSet . new ( [ pid1 ] ) ==
109+ GarbageCollectingActions . garbage_collect_states! ( state , watched_pids , alive_pids )
110+ end
111+
112+ test "deletes states if not watched, not alive and marked for removal " do
113+ pid1 = :c . pid ( 0 , 12 , 0 )
114+ watched_pids = MapSet . new ( [ :c . pid ( 0 , 11 , 0 ) ] )
115+ alive_pids = MapSet . new ( [ :c . pid ( 0 , 13 , 0 ) ] )
116+ state = % { to_remove: MapSet . new ( [ pid1 ] ) }
84117
85118 MockAPIStatesStorage
86119 |> expect ( :get_all_states , fn -> [ { pid1 , :some_state } ] end )
87120 |> expect ( :delete! , fn ^ pid1 -> :ok end )
88121
89- MockBus
90- |> expect ( :broadcast_event! , fn % TableTrimmed { } -> :ok end )
122+ expect ( MockBus , :broadcast_event! , fn % TableTrimmed { } -> :ok end )
91123
92- assert true == GarbageCollectingActions . garbage_collect_states! ( watched_pids , alive_pids )
124+ assert MapSet . new ( ) ==
125+ GarbageCollectingActions . garbage_collect_states! ( state , watched_pids , alive_pids )
93126 end
94127
95- test "does not collect garbage for states if pids are watched or alive" do
128+ test "do nothing if pids are watched or alive" do
96129 pid1 = :c . pid ( 0 , 12 , 0 )
97130 pid2 = :c . pid ( 0 , 13 , 0 )
98131 watched_pids = MapSet . new ( [ pid1 ] )
99132 alive_pids = MapSet . new ( [ pid2 ] )
133+ state = % { to_remove: MapSet . new ( ) }
100134
101135 MockAPIStatesStorage
102136 |> expect ( :get_all_states , fn -> [ { pid1 , :some_state } , { pid2 , :some_other_state } ] end )
@@ -105,7 +139,8 @@ defmodule LiveDebugger.Services.GarbageCollector.Actions.GarbageCollectingTest d
105139 MockBus
106140 |> deny ( :broadcast_event! , 1 )
107141
108- assert false == GarbageCollectingActions . garbage_collect_states! ( watched_pids , alive_pids )
142+ assert MapSet . new ( ) ==
143+ GarbageCollectingActions . garbage_collect_states! ( state , watched_pids , alive_pids )
109144 end
110145 end
111146end
0 commit comments