citrusframework / citrusframework/citrus

StackOverflowError when using many SequenceBefore / SequenceAfter

Open
#595 2 comments 9 reactions 0 assignees View on GitHub
enhancement prio-low
Dominant language
Java
Stars
485
Forks
155
Avg merge
4d 22h
Merged PRs (30d)
6

Description

**Description:** When having many SequenceBefore / SequenceAfter (e.g. 'TestRunnerBeforeTestSupport') the application context cannot be created because of an StackOverflowError.

**Citrus Version**
2.7.8
2.7.9-SNAPSHOT

**Expected behavior**
Application Context should have been initialized and tests should run.

**Actual behavior**
Application crashes with 'StackOverflowError'

**Test case sample**
Testclass:
```java
package stackoverflow;

import com.consol.citrus.annotations.CitrusTest;
import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;
import org.testng.annotations.Test;

@Test
public class StackOverflowIT extends TestNGCitrusTestRunner {

@CitrusTest
public void testStackOverflowIT() {
echo("this is a test");
}
}
```

Fixture:
```java
package stackoverflow;

import com.consol.citrus.dsl.runner.TestRunner;
import com.consol.citrus.dsl.runner.TestRunnerBeforeTestSupport;

public class Fixture extends TestRunnerBeforeTestSupport {

public void beforeTest(TestRunner runner) {
runner.echo("beforeTest");
}
}
```

Configuration:
```java
package stackoverflow;

import org.springframework.context.annotation.Bean;

public class Configuration {

@Bean
public Fixture beforeTest_0() {
return new Fixture();
}

@Bean
public Fixture beforeTest_1() {
return new Fixture();
}

@Bean
public Fixture beforeTest_2() {
return new Fixture();
}

...

The 'real' range is from 0 to 999. Leaving out everything between 3 and 996 because this would make this example unreadable.

...

@Bean
public Fixture beforeTest_997() {
return new Fixture();
}

@Bean
public Fixture beforeTest_998() {
return new Fixture();
}

@Bean
public Fixture beforeTest_999() {
return new Fixture();
}
}
```

**Cause:**

It seems as if this is caused by the fact that 'afterPropertiesSet' method of 'TestRunnerBeforeTestSupport' class creates a new DefaultTestRunner which itsself calls 'applicationContext.getBeansOfType(SequenceBeforeTest.class)' in its constructor. As a result all not-yet initialized Beans of type 'SequenceBeforeTest' get initialized, which also includes calling 'afterPropertiesSet'.

Because of this a very large call stack gets created that eventually gets too big - StackOverflowError.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.