player icon indicating copy to clipboard operation
player copied to clipboard

Issue when trying to use `with`, `assert`, and variables together

Open Kocal opened this issue 3 years ago • 1 comments

Hi!

I'm trying to combine the usage of with and assert in order to write a single visit url() block which will be driven by configuration (from the with).

Here is our .blackfire.yaml:

scenarios: |
    #!blackfire-player

    scenario
        name "Performance regression"

        with slug, data in \
            { \
                '/a': { name: 'A', maxWallTime: '1s' }, \
                '/b': { name: 'B', maxWallTime: '2s' }, \
                '/c': { name: 'C', maxWallTime: '3s' }
            }

            visit url(slug)
                samples 3
                warmup true
                name "Checking performance for " ~ data['name']
                expect status_code() == 200
                assert main.wall_time < data["maxWallTime"] * var('time_coeff', 1)
                assert percent(main.wall_time) < 10%

The issue is caused by the usage of data["maxWallTime"]. I've tried different syntaxes but it still fails (with different error message tho):

  1. assert main.wall_time < data["maxWallTime"] * var('time_coeff', 1):
Unexpected characters (maxWallTime"]) at line 3 (near "assertions: ["main.wall_time < data["maxWallTime"] * var('time_coeff', 1)"]") in the request configuration (config_yml)
  1. assert main.wall_time < data['maxWallTime'] * var('time_coeff', 1):
Invalid configuration for path "tests._assertion_2.assertions.0.expression": Variable "data" is not valid around position 18 for expression `main.wall_time < data['maxWallTime'] * var('time_coeff', 1)`. Did you forget to prefix your variable with "main.", "metrics.", "runtime.", or "vars."?
  1. assert main.wall_time < data.maxWallTime * var('time_coeff', 1):
Invalid configuration for path "tests._assertion_2.assertions.0.expression": Variable "data" is not valid around position 18 for expression `main.wall_time < data.maxWallTime * var('time_coeff', 1)`. Did you forget to prefix your variable with "main.", "metrics.", "runtime.", or "vars."?

Does someone know how to make things working?

Thanks!

Kocal avatar Feb 10 '22 14:02 Kocal

Anyone? 😅

Kocal avatar Nov 03 '22 09:11 Kocal