tsung
tsung copied to clipboard
if matches for undefined variables
I only now realised, that for <if> and other conditionals, the jump to skip over this block is not executed, if the dynvar could not be found.
<if var="undefined_variable" eq="something">
<!-- This will ALWAYS be executed -->
</if>
This happens, because {next,DynVars} is returned if ts_dynvars:lookup(VarName,DynVars) returns false:
https://github.com/processone/tsung/blob/5b4bae69c5af5351d585f654fbfae243752cf885/src/tsung/ts_client.erl#L644-L666
IMO this is a very unexpected behaviour. We noticed this, because we had two <if> blocks where the second exactly negates the first one (to get if-else basically). But if the variable is undefined, both sections get executed 😕
<if var="undefined_variable" eq="something">
<!-- This will be executed -->
</if>
<if var="undefined_variable" neq="something">
<!-- This will ALSO be executed -->
</if>
Suggestions
- never match a undefined variable (always skip the
ifsection) - tread an undefined DynVar as empty
""
I would tend towards 2. because it is less surprising in case someone writes:
<if var="undefined_variable" eq="">
<!-- This will be executed if variable is undefined or empty -->
</if>
Implementation
I have patches prepared for different variants, but I'd like to know what @nniclausse thinks about this first :)
@nniclausse ping
sorry i forgot to reply. Yes i agree, 2. is fine.