Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run <if> value by ts_search:subst/2 #311

Merged
merged 3 commits into from
Jul 17, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/tsung/ts_client.erl
Original file line number Diff line number Diff line change
Expand Up @@ -641,9 +641,19 @@ ctrl_struct_impl({for_end,VarName,EndValue,Increment,Target},DynVars) ->
NewDynVars = ts_dynvars:set(VarName,NewValue,DynVars),
{jump,Target,NewDynVars}
end;


ctrl_struct_impl({if_start,Rel, VarName, Value, Target},DynVars) ->
ctrl_struct_impl({if_start,Rel, VarName, Value, subst, Target},DynVars) ->
case ts_dynvars:lookup(VarName,DynVars) of
{ok,VarValue} ->
NewValue = ts_search:subst(Value, DynVars),
?DebugF("If found ~p; value is ~p; applying substitutions~n",[VarName,VarValue]),
?DebugF("Calling need_jump with args ~p ~p ~p~n",[Rel,NewValue,VarValue]),
Jump = need_jump('if',rel(Rel,NewValue,VarValue)),
jump_if(Jump,Target,DynVars);
false ->
ts_mon_cache:add({ count, 'error_if_undef'}),
{next,DynVars}
end;
ctrl_struct_impl({if_start,Rel, VarName, Value, nosubst, Target},DynVars) ->
case ts_dynvars:lookup(VarName,DynVars) of
{ok,VarValue} ->
?DebugF("If found ~p; value is ~p~n",[VarName,VarValue]),
Expand Down
8 changes: 7 additions & 1 deletion src/tsung_controller/ts_config.erl
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,13 @@ parse(_Element = #xmlElement{name='if', attributes=Attrs,content=Content},
NewConf = lists:foldl(fun parse/2, Conf#config{curid=Id+1}, Content),
NewId = NewConf#config.curid,
?LOGF("endif in session ~p as id ~p",[CurS#session.id,NewId+1],?INFO),
InitialAction = {ctrl_struct, {if_start, Rel, VarName, list_to_binary(Value) , NewId+1}},
SubstitutionFlag = case string:str(Value, "%%") of
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should use re:run(Value, "%%.+%%") instead if think

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. I thought string:str because that's recommended for performance reasons, but since we are only parsing the configuration, that should not be a issue to begin with.

I'll change this.

Do you have anything else on the new approach?

Pos when Pos > 0 ->
subst;
Pos when Pos =:= 0 ->
nosubst
end,
InitialAction = {ctrl_struct, {if_start, Rel, VarName, list_to_binary(Value), SubstitutionFlag, NewId+1}},
%%NewId+1 -> id of the first action after the if
ets:insert(Tab,{{CurS#session.id,Id+1},InitialAction}),
NewConf;
Expand Down