citrusframework / citrusframework/citrus-simulator

Race condition between Active and default scenario

Open
#23 0 comments 0 reactions 0 assignees View on GitHub
Prio: Medium READY Type: Bug
Dominant language
Java
Stars
47
Forks
45
Avg merge
4d 10h
Merged PRs (30d)
7

Description

Given the following Test of `sample-combined`:
```java
@CitrusTest
public void testInterveningRequest() {
variable("correlationId", "citrus:randomNumber(10)");

//GoodNightScenario
http().client(simulatorClient)
.send()
.post("goodnight")
.payload("" +
"Go to sleep!" +
"")
.header("x-correlationid", "${correlationId}");

http().client(simulatorClient)
.receive()
.response(HttpStatus.OK)
.payload("" +
"Good Night!" +
"");

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

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

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

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

//Should be DefaultScenario (Race condition here)
http().client(simulatorClient)
.send()
.put("goodnight")
.payload("In between!")
.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

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the sample-combined test and trace the GoodNightScenario through CorrelationHandlerRegistry and ScenarioDesigner, especially the StopCorrelationHandlerAction in doFinally(). Reproduce the fast request sequence and verify that the scenario is no longer active before the following request is matched as DefaultScenario.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend, testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.