Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Race condition between Active and default scenario #23

Open
svettwer opened this issue Oct 24, 2018 · 0 comments
Open

Race condition between Active and default scenario #23

svettwer opened this issue Oct 24, 2018 · 0 comments

Comments

@svettwer
Copy link
Contributor

Given the following Test of sample-combined:

@CitrusTest
    public void testInterveningRequest() {
        variable("correlationId", "citrus:randomNumber(10)");

        //GoodNightScenario
        http().client(simulatorClient)
                .send()
                .post("goodnight")
                .payload("<GoodNight xmlns=\"http://citrusframework.org/schemas/hello\">" +
                            "Go to sleep!" +
                        "</GoodNight>")
                .header("x-correlationid", "${correlationId}");

        http().client(simulatorClient)
                .receive()
                .response(HttpStatus.OK)
                .payload("<GoodNightResponse xmlns=\"http://citrusframework.org/schemas/hello\">" +
                            "Good Night!" +
                        "</GoodNightResponse>");

        //DefaultScenario
        http().client(simulatorClient)
                .send()
                .post()
                .payload("<InterveningRequest>In between!</InterveningRequest>");

        http().client(simulatorClient)
                .receive()
                .response(HttpStatus.OK)
                .payload(defaultResponse);

        //GoodNightScenario
        http().client(simulatorClient)
                .send()
                .post()
                .payload("<InterveningRequest>In between!</InterveningRequest>")
                .header("x-correlationid", "${correlationId}");

        http().client(simulatorClient)
                .receive()
                .response(HttpStatus.OK)
                .payload("<InterveningResponse>In between!</InterveningResponse>");

        //Should be DefaultScenario (Race condition here)
        http().client(simulatorClient)
                .send()
                .put("goodnight")
                .payload("<InterveningRequest>In between!</InterveningRequest>")
                .header("x-correlationid", "${correlationId}");

        http().client(simulatorClient)
                .receive()
                .response(HttpStatus.OK)
                .payload(defaultResponse);
    }

If the test runs "fast enough", the GoodNightScenario is still active in the CorrelationHandlerRegistry, because doFinally().actions(builder.stop()) of the ScenarioDesigner, containing the StopCorrelationHandlerAction to stop the scenario, has not been finished, until the next request, that matches the x-correlationid header condition, arrives.

BR,
Sven

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant