Permalink
Browse files

Added process exit test, one level deep

  • Loading branch information...
Gianfranco
Gianfranco committed Jul 7, 2011
1 parent 50cefbd commit c40d2de62a86ab7bb93414269f2f56fce7df7b0a
Showing with 25 additions and 2 deletions.
  1. +11 −1 src/audit_collector.erl
  2. +14 −1 test/audit_collector_tests.erl
View
@@ -54,7 +54,7 @@ handle_call({review,{process,Options}},_,State) ->
handle_cast(_Msg, State) ->
{noreply, State}.
-handle_info(X, State) ->
+handle_info(X, State) ->
{noreply, State#state{log = [X|State#state.log]}}.
terminate(_Reason, _State) ->
@@ -68,6 +68,8 @@ code_change(_OldVsn, State, _Extra) ->
%%%===================================================================
options_to_trace_flag([start|R]) ->
[procs,set_on_spawn|options_to_trace_flag(R)];
+options_to_trace_flag([exit|R]) ->
+ [procs,set_on_spawn|options_to_trace_flag(R)];
options_to_trace_flag([X|R]) ->
[X|options_to_trace_flag(R)];
options_to_trace_flag([]) -> [].
@@ -100,4 +102,12 @@ make_log([start|R],History) ->
fun({trace_ts,P,spawn,P2,{_M,_F,_A},_},Acc) ->
Acc++[{started,P,P2}];
(_,Acc) -> Acc
+ end,[],History)++make_log(R,History);
+make_log([exit|R],History) ->
+ lists:foldl(
+ fun({trace_ts,P,exit,C,_},Acc) ->
+ Acc++[{exited,P,C}];
+ (_,Acc) ->
+ Acc
end,[],History)++make_log(R,History).
+
@@ -8,7 +8,8 @@ audit_collector_test_() ->
[
fun audit_collector_process_send/0,
fun audit_collector_process_receive/0,
- fun audit_collector_process_started/0
+ fun audit_collector_process_started/0,
+ fun audit_collector_process_exited/0
]}.
audit_collector_process_send() ->
@@ -41,3 +42,15 @@ audit_collector_process_started() ->
[{started,Started,Startee}],
audit_collector:review(process,[start])).
+audit_collector_process_exited() ->
+ process_flag(trap_exit,true),
+ audit_collector:audit(process,[exit]),
+ Started = spawn_link(fun() -> hello end),
+ receive
+ {'EXIT',Started,normal} ->
+ ok
+ end,
+ timer:sleep(10),
+ ?assertMatch(
+ [{exited,Started,normal}],
+ audit_collector:review(process,[exit])).

0 comments on commit c40d2de

Please sign in to comment.