Permalink
Browse files

TSUN-266 #close End of work on request tagging url, add doc and tests

1 parent af66934 commit ae3224d7bf99bb934e6bb349f05a35ce87199758 @rodo rodo committed Oct 15, 2013
@@ -753,3 +753,31 @@ For example, to limit the rate to 64KB/sec for a given session:
Only the incoming traffic is rate limited currently.
+
+.. index:: tag
+
+Requests exclusion
+^^^^^^^^^^^^^^^^^^
+
+.. versionadded:: 1.5.1
+
+It is possible to exclude some request for a special run. To do this
+you have to tag them and use the option ``-x`` when launching the run.
+
+For example, to exclude the GET of foo.png, add a ``tag`` to the
+respective request:
+
+.. code-block:: xml
+
+ <request>
+ <http url="/" method="GET"></http>
+ </request>
+ <request tag="image">
+ <http url="/foo.png" method="GET"></http>
+ </request>
+
+Then launch the run with::
+
+ tsung -f SCENARIO.xml -x image start
+
+Only the GET to ``/`` will be done.
View
@@ -0,0 +1,48 @@
+<?xml version="1.0"?>
+<!DOCTYPE tsung SYSTEM "@prefix@/share/@PACKAGE_NAME@/@DTD@">
+<tsung loglevel="notice" version="1.0">
+
+ <!-- Client side setup -->
+ <clients>
+ <client host="localhost" use_controller_vm="true"/>
+ </clients>
+
+ <!-- Server side setup -->
+ <servers>
+ <server host="localhost" port="80" type="tcp"></server>
+ </servers>
+
+ <load>
+ <!-- several arrival phases can be set: for each phase, you can set
+ the mean inter-arrival time between new clients and the phase
+ duration -->
+ <arrivalphase phase="1" duration="10" unit="minute">
+ <users interarrival="2" unit="second"></users>
+ </arrivalphase>
+ </load>
+
+ <sessions>
+ <session name="images" probability="100" type="ts_http">
+
+ <request>
+ <http url="/" method="GET" version="1.1"></http>
+ </request>
+
+ <!-- this request will be exclude in the unit test -->
+ <request tag="landing">
+ <http url="/img/excluded.png" method="GET" version="1.1"></http>
+ </request>
+
+ <!-- this request will be exclude in the unit test -->
+ <request tag="gif">
+ <http url="/img/excluded.gif" method="GET" version="1.1"></http>
+ </request>
+
+ <request>
+ <http url="/img/not-excluded.png" method="GET" version="1.1"></http>
+ </request>
+
+
+ </session>
+ </sessions>
+</tsung>
@@ -13,6 +13,7 @@
-include("ts_config.hrl").
-include_lib("eunit/include/eunit.hrl").
-include("xmerl.hrl").
+-include("ts_http.hrl").
test()->
ok.
@@ -124,6 +125,40 @@ config_thinktime2_test() ->
random:seed(), % reinit seed for others tests
?assertMatch({random,1000}, Req).
+read_config_tag_noexclusion_test() ->
+ %% no exclusion all request will be played
+ myset_env(),
+ ok = ts_config_server:read_config("./examples/http_tag.xml"),
+ {ok, Session=#session{userid=7} } = ts_config_server:get_next_session({"localhost",1}),
+ Id = Session#session.id,
+ ReqRef = #http_request{url="/img/excluded.png"},
+ {ts_request,parse,false,[],[],Req,_,_,_,_} = ts_config_server:get_req(Id,2),
+ ?assertEqual(ReqRef#http_request.url, Req#http_request.url).
+
+read_config_tag_one_test() ->
+ %% one tag defined
+ %% exclude urls tagged as 'landing'
+ myset_env(),
+ application:set_env(stdlib,exclude_tag,"landing"),
+ ok = ts_config_server:read_config("./examples/http_tag.xml"),
+ {ok, Session=#session{userid=8} } = ts_config_server:get_next_session({"localhost",1}),
+ Id = Session#session.id,
+ ReqRef = #http_request{url="/img/excluded.gif"},
+ {ts_request,parse,false,[],[],Req,_,_,_,_} = ts_config_server:get_req(Id,2),
+ ?assertEqual(ReqRef#http_request.url, Req#http_request.url).
+
+read_config_tag_two_test() ->
+ %% two tag defined
+ %% exclude urls tagged as 'landing' and 'gif'
+ myset_env(),
+ application:set_env(stdlib,exclude_tag,"gif,landing"),
+ ok = ts_config_server:read_config("./examples/http_tag.xml"),
+ {ok, Session=#session{userid=9} } = ts_config_server:get_next_session({"localhost",1}),
+ Id = Session#session.id,
+ ReqRef = #http_request{url="/img/not-excluded.png"},
+ {ts_request,parse,false,[],[],Req,_,_,_,_} = ts_config_server:get_req(Id,2),
+ ?assertEqual(ReqRef#http_request.url, Req#http_request.url).
+
config_arrivalrate_test() ->
myset_env(),
ok = ts_config_server:read_config("./examples/thinks.xml"),
@@ -146,7 +181,6 @@ config_interarrival_test() ->
?assertEqual({RealIntensity/60,RealNU div 60,RealDur}, Phase2),
?assertEqual({RealIntensity/3600,12,RealDur*36}, Phase3).
-
read_config_maxusers_test() ->
read_config_maxusers({5,15},10,"./src/test/thinkfirst.xml").
@@ -177,7 +211,6 @@ read_config_static_test() ->
end, C),
?assertEqual(lists:sum(M) , 5).
-
cport_list_node_test() ->
List=['tsung1@toto',
'tsung3@titi',
@@ -205,7 +238,6 @@ ifalias_ip_test() ->
Res=lists:foldl(fun(A,L) -> [{192,12,0,A}|L] end, [],lists:seq(1,12)),
?assertEqual(Out,Res).
-
encode_test() ->
Encoded="ts_encoded_47myfilepath_47toto_47titi_58sdfsdf_45sdfsdf_44aa_47",
Str="/myfilepath/toto/titi:sdfsdf-sdfsdf,aa/",
@@ -254,4 +286,5 @@ myset_env(Level)->
application:set_env(stdlib,warm_time,1000),
application:set_env(stdlib,thinktime_value,"5"),
application:set_env(stdlib,thinktime_override,"false"),
- application:set_env(stdlib,thinktime_random,"false").
+ application:set_env(stdlib,thinktime_random,"false"),
+ application:set_env(stdlib,exclude_tag,"").
View
@@ -92,6 +92,8 @@ ensure_string(proxy_log_file, Atom) when is_atom(Atom) ->
atom_to_list(Atom);
ensure_string(config_file, Atom) when is_atom(Atom) ->
atom_to_list(Atom);
+ensure_string(exclude_tag, Atom) when is_atom(Atom) ->
+ atom_to_list(Atom);
ensure_string(_, Other) ->
Other.
@@ -662,12 +662,14 @@ parse(Element = #xmlElement{name=request, attributes=Attrs},
Type = CurSess#session.type,
SubstitutionFlag = getAttr(atom, Attrs, subst, false),
Tag = getAttr(string, Attrs, tag, "undefined"),
-
+ Tags = lists:map(fun(X)->{X,ok} end, string:tokens(?config(exclude_tag),",")),
%% do not add in Conf excluded requests
- case Tag of
- "foo" ->
+ case proplists:is_defined(Tag, Tags) of
+ true ->
+ ?LOGF("Tag ~p in ~p ~p ~p ~n",[Tag,true,?config(exclude_tag),Tags],?NOTICE),
Conf;
- _ ->
+ false ->
+ ?LOGF("Tag ~p in ~p ~p ~p ~n",[Tag,false,?config(exclude_tag),Tags],?NOTICE),
lists:foldl( fun(A,B) ->Type:parse_config(A,B) end,
Conf#config{curid=Id+1, cur_req_id=Id+1,
subst=SubstitutionFlag,
@@ -46,7 +46,8 @@
{nclients_fin, 2000}, %% end of interval
{config_file, "./tsung.xml"},
{log_file, "./tsung.log"},
- {match_log_file, "./match.log"}
+ {match_log_file, "./match.log"},
+ {exclude_tag, ""}
]},
{applications, [ @ERLANG_APPLICATIONS@ ]},
{start_phases, [{load_config, []},{start_os_monitoring,[{timeout,30000}]},
View
@@ -33,7 +33,7 @@ CONTROLLER=tsung_controller
SMP_DISABLE=true
WARM_TIME=10
MAX_PROCESS=250000
-EXCLUDE_REQUESTS=""
+EXCLUDE_TAG_LIST=""
TSUNGPATH=$INSTALL_DIR/lib/tsung-$VERSION/ebin
CONTROLLERPATH=$INSTALL_DIR/lib/tsung_controller-$VERSION/ebin
@@ -77,7 +77,7 @@ start() {
-tsung_controller smp_disable $SMP_DISABLE \
-tsung_controller debug_level $DEBUG_LEVEL \
-tsung_controller warm_time $WARM_TIME \
- -tsung_controller exclude_requests $EXCLUDE_REQUESTS \
+ -tsung_controller exclude_tag \"$EXCLUDE_TAG_LIST\" \
-tsung_controller config_file \"$CONF_OPT_FILE\" -tsung_controller $LOG_OPT -tsung_controller $MON_FILE
}
@@ -86,6 +86,7 @@ debug() {
-pa $TSUNGPATH -pa $CONTROLLERPATH \
-tsung_controller warm_time $WARM_TIME \
-tsung_controller config_file \"$CONF_OPT_FILE\" \
+ -tsung_controller exclude_tag \"$EXCLUDE_TAG_LIST\" \
-tsung_controller $LOG_OPT -tsung_controller $MON_FILE
}
@@ -148,11 +149,12 @@ usage() {
echo " -w warmup delay (default is 10 sec)"
echo " -v print version information and exit"
echo " -6 use IPv6 for Tsung internal communications"
+ echo " -x <tags> list of requests tag to be excluded from the run (separated by comma)"
echo " -h display this help and exit"
exit
}
-while getopts "6vhf:l:d:r:i:Fsw:m:p:" Option
+while getopts "6vhf:l:d:r:i:Fsw:m:p:x:" Option
do
case $Option in
f) CONF_OPT_FILE=$OPTARG;;
@@ -178,6 +180,7 @@ do
COOKIE=$COOKIE"_"$ID
CONTROLLER=$CONTROLLER"_"$ID
;;
+ x) EXCLUDE_TAG_LIST=$OPTARG;;
h) usage;;
*) usage ;;
esac

0 comments on commit ae3224d

Please sign in to comment.