Permalink
Browse files

Added message consumption test

  • Loading branch information...
1 parent e413f0f commit c438dbdba23f3e49b63361b79e32bb7593dc3be5 Gianfranco committed Jun 30, 2011
Showing with 55 additions and 1 deletion.
  1. +16 −0 src/frame_axiom.erl
  2. +39 −1 test/frame_axiom_tests.erl
View
@@ -103,6 +103,10 @@ snapshot(Ets,process,replaced_named) ->
snapshot(Ets,process,received_messages) ->
MessagesWithPids = messages_with_pids(),
ets:insert(Ets,{{process,received_messages},MessagesWithPids}),
+ Ets;
+snapshot(Ets,process,consumed_messages) ->
+ MessagesWithPids = messages_with_pids(),
+ ets:insert(Ets,{{process,consumed_messages},MessagesWithPids}),
Ets.
diff(Ets,[X]) ->
@@ -209,6 +213,18 @@ diff(Ets,process,received_messages) ->
[] -> Acc;
X -> Acc++[{received,RecPid,X}]
end
+ end,[],RecordedWithPid);
+diff(Ets,process,consumed_messages) ->
+ MessagesWithPids = messages_with_pids(),
+ Key = {process,consumed_messages},
+ [{Key,RecordedWithPid}] = ets:lookup(Ets,Key),
+ lists:foldl(
+ fun({RecPid,RecMessages},Acc) ->
+ OldMessages = proplists:get_value(RecPid,MessagesWithPids),
+ case [R||R<-RecMessages,not lists:member(R,OldMessages)] of
+ [] -> Acc;
+ X -> Acc++[{consumed,RecPid,X}]
+ end
end,[],RecordedWithPid).
View
@@ -48,7 +48,23 @@ process_mailbox_received_test() ->
Message = {iMessage,make_ref()},
Pid ! Message,
?assertEqual([{received,Pid,[Message]}],
- frame_axiom:diff(Ref,[{process,Options}])).
+ frame_axiom:diff(Ref,[{process,Options}])),
+ synchronoulsy_kill_process(Pid).
+
+process_consumed_messages_test() ->
+ Options = [consumed_messages],
+ Pid = synchronoulsy_start_a_synchronous_consumer_process(),
+ Message = {iMessage,make_ref()},
+ Pid ! Message,
+ Ref = frame_axiom:snapshot([{process,Options}]),
+ Pid ! consume,
+ receive
+ {Pid,consumed,Message} -> ok
+ end,
+ ?assertEqual([{consumed,Pid,[Message]}],
+ frame_axiom:diff(Ref,[{process,Options}])),
+ synchronoulsy_kill_process(Pid).
+
named_process_creation_diff_test() ->
Options = [creation_named],
@@ -351,6 +367,28 @@ synchronoulsy_start_a_process() ->
end,
Pid.
+synchronoulsy_start_a_synchronous_consumer_process() ->
+ SharedSecret = make_ref(),
+ Master = self(),
+ F = fun(F) ->
+ Master ! SharedSecret,
+ receive
+ die -> ok;
+ consume ->
+ receive
+ X ->
+ Master ! {self(),consumed,X},
+ F(F)
+ end
+ end
+ end,
+ Pid = spawn_link(fun() ->F(F)end),
+ receive
+ SharedSecret ->
+ ok
+ end,
+ Pid.
+
synchronoulsy_kill_process(Pid) ->
Pid ! die,

0 comments on commit c438dbd

Please sign in to comment.