Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Change to new interface

  • Loading branch information...
commit 7798e7029daa205f89e126ad8940e34229ac4f2b 1 parent 6f562ab
Gianfranco authored
Showing with 55 additions and 52 deletions.
  1. +6 −29 src/frame_axiom.erl
  2. +49 −23 test/frame_axiom_tests.erl
View
35 src/frame_axiom.erl
@@ -31,9 +31,7 @@
snapshot({D,Path}) when D == dir_detailed ;
D == dir ->
snapshot(ets:new(snapshot,[private]),{D,Path});
-snapshot(SnapShot) when SnapShot == application;
- SnapShot == ets;
- SnapShot == port;
+snapshot(SnapShot) when SnapShot == port;
SnapShot == node;
SnapShot == named_process ->
snapshot(ets:new(snapshot,[private]),SnapShot);
@@ -41,6 +39,9 @@ snapshot(SnapShots) when is_list(SnapShots) ->
lists:foldl(fun(SnapShot,Ets) -> snapshot(Ets,SnapShot)
end,ets:new(snapshot,[private]),SnapShots).
+snapshot(Ets,SnapSpecs) when is_list(SnapSpecs) ->
+ lists:foldl(fun(SnapSpec,Res) -> snapshot(Res,SnapSpec) end,
+ Ets,SnapSpecs);
snapshot(Ets,{process,Options}) when is_list(Options) ->
lists:foldl(fun(Option,EtsAcc) -> snapshot(EtsAcc,process,Option)
end,Ets,Options);
@@ -57,15 +58,6 @@ snapshot(Ets,{ets,Options}) when is_list(Options) ->
lists:foldl(fun(Option,EtsAcc) -> snapshot(EtsAcc,ets,Option)
end,Ets,Options);
-snapshot(Ets,process) ->
- Processes = erlang:processes(),
- ets:insert(Ets,{process,Processes}),
- Ets;
-snapshot(Ets,application) ->
- Running = application:which_applications(),
- Loaded = application:loaded_applications(),
- ets:insert(Ets,{application,Running,Loaded}),
- Ets;
snapshot(Ets,ets) ->
Existing = ets:all(),
ets:insert(Ets,{ets,Existing}),
@@ -144,9 +136,8 @@ snapshot(Ets,ets,deletion) ->
diff(Ets,[X]) ->
diff(Ets,X);
diff(Ets,DiffSpecs) when is_list(DiffSpecs) ->
- lists:foldl(fun(DiffSpec,Res) ->
- Key = diffspec_key(DiffSpec),
- Res++[{Key,diff(Ets,DiffSpec)}]
+ lists:foldl(fun({DiffType,Options},Res) ->
+ Res++[{DiffType,diff(Ets,{DiffType,Options})}]
end,[],DiffSpecs);
diff(Ets,{process,all}) ->
diff(Ets,{process,all(process)});
@@ -164,11 +155,6 @@ diff(Ets,{ets,Options}) when is_list(Options) ->
lists:foldl(fun(Option,Res) -> Res++diff(Ets,ets,Option)
end,[],Options);
-diff(Ets,process) ->
- Processes = erlang:processes(),
- [{process,Recorded}] = ets:lookup(Ets,process),
- {Dead,Created} = split(created,died,Processes,Recorded),
- Dead++Created;
diff(Ets,ets) ->
Current = ets:all(),
[{ets,Recorded}] = ets:lookup(Ets,ets),
@@ -195,12 +181,6 @@ diff(Ets,node) ->
{Connected,Disconnected} = split(connected,disconnected,Current,Recorded),
Connected++Disconnected.
-diff(Ets,application,start_stop) ->
- Running = application:which_applications(),
- [{application,Recorded,_}] = ets:lookup(Ets,application),
- Started = [{started,hd(tuple_to_list(App))} ||App <- Running, not lists:member(App,Recorded)],
- Stopped = [{stopped,hd(tuple_to_list(App))} ||App <- Recorded, not lists:member(App,Running)],
- Started++Stopped;
diff(Ets,process,creation) ->
CurrentPids = erlang:processes(),
Key = {process,creation},
@@ -325,9 +305,6 @@ collect(ExactP,Path) ->
end
end.
-diffspec_key({application,_}) ->
- application;
-diffspec_key(X) -> X.
split(KeyA,KeyB,As,Bs) ->
{[{KeyA,A}||A<-As,not lists:member(A,Bs)],
View
72 test/frame_axiom_tests.erl
@@ -51,6 +51,7 @@ process_mailbox_received_test() ->
frame_axiom:diff(Ref,[{process,Options}])).
process_consumed_messages_test() ->
+ timer:sleep(300), %% Let the Eunit processes settle in peace
Options = [consumed_messages],
Pid = synchronoulsy_start_a_synchronous_consumer_process(),
Message = {iMessage,make_ref()},
@@ -93,6 +94,7 @@ all_no_change_diff_test() ->
?assertEqual([],frame_axiom:diff(Ref,[{process,Options}])).
all_change_diff_test() ->
+ timer:sleep(300), %% Let the Eunit processes settle in peace
process_flag(trap_exit,true),
Options = all,
Killed = synchronoulsy_start_a_process(),
@@ -127,7 +129,9 @@ all_change_diff_test() ->
{died,named_process_b},
{replaced,named_process_c}
],
- frame_axiom:diff(Ref,[{process,Options}])).
+ frame_axiom:diff(Ref,[{process,Options}])),
+ synchronoulsy_kill_process(NamedCreated),
+ synchronoulsy_kill_process(Replacer).
%% application
@@ -309,8 +313,13 @@ node_disconnected_diff_test() ->
%% multiple type snapshot
%% ---------------------------------------------------------
multiple_type_creation_test() ->
- Ref = frame_axiom:snapshot([process,application,ets]),
- Pid = spawn_link(fun() -> receive _ -> ok end end),
+ P_Options = [creation],
+ A_Options = [started],
+ E_Options = [creation],
+ Ref = frame_axiom:snapshot([{process,P_Options},
+ {application,A_Options},
+ {ets,E_Options}]),
+ Pid = synchronoulsy_start_a_process(),
application:start(snmp),
Ets = ets:new(created,[]),
?assertMatch([
@@ -318,19 +327,24 @@ multiple_type_creation_test() ->
{application,[{started,snmp}]},
{ets,[{created,Ets}]}
],
- frame_axiom:diff(Ref,[process,
- {application,[start_stop]},
- ets
+ frame_axiom:diff(Ref,[{process,P_Options},
+ {application,A_Options},
+ {ets,E_Options}
])),
application:stop(snmp),
ets:delete(Ets),
synchronoulsy_kill_process(Pid).
multiple_type_deletion_test() ->
- Pid = spawn_link(fun() -> receive _ -> ok end end),
+ P_Options = [death],
+ A_Options = [stopped],
+ E_Options = [deletion],
+ Pid = synchronoulsy_start_a_process(),
application:start(snmp),
Ets = ets:new(created,[]),
- Ref = frame_axiom:snapshot([process,application,ets]),
+ Ref = frame_axiom:snapshot([{process,P_Options},
+ {application,A_Options},
+ {ets,E_Options}]),
application:stop(snmp),
ets:delete(Ets),
synchronoulsy_kill_process(Pid),
@@ -339,41 +353,53 @@ multiple_type_deletion_test() ->
{application,[{stopped,snmp}]},
{ets,[{deleted,Ets}]}
],
- frame_axiom:diff(Ref,[process,
- {application,[start_stop]},
- ets])).
+ frame_axiom:diff(Ref,[{process,P_Options},
+ {application,A_Options},
+ {ets,E_Options}])).
multiple_type_mixed_test() ->
+ P_Options = [creation],
+ E_Options = [deletion],
Ets = ets:new(created,[]),
- Ref = frame_axiom:snapshot([process,ets]),
- Pid = spawn_link(fun() -> receive _ -> ok end end),
+ Ref = frame_axiom:snapshot([{process,P_Options},
+ {ets,E_Options}]),
+ Pid = synchronoulsy_start_a_process(),
ets:delete(Ets),
?assertMatch([
{process,[{created,Pid}]},
{ets,[{deleted,Ets}]}
],
- frame_axiom:diff(Ref,[process,ets])),
+ frame_axiom:diff(Ref,[{process,P_Options},
+ {ets,E_Options}])),
synchronoulsy_kill_process(Pid).
-multiple_type_no_change_test() ->
- Ref = frame_axiom:snapshot([process,ets]),
- ?assertEqual([{process,[]},{ets,[]}],frame_axiom:diff(Ref,[process,ets])).
+multiple_type_no_change_test() ->
+ Ref = frame_axiom:snapshot([{application,all},
+ {ets,all}]),
+ ?assertEqual([{application,[]},{ets,[]}],
+ frame_axiom:diff(Ref,[{application,all},
+ {ets,all}])).
%% multiple calls to snapshot
%% ---------------------------------------------------------
second_snapshot_call_test() ->
- Ref = frame_axiom:snapshot(ets),
+ E_Options = [creation],
+ A_Options = [started],
+ Ref = frame_axiom:snapshot([{ets,E_Options}]),
Ets = ets:new(test,[]),
- frame_axiom:snapshot(Ref,application),
+ frame_axiom:snapshot(Ref,[{application,A_Options}]),
application:start(snmp),
?assertEqual([{ets,[{created,Ets}]},
- {application,[{started,snmp}]}
- ],
- frame_axiom:diff(Ref,[ets,{application,[start_stop]}])).
+ {application,[{started,snmp}]}
+ ],
+ frame_axiom:diff(Ref,[{ets,E_Options},
+ {application,A_Options}])),
+ application:stop(snmp).
successive_snapshots_of_same_resets_test() ->
- Ref = frame_axiom:snapshot(ets),
+ E_Options = all,
+ Ref = frame_axiom:snapshot([{ets,E_Options}]),
Ets = ets:new(a,[]),
frame_axiom:snapshot(Ref,ets),
?assertEqual([],frame_axiom:diff(Ref,ets)),
Please sign in to comment.
Something went wrong with that request. Please try again.