Permalink
Browse files

- add log action to <match> (TSUN-94)

- add userid dyn_variable (TSUN-95)

SVN Revision: 953
  • Loading branch information...
1 parent baf5694 commit 17a817873469b0fe877b6b75e8b3680d51688ead @nniclausse nniclausse committed Nov 23, 2008
View
@@ -20,12 +20,14 @@ o J
o Jason Tucker: Solaris testing and fixes, jabber patches (sip_digest,
roster and presence enhancements, bidi support for presence:subscribe ).
-o Pablo Polvorin: LDAP plugin, set_dynvars, xpath search for html.
+o Pablo Polvorin: LDAP plugin, set_dynvars, xpath search for html,
+ for/repeat loop, dynvars_api, hibernate.
o Gregoire Reboul: MySQL plugin.
+o Dimitri Fontaine: SNMP & postgresql testing, patch for snmp, tsung-plotter
+
o Jonathan Bresler: Jabber testing and bug reporting
-o Dimitri Fontaine: SNMP & postgresql testing, patch for snmp.
o Gordon Guthrie: tips for ssh setup on Suse
o Romain Lenglet: Suggestions for ts_os_mon
o Johann Messner: Bug reports
View
@@ -92,6 +92,7 @@
% all the response to do pattern matching)
session, % record of session status; depends on 'clienttype'
datasize=0,
+ id, % user id
size_mon_thresh=?size_mon_thresh, % if rcv data is > to this, update stats
dyndata=[], % persistent data dynamically added during the
% session (Cookies for examples)
@@ -34,12 +34,12 @@ config_get_session_test() ->
ts_user_server:start([]),
ts_config_server:start_link(["/tmp"]),
ok = ts_config_server:read_config("./examples/http_setdynvars.xml"),
- {ok, {Session,IP,Server} } = ts_config_server:get_next_session("localhost"),
+ {ok, {Session,IP,Server,1} } = ts_config_server:get_next_session("localhost"),
?assertEqual(1, Session#session.id).
config_get_session_size_test() ->
myset_env(),
- {ok, {Session,IP,Server} } = ts_config_server:get_next_session("localhost"),
+ {ok, {Session,IP,Server,2} } = ts_config_server:get_next_session("localhost"),
?assertEqual(13, Session#session.size).
@@ -57,13 +57,13 @@ read_config_thinkfirst_test() ->
config_minmax_test() ->
myset_env(),
- {ok, {Session,IP,Server} } = ts_config_server:get_next_session("localhost"),
+ {ok, {Session,IP,Server,3} } = ts_config_server:get_next_session("localhost"),
Id = Session#session.id,
?assertMatch({thinktime,{range,2000,4000}}, ts_config_server:get_req(Id,7)).
config_minmax2_test() ->
myset_env(),
- {ok, {Session,IP,Server} } = ts_config_server:get_next_session("localhost"),
+ {ok, {Session,IP,Server,4} } = ts_config_server:get_next_session("localhost"),
Id = Session#session.id,
{thinktime, Req} = ts_config_server:get_req(Id,7),
Think=ts_client:set_thinktime(Req),
@@ -75,7 +75,7 @@ config_minmax2_test() ->
config_thinktime_test() ->
myset_env(),
ok = ts_config_server:read_config("./examples/thinks.xml"),
- {ok, {Session,IP,Server} } = ts_config_server:get_next_session("localhost"),
+ {ok, {Session,IP,Server,5} } = ts_config_server:get_next_session("localhost"),
Id = Session#session.id,
{thinktime, Req=2000} = ts_config_server:get_req(Id,5),
{thinktime, 2000} = ts_config_server:get_req(Id,7),
@@ -89,7 +89,7 @@ config_thinktime_test() ->
config_thinktime2_test() ->
myset_env(),
ok = ts_config_server:read_config("./examples/thinks2.xml"),
- {ok, {Session,IP,Server} } = ts_config_server:get_next_session("localhost"),
+ {ok, {Session,IP,Server,6} } = ts_config_server:get_next_session("localhost"),
Id = Session#session.id,
{thinktime, Req} = ts_config_server:get_req(Id,5),
Ref=ts_client:set_thinktime(Req),
View
@@ -16,89 +16,92 @@
-define(MAX_COUNT,42).
-define(COUNT,5).
+-define(USER_ID,2).
+-define(SESSION_ID,1).
+-define(COUNTS,{5,42,2,1}).
test()->
ok.
match_abort_ok_test() ->
myset_env(),
Data="C'est n'est pas une chaine de caractere",
- ?assertMatch(?COUNT, ts_search:match([#match{regexp="Erreur", do=abort, 'when'=match}],Data, {?COUNT,?MAX_COUNT})).
+ ?assertMatch(?COUNT, ts_search:match([#match{regexp="Erreur", do=abort, 'when'=match}],Data, ?COUNTS)).
match_abort_nok_test() ->
myset_env(),
Data="Ceci est une Erreur",
- ?assertMatch(0, ts_search:match([#match{regexp="Erreur", do=abort, 'when'=match}],Data, {?COUNT,?MAX_COUNT})).
+ ?assertMatch(0, ts_search:match([#match{regexp="Erreur", do=abort, 'when'=match}],Data, ?COUNTS)).
nomatch_abort_ok_test() ->
myset_env(),
Data="C'est n'est pas une chaine de caractere",
- ?assertMatch(0, ts_search:match([#match{regexp="Erreur", do=abort, 'when'=nomatch}],Data, {?COUNT,?MAX_COUNT})).
+ ?assertMatch(0, ts_search:match([#match{regexp="Erreur", do=abort, 'when'=nomatch}],Data, ?COUNTS)).
nomatch_abort_nok_test() ->
myset_env(),
Data="Ceci est une Erreur",
- ?assertMatch(?COUNT, ts_search:match([#match{regexp="Erreur", do=abort, 'when'=nomatch}],Data, {?COUNT,?MAX_COUNT})).
+ ?assertMatch(?COUNT, ts_search:match([#match{regexp="Erreur", do=abort, 'when'=nomatch}],Data, ?COUNTS)).
nomatch_continue_ok_test() ->
myset_env(),
Data="C'est n'est pas une chaine de caractere",
- ?assertMatch(?COUNT, ts_search:match([#match{regexp="Erreur", do=continue, 'when'=nomatch}],Data, {?COUNT,?MAX_COUNT})).
+ ?assertMatch(?COUNT, ts_search:match([#match{regexp="Erreur", do=continue, 'when'=nomatch}],Data, ?COUNTS)).
nomatch_continue_nok_test() ->
myset_env(),
Data="Ceci est une Erreur",
- ?assertMatch(?COUNT, ts_search:match([#match{regexp="Erreur", do=continue, 'when'=nomatch}],Data, {?COUNT,?MAX_COUNT})).
+ ?assertMatch(?COUNT, ts_search:match([#match{regexp="Erreur", do=continue, 'when'=nomatch}],Data, ?COUNTS)).
match_continue_ok_test() ->
myset_env(),
Data="C'est n'est pas une chaine de caractere",
- ?assertMatch(?COUNT, ts_search:match([#match{regexp="Erreur", do=continue, 'when'=match}],Data, {?COUNT,?MAX_COUNT})).
+ ?assertMatch(?COUNT, ts_search:match([#match{regexp="Erreur", do=continue, 'when'=match}],Data, ?COUNTS)).
match_continue_nok_test() ->
myset_env(),
Data="Ceci est une Erreur",
- ?assertMatch(?COUNT, ts_search:match([#match{regexp="Erreur", do=continue, 'when'=match}],Data, {?COUNT,?MAX_COUNT})).
+ ?assertMatch(?COUNT, ts_search:match([#match{regexp="Erreur", do=continue, 'when'=match}],Data, ?COUNTS)).
nomatch_loop_ok_test() ->
myset_env(),
Data="C'est n'est pas une chaine de caractere",
- ?assertMatch(?COUNT+1, ts_search:match([#match{regexp="Erreur", do=loop, max_loop=?COUNT, loop_back=0, sleep_loop=1,'when'=nomatch}],Data, {?COUNT,?MAX_COUNT})).
+ ?assertMatch(?COUNT+1, ts_search:match([#match{regexp="Erreur", do=loop, max_loop=?COUNT, loop_back=0, sleep_loop=1,'when'=nomatch}],Data, ?COUNTS)).
nomatch_loop_nok_test() ->
myset_env(),
Data="Ceci est une Erreur",
- ?assertMatch(?COUNT, ts_search:match([#match{regexp="Erreur", do=loop, max_loop=?COUNT, loop_back=0, sleep_loop=1,'when'=nomatch}],Data, {?COUNT,?MAX_COUNT})).
+ ?assertMatch(?COUNT, ts_search:match([#match{regexp="Erreur", do=loop, max_loop=?COUNT, loop_back=0, sleep_loop=1,'when'=nomatch}],Data, ?COUNTS)).
match_loop_ok_test() ->
myset_env(),
Data="C'est n'est pas une chaine de caractere",
- ?assertMatch(?COUNT, ts_search:match([#match{regexp="Erreur", do=loop, max_loop=?COUNT, loop_back=0, sleep_loop=1,'when'=match}],Data, {?COUNT,?MAX_COUNT})).
+ ?assertMatch(?COUNT, ts_search:match([#match{regexp="Erreur", do=loop, max_loop=?COUNT, loop_back=0, sleep_loop=1,'when'=match}],Data, ?COUNTS)).
match_loop_nok_test() ->
myset_env(),
Data="Ceci est une Erreur",
- ?assertMatch(?COUNT+1, ts_search:match([#match{regexp="Erreur", do=loop, max_loop=?COUNT, loop_back=0, sleep_loop=1, 'when'=match}],Data, {?COUNT,?MAX_COUNT})).
+ ?assertMatch(?COUNT+1, ts_search:match([#match{regexp="Erreur", do=loop, max_loop=?COUNT, loop_back=0, sleep_loop=1, 'when'=match}],Data, ?COUNTS)).
nomatch_restart_ok_test() ->
myset_env(),
Data="C'est n'est pas une chaine de caractere",
- ?assertMatch(?MAX_COUNT, ts_search:match([#match{regexp="Erreur", do=restart, max_restart=?COUNT,'when'=nomatch}],Data, {?COUNT,?MAX_COUNT})).
+ ?assertMatch(?MAX_COUNT, ts_search:match([#match{regexp="Erreur", do=restart, max_restart=?COUNT,'when'=nomatch}],Data, ?COUNTS)).
nomatch_restart_nok_test() ->
myset_env(),
Data="Ceci est une Erreur",
- ?assertMatch(?COUNT, ts_search:match([#match{regexp="Erreur", do=restart, max_restart=?COUNT,'when'=nomatch}],Data, {?COUNT,?MAX_COUNT})).
+ ?assertMatch(?COUNT, ts_search:match([#match{regexp="Erreur", do=restart, max_restart=?COUNT,'when'=nomatch}],Data, ?COUNTS)).
match_restart_ok_test() ->
myset_env(),
Data="C'est n'est pas une chaine de caractere",
- ?assertMatch(?COUNT, ts_search:match([#match{regexp="Erreur", do=restart, max_restart=?COUNT,'when'=match}],Data, {?COUNT,?MAX_COUNT})).
+ ?assertMatch(?COUNT, ts_search:match([#match{regexp="Erreur", do=restart, max_restart=?COUNT,'when'=match}],Data, ?COUNTS)).
match_restart_nok_test() ->
myset_env(),
Data="Ceci est une Erreur",
- ?assertMatch(?MAX_COUNT, ts_search:match([#match{regexp="Erreur", do=restart, max_restart=?COUNT, 'when'=match}],Data, {?COUNT,?MAX_COUNT})).
+ ?assertMatch(?MAX_COUNT, ts_search:match([#match{regexp="Erreur", do=restart, max_restart=?COUNT, 'when'=match}],Data, ?COUNTS)).
myset_env()->
myset_env(0).
@@ -181,6 +181,14 @@ parse_extract_fun2_test() ->
Data="/stuff/%%ts_test_search:namespace%%/%%ts_test_search:marketplace%%/%%ts_test_search:sessionBucket%%/01/2000?keyA1=dataA1&amp;keyB1=dataB1",
?assertMatch("/stuff/namespace2/6/91/01/2000?keyA1=dataA1&amp;keyB1=dataB1", ts_search:subst(Data,[])).
+parse_subst_var_fun_test() ->
+ myset_env(),
+ Data=?FORMDATA,
+ StrName="jsf_tree_64",
+ Regexp = ?DEF_REGEXP_DYNVAR_BEGIN++ StrName ++?DEF_REGEXP_DYNVAR_END,%'
+ [{Name,Value}] = ts_search:parse_dynvar([{regexp, 'jsf_tree_64', Regexp }],list_to_binary(Data)),
+ ?assertMatch("H4sIAAAAAAAAAK1VS2/TQBBeo+kalCKAA-MSFT", ts_search:subst("%%_jsf_tree_64%%-%%ts_test_search:new%%",[{Name,Value}])).
+
dynvars_urandom_test() ->
myset_env(),
?assertMatch(["qxvmvtglimieyhemzlxc"],ts_client:set_dynvars(urandom,{string,20},[toto],[])).
View
@@ -49,13 +49,15 @@
%%% API
%%%----------------------------------------------------------------------
+%% @spec start(Opts::{Session::#session{},IP::tuple(),Server::#server{}},
+%% Id::integer()) -> {ok, Pid::pid()} | ignore | {error, Error::term()}
%% @doc Start a new session
start(Opts) ->
?DebugF("Starting with opts: ~p~n",[Opts]),
gen_fsm:start_link(?MODULE, Opts, []).
%%----------------------------------------------------------------------
-%% next/1
+%% @spec next({pid()}) -> ok
%% @doc Purpose: continue with the next request (used for global ack)
%% @end
%%----------------------------------------------------------------------
@@ -79,12 +81,14 @@ init({#session{id = SessionId,
hibernate = Hibernate,
proto_opts = ProtoOpts,
size = Count,
- type = CType}, IP, Server}) ->
+ type = CType}, IP, Server,Id}) ->
?DebugF("Init ... started with count = ~p~n",[Count]),
ts_utils:init_seed(),
?DebugF("Get dynparams for ~p~n",[CType]),
DynData = CType:init_dynparams(),
+ NewDynVars = ts_dynvars:set(tsung_userid,Id,DynData#dyndata.dynvars),
+ NewDynData = DynData#dyndata{dynvars=NewDynVars},
StartTime= now(),
ts_mon:newclient({self(), StartTime}),
set_thinktime(?short_timeout),
@@ -101,9 +105,10 @@ init({#session{id = SessionId,
proto_opts = ProtoOpts,
count = Count,
ip = IP,
+ id = Id,
hibernate = Hibernate,
maxcount = Count,
- dyndata = DynData
+ dyndata = NewDynData
}}.
%%--------------------------------------------------------------------
@@ -350,7 +355,8 @@ handle_next_action(State) ->
%%----------------------------------------------------------------------
%% @spec set_dynvars (Type::erlang|random|urandom|file, Args::tuple(),
%% Variables::list(), DynData::#dyndata{}) -> list()
-%% @doc setting the value of several dynamic variables at once.
+%% @doc setting the value of several dynamic variables at once.
+%% @end
%%----------------------------------------------------------------------
set_dynvars(erlang,{Module,Callback},_Vars,DynData) ->
Module:Callback({self(),DynData#dyndata.dynvars});
@@ -733,7 +739,8 @@ handle_data_msg(Data,State=#state_rcv{request=Req,clienttype=Type,maxcount=MaxCo
true ->
?DebugF("Response done:~p~n", [NewState#state_rcv.datasize]),
{PageTimeStamp, DynVars} = update_stats(NewState#state_rcv{buffer=NewBuffer}),
- NewCount = ts_search:match(Req#ts_request.match, NewBuffer, {NewState#state_rcv.count, MaxCount}),
+ NewCount = ts_search:match(Req#ts_request.match, NewBuffer,
+ {NewState#state_rcv.count, MaxCount, NewState#state_rcv.session_id, NewState#state_rcv.id}),
NewDynVars=ts_dynvars:merge(DynVars,(NewState#state_rcv.dyndata)#dyndata.dynvars),
NewDynData=(NewState#state_rcv.dyndata)#dyndata{dynvars=NewDynVars},
case Close of
@@ -799,7 +806,7 @@ handle_data_msg(Data, State=#state_rcv{request=Req, maxcount= MaxCount}) ->
DataSize = size(Data),
{PageTimeStamp, DynVars} = update_stats(State#state_rcv{datasize=DataSize,
buffer=NewBuffer}),
- NewCount = ts_search:match(Req#ts_request.match, NewBuffer, {State#state_rcv.count,MaxCount}),
+ NewCount = ts_search:match(Req#ts_request.match, NewBuffer, {State#state_rcv.count,MaxCount,State#state_rcv.id,State#state_rcv.id}),
NewDynVars=ts_dynvars:merge(DynVars,(State#state_rcv.dyndata)#dyndata.dynvars),
NewDynData=(State#state_rcv.dyndata)#dyndata{dynvars=NewDynVars},
{State#state_rcv{ack_done = true, buffer= NewBuffer, dyndata = NewDynData,
@@ -50,10 +50,9 @@ start_child(Profile) ->
%%%----------------------------------------------------------------------
%%--------------------------------------------------------------------
-%% Func: active_clients/0
-%% Returns: [ Client ]
-%% Description: returns the list of all active children on this beam's
-%% client supervisor.
+%% @spec active_clients() -> [tuple()]
+%% @doc returns the list of all active children on this beam's
+%% client supervisor. @end
%%--------------------------------------------------------------------
active_clients()->
length(supervisor:which_children(?MODULE)).
View
@@ -74,7 +74,8 @@ extract_variable([],_DynVar,Acc,_) ->
extract_variable([$%,$%|Tail], DynVar, Acc, Var) ->
VarName = list_to_atom(lists:reverse(Var)),
case ts_dynvars:lookup(VarName,DynVar) of
- {ok, Result} ->
+ {ok, ResultTmp} ->
+ Result=ts_utils:term_to_list(ResultTmp),
?DebugF("found value ~p for name ~p~n",[Result,VarName]),
subst(Tail, DynVar,lists:reverse(Result) ++ Acc);
false ->
@@ -108,21 +109,21 @@ extract_function([H|Tail],DynVar, Acc, Mod, Fun) ->
extract_function(Tail, DynVar, Acc, Mod, [H|Fun]).
%%----------------------------------------------------------------------
-%% @spec match(Match::#match{}, Data::binary() | list, Counts::integer())
-%% -> Count::integer()
+%% @spec match(Match::#match{}, Data::binary() | list, Counts::integer(),
+%% Id::integer())-> Count::integer()
%% @doc search for regexp in Data; send result to ts_mon
%% @end
%%----------------------------------------------------------------------
-match([], _Data, {Count, _MaxC}) -> Count;
+match([], _Data, {Count, _MaxC, _SessionId, _UserId}) -> Count;
match(Match, Data, Counts) when is_binary(Data)->
?DebugF("Matching Data size ~p~n",[size(Data)]),
- match(Match, binary_to_list(Data), Counts, []);
-match(Match, Data, Counts) ->
- match(Match, Data, Counts, []).
+ match(Match, binary_to_list(Data), Counts);
+match(Match, Data, {Count,MaxC,SessionId,UserId}) when is_list(Data) ->
+ match(Match, Data, {Count,MaxC,SessionId,UserId}, []).
-%% @spec match(Match::#match{}, Data::binary() | list(), Counts::integer(), Stats::list())
-%% -> Count::integer()
-match([], _Data, {Count, _MaxC}, Stats) ->
+%% @spec match(Match::#match{}, Data::binary() | list(), Count::tuple(),
+%% Stats::list()) -> Count::integer()
+match([], _Data, {Count, _MaxC, _SessionId,_UserId}, Stats) ->
%% all matches done, add stats, and return Count unchanged (continue)
ts_mon:add(Stats),
Count;
@@ -134,15 +135,15 @@ match([Match=#match{regexp=RegExp, do=Action, 'when'=When}| Tail], String, Count
When -> % nomatch
?LOGF("Bad Match (regexp=~p) do=~p~n",[RegExp, Action], ?INFO),
setcount(Match, Counts, [{count, nomatch} | Stats]);
- {match,_, _} ->
+ {match,_, _} -> % match but when=nomatch
?LOGF("Ok Match (regexp=~p)~n",[RegExp], ?INFO),
case Action of
loop -> put(loop_count, 0);
restart -> put(restart_count, 0);
_ -> ok
end,
match(Tail, String, Counts, [{count, match} | Stats]);
- nomatch ->
+ nomatch -> % nomatch but when=match
?LOGF("Bad Match (regexp=~p)~n",[RegExp], ?INFO),
case Action of
loop -> put(loop_count, 0);
@@ -163,27 +164,31 @@ match([Match=#match{regexp=RegExp, do=Action, 'when'=When}| Tail], String, Count
%% - if restart is true, we must start again the whole session, set count to MaxCount
%% - if stop is true, set count to 0
%%----------------------------------------------------------------------
-setcount(#match{do=continue}, {Count, _MaxC}, Stats)->
+setcount(#match{do=continue}, {Count, _MaxC, _SessionId, _UserId}, Stats)->
ts_mon:add(Stats),
Count;
-setcount(#match{do=restart, max_restart=MaxRestart}, {_Count, MaxC}, Stats)->
+setcount(#match{do=log}, {Count, MaxC, SessionId, UserId}, Stats)->
+ ts_mon:add_match(Stats,{UserId,SessionId,MaxC-Count}),
+ Count;
+setcount(#match{do=restart, max_restart=MaxRestart}, {Count, MaxC,SessionId,UserId}, Stats)->
CurRestart = get(restart_count),
+ Ids={UserId,SessionId,MaxC-Count},
?LOGF("Restart on (no)match ~p~n",[CurRestart], ?INFO),
case CurRestart of
undefined ->
put(restart_count,1),
- ts_mon:add([{count, match_restart} | Stats]),
+ ts_mon:add_match([{count, match_restart} | Stats],Ids),
MaxC ;
Val when Val > MaxRestart ->
?LOG("Max restart reached, abort ! ~n", ?WARN),
- ts_mon:add([{count, match_restart_abort} | Stats]),
+ ts_mon:add_match([{count, match_restart_abort} | Stats],Ids),
0;
Val ->
put(restart_count, Val +1),
- ts_mon:add([{count, match_restart} | Stats]),
+ ts_mon:add_match([{count, match_restart} | Stats],Ids),
MaxC
end;
-setcount(#match{do=loop,loop_back=Back,max_loop=MaxLoop,sleep_loop=Sleep},{Count,_MaxC},Stats)->
+setcount(#match{do=loop,loop_back=Back,max_loop=MaxLoop,sleep_loop=Sleep},{Count,_MaxC,_SessionId,_UserId},Stats)->
CurLoop = get(loop_count),
?LOGF("Loop on (no)match ~p~n",[CurLoop], ?INFO),
ts_mon:add([{count, match_loop} | Stats]),
@@ -201,8 +206,8 @@ setcount(#match{do=loop,loop_back=Back,max_loop=MaxLoop,sleep_loop=Sleep},{Count
timer:sleep(Sleep),
Count + 1 + Back
end;
-setcount(#match{do=abort}, _, Stats) ->
- ts_mon:add([{count, match_stop} | Stats]),
+setcount(#match{do=abort}, {Count,MaxC,SessionId,UserId}, Stats) ->
+ ts_mon:add_match([{count, match_stop} | Stats],{SessionId,UserId,MaxC-Count}),
0.
%%----------------------------------------------------------------------
Oops, something went wrong.

0 comments on commit 17a8178

Please sign in to comment.