abstracta / jmeter-java-dsl

Simple JMeter performance tests API
https://abstracta.github.io/jmeter-java-dsl/
Apache License 2.0
469 stars 58 forks source link

Header inheritance fails if encounters JSR223 sampler with SamplerScript class #240

Closed FakeLogin closed 10 months ago

FakeLogin commented 10 months ago

Hello Abstracta team, Here is a Header-is-missing thing I've faced while working with DSL.

Preconditions

Results in Only outermost header is assigned to the request. The other header is not assigned. See a sample test below as it may give a better sense of what's going on.

Thoughts It can be simply me implementing SamplerScript incorrectly. Should I do something with Run method? If that's the case, I'd be so grateful for guidance.

I also realise, there are workarounds. E.g. I can redesign the test to avoid header inheritance and pull all the headers as HttpRequest direct children (tried, that works). Yet I'd rather avoid the latter as it makes the script overloaded with details. In case of a large script it's easier to figure out a point of header related failure by filtering out the requests with no headers attached directly.

Consider the following sample test:

public class HeaderTest {
   //WireMock set-up omitted for the sake of brevity

    public static class NoAction implements DslJsr223Sampler.SamplerScript {
        @Override
        public void runScript(DslJsr223Sampler.SamplerVars vars) {
            //Nothing happens here
        }
    }

    @Test
    void test() throws IOException {
        testPlan(
                httpHeaders().header("ROOT_LEVEL", "rootLevelHeader"),
                threadGroup(1, 1,
                        transaction("LEVEL_ONE",
                                httpHeaders().header("LEVEL_ONE", "firstLevelHeader"),
                                jsr223Sampler("No action Lambda Sampler", NoAction.class),
                                httpSampler("Request at level one", "http://localhost:8888/one")
                        )
                )
        ).run();

        mockServer.verify(getRequestedFor(urlEqualTo("/one"))
                .withHeader("ROOT_LEVEL", equalTo("rootLevelHeader"))
                .withHeader("LEVEL_ONE", equalTo("firstLevelHeader")));
    }
}

The test results:

expected:
GET
/one
ROOT_LEVEL: rootLevelHeader
LEVEL_ONE: firstLevelHeader

but was:
GET
/one
ROOT_LEVEL: rootLevelHeader

And once again, thank you so much for crafting the DSL project. It makes the testing fun again (:

rabelenda commented 10 months ago

Hello, this is a very interesting bug that you have found, thank you!

The information you provided allowed us to easily reproduce and then identify the issue.

We have detected the source of the issue and will release a fix in next version.

Stay tuned!

rabelenda commented 10 months ago

We just released a new version which fixes reported issue. Thank you!

FakeLogin commented 10 months ago

That's amazing news! Thank you for taking care (: