tsung icon indicating copy to clipboard operation
tsung copied to clipboard

if matches for undefined variables

Open tisba opened this issue 6 years ago • 2 comments

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

  1. never match a undefined variable (always skip the if section)
  2. 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 :)

tisba avatar Feb 19 '19 14:02 tisba

@nniclausse ping

tisba avatar Mar 18 '19 16:03 tisba

sorry i forgot to reply. Yes i agree, 2. is fine.

nniclausse avatar Mar 19 '19 17:03 nniclausse