Skip to content

Commit

Permalink
Added test and implementation for named starting another process
Browse files Browse the repository at this point in the history
  • Loading branch information
Gianfranco committed Jul 8, 2011
1 parent c567948 commit ffa6bec
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
16 changes: 15 additions & 1 deletion src/audit_collector.erl
Expand Up @@ -74,6 +74,8 @@ options_to_trace_flag([named_send|R]) ->
[procs,send|options_to_trace_flag(R)];
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([X|R]) ->
[X|options_to_trace_flag(R)];
options_to_trace_flag([]) -> [].
Expand Down Expand Up @@ -135,7 +137,19 @@ make_log([named_receive|R],History) ->
Acc;
Name -> Acc++[{'receive',Name,Msg}]
end
end,[],Received)++make_log(R,History).
end,[],Received)++make_log(R,History);
make_log([named_start|R],History) ->
Registered = registered(History),
Started = make_log([start],History),
lists:foldl(
fun({started,P,P2},Acc) ->
case proplists:get_value(P,Registered) of
undefined ->
Acc;
Name ->
Acc++[{started,Name,P2}]
end
end,[],Started)++make_log(R,History).

registered(History) ->
lists:foldl(
Expand Down
17 changes: 16 additions & 1 deletion test/audit_collector_tests.erl
Expand Up @@ -12,7 +12,8 @@ audit_collector_test_() ->
fun audit_collector_process_exited/0,
fun audit_collector_process_exited_deep/0,
fun audit_collector_process_named_send/0,
fun audit_collector_process_named_receive/0
fun audit_collector_process_named_receive/0,
fun audit_collector_process_named_started/0
]}.

audit_collector_process_send() ->
Expand Down Expand Up @@ -104,3 +105,17 @@ audit_collector_process_named_receive() ->
?assertMatch(
[{'receive',iName,die}],
audit_collector:review(process,[named_receive])).

audit_collector_process_named_started() ->
audit_collector:audit(process,[named_start]),
Self = self(),
Started = spawn(fun() ->
register(iName,self()),
Startee = spawn(lists,reverse,[[1,2,3]]),
Self ! {started,Startee} end),
{started,Startee} = receive X -> X end,
timer:sleep(10),
?assertMatch(
[{started,iName,Startee}],
audit_collector:review(process,[named_start])).

0 comments on commit ffa6bec

Please sign in to comment.