Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added test for named process exit

  • Loading branch information...
commit 874fe8e9fbad7d4d7b9efcb9f1888f2d404e6177 1 parent 7fe16e6
Gianfranco authored
Showing with 30 additions and 3 deletions.
  1. +16 −1 src/audit_collector.erl
  2. +14 −2 test/audit_collector_tests.erl
View
17 src/audit_collector.erl
@@ -75,6 +75,8 @@ options_to_trace_flag([named_receive|R]) ->
[procs,'receive'|options_to_trace_flag(R)];
options_to_trace_flag([named_start|R]) ->
[procs|options_to_trace_flag(R)];
+options_to_trace_flag([named_exit|R]) ->
+ [procs|options_to_trace_flag(R)];
options_to_trace_flag([X|R]) ->
[X|options_to_trace_flag(R)];
options_to_trace_flag([]) -> [].
@@ -152,7 +154,20 @@ make_log([named_start|R],History) ->
Acc++[{started,Name,Name2}]
end
end
- end,[],Started)++make_log(R,History).
+ end,[],Started)++make_log(R,History);
+make_log([named_exit|R],History) ->
+ Registered = registered(History),
+ Exited = make_log(['exit'],History),
+ lists:foldl(
+ fun({'exited',P,Type},Acc) ->
+ case proplists:get_value(P,Registered) of
+ undefined ->
+ Acc;
+ Name -> Acc++[{'exited',Name,Type}]
+ end
+ end,[],Exited)++make_log(R,History).
+
+
registered(History) ->
lists:foldl(
View
16 test/audit_collector_tests.erl
@@ -14,7 +14,8 @@ audit_collector_test_() ->
{"Named Process Send",fun audit_collector_process_named_send/0},
{"Named Process Receive",fun audit_collector_process_named_receive/0},
{"Named Process Starts Process",fun audit_collector_process_named_started/0},
- {"Named Process Starts Named",fun audit_collector_process_named_started_named/0}
+ {"Named Process Starts Named",fun audit_collector_process_named_started_named/0},
+ {"Named Process Exited",fun audit_collector_process_named_exited/0}
]}.
audit_collector_process_send() ->
@@ -141,4 +142,15 @@ audit_collector_process_named_started_named() ->
?assertMatch(
[{started,iName,iStarted}],
audit_collector:review(process,[named_start])).
-
+
+
+audit_collector_process_named_exited() ->
+ process_flag(trap_exit,true),
+ audit_collector:audit(process,[named_exit]),
+ Started = spawn_link(fun() -> register(iName,self()) end),
+ receive {'EXIT',Started,normal} -> ok end,
+ timer:sleep(10),
+ ?assertMatch(
+ [{exited,iName,normal}],
+ audit_collector:review(process,[named_exit])).
+
Please sign in to comment.
Something went wrong with that request. Please try again.