Use the duration() modifier to constrain a scenario's duration
For the purposes of various tests, you may want to constrain the duration of a scenario to different values. One way to do this is to constrain the scenario's duration using a keep() constraint.
extend top.main:
keep(d1.duration in [3..5]second)
do d1: sut.car.simple_drive()
Another approach is to constrain the duration parameter during scenario invocation:
extend top.main:
do d1: sut.car.simple_drive(duration: [3..5]second)
Both of these approaches are problematic.
During the generation test phase, Foretify chooses a value within the specified range for scenario duration constrained with keep() or passed as a parameter during scenario invocation. In the code above, Foretify chooses a specific value for the duration of simple_drive(), for example 3second. Then, during the execution test phase, Foretify uses the generated value of 3second for the duration of simple_drive(). The valid range for the execution of the scenario is much narrower than the range specified. As a result, the test conditions may not be met and the test may fail with an incomplete_scenario error.
Recommendation
During both the generation and the execution phases, Foretify considers all modifiers, including those specified with the in directive in scenario extensions. During the execution phase, for each modifier of a movement that is not overridden, Foretify confirms that it is satisfied.
Therefore, it is recommended to constrain the duration of a scenario using the duration() modifier and a literal range. In a scenario extension, you can use the in directive to do this. This approach is advantageous because you can also specify an appropriate tolerance parameter. The tolerance parameter is ignored during generation but used during execution.
Problematic coding styles
import "$FTX_BASIC/exe_platforms/sumo_ssp/config/sumo_config.osc"
extend test_config:
set map = "$FTX_PACKAGES/maps/highway.xodr"
scenario vehicle.simple_drive:
do drive() with:
speed([40..60]kph)
duration([2..10]second)
extend top.main:
keep(d1.duration in [3..5]second)
do d1: sut.car.simple_drive()
import "$FTX_BASIC/exe_platforms/sumo_ssp/config/sumo_config.osc"
extend test_config:
set map = "$FTX_PACKAGES/maps/highway.xodr"
scenario vehicle.simple_drive:
do drive() with:
speed([40..60]kph)
duration([2..10]second)
extend top.main:
do d1: sut.car.simple_drive(duration: [3..5]second)
Recommended coding style
import "$FTX_BASIC/exe_platforms/sumo_ssp/config/sumo_config.osc"
extend test_config:
set map = "$FTX_PACKAGES/maps/highway.xodr"
scenario vehicle.simple_drive:
do drive() with:
speed([40..60]kph)
duration([2..10]second)
extend top.main:
in d1 with: duration([4..5]second, tolerance: [1..2]second)
do d1: sut.car.simple_drive()
Linter rule name
Note
The linter identifies constraining duration with keep() but does not identify constraining duration in scenario invocation.