java.lang.StackOverflowError for Test Collection (Parallel)

Hi there hope you are fine today,

Some of the tests return a java.lang.StackOverflowError.
I have no idea how to solve that,Katalon JVM argument have been already increased to -Xmx5g

The code below is start in a collection of 31 thread within a max of 7 thread at the same time.

import com.kms.katalon.core.configuration.RunConfiguration
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import internal.GlobalVariable
import tags.manager.TagManager

String projDir = RunConfiguration.getProjectDir();
String folderName = "/Data Files/Make Tags Parallel/CompositeTagsTree.json";
TagManager tagManager = new TagManager(projDir+folderName);

String TagsTostart = tagManager.PopNewUnitaryTags();

if(TagsTostart != "") CucumberKW.runFeatureFileWithTags('Include/features/', 'not @skip and not @0_AvoidOnVersion'+ GlobalVariable.version + ' and (' +TagsTostart+ ')')

Some of the test return such an error :

Test Cases/Cucumber - Parallelised test - Launch Test FAILED. 
Reason: com.kms.katalon.core.exception.StepFailedException: Keyword runFeatureFileWithTags was failed (Root cause: java.lang.StackOverflowError at cucumber.runtime.io.FileResourceIterator$FileIterator.<init>(FileResourceIterator.java:59) at 
cucumber.runtime.io.FileResourceIterator$FileIterator.next(FileResourceIterator.java:74) at cucumber.runtime.io.FlatteningIterator.moveToNext(FlatteningIterator.java:29) at 
cucumber.runtime.io.FlatteningIterator.moveToNext(FlatteningIterator.java:27) at 
cucumber.runtime.io.FlatteningIterator.moveToNext(FlatteningIterator.java:32) at 
cucumber.runtime.io.FlatteningIterator.moveToNext(FlatteningIterator.java:27) at 
cucumber.runtime.io.FlatteningIterator.moveToNext(FlatteningIterator.java:32) at 
cucumber.runtime.io.FlatteningIterator.moveToNext(FlatteningIterator.java:27) at 
cucumber.runtime.io.FlatteningIterator.moveToNext(FlatteningIterator.java:32) at 
cucumber.runtime.io.FlatteningIterator.moveToNext(FlatteningIterator.java:27) at 
cucumber.runtime.io.FlatteningIterator.moveToNext(FlatteningIterator.java:32) at 
[...]
cucumber.runtime.io.FlatteningIterator.moveToNext(FlatteningIterator.java:27) at 
cucumber.runtime.io.FlatteningIterator.moveToNext(FlatteningIterator.java:32) at 

Any idea ? I heard about a -Xss option, could it be a solution ?
The feature file is too long ?

We have this error after adding a lot more of test. Is there a limit of test quantity ?

@spuygrenier
Please share your feature files content and the step definitions

Thanks @duyluong !

The test start a thread by tag, with a total amont of 31 tags / thread.

See below the Feature files :

StaticDataHD.txt (460.3 KB)
StaticDataInbound.txt (1.4 KB)
StaticDataMasterItem.txt (1.6 KB)
StaticDataOutbound.txt (58.4 KB)
StaticDataOutboundPublishInTopic.txt (4.9 KB)
StaticDataPickBatch.txt (2.7 KB)

The steep definition are more or less the same, only the @Given steep may change a little bit.

// Can be used for any API, below a sample with OutboundConfirmation 
@Given("I request data for API OutboundConfirmation for the {string} {string}")
	def I_request_the_topic_data_for_API_OutboundConfirmation(String yearNo,String outboundNo){
		apiReply = WS.sendRequest(findTestObject('Webservices WDP/OutboundConfirmation', [('preparationYear') : yearNo,('outboundNumber') : outboundNo]))
	}

@Then("I verify the status code is 200")
	def I_verify_the_status_code_is_200(){
		WS.verifyResponseStatusCode(apiReply, 200)
	}

// We take a template an we verify there is no change between current reply and template file
@Then("I verify if the content match with the template {string}")
	def I_verify_if_the_content_match_with_the_template2(String suffixe) {
		// remove special char in file
		suffixe=suffixe.replace("#", "")
		String template_filename = GlobalVariable.scenarioPrefix + "_"+suffixe+".txt"
		println "template_filename: $template_filename - suffixe: $suffixe"
		ArtifactHandlerForCucumber.WritteNiceJsonIntoCorrectFolder(apiReply.getResponseText(),template_filename+"_received_api.original.json")
		String receivedJson = apiReply.getResponseText()
		def diffOfApi = JsonDiff.BuildJsonDiff(receivedJson, "API template response/Topic Static Template File/", template_filename)
		//JsonDiff.PreformatSwitchCaseCodeToCopyPastIfUpdateNeeded(diffOfApi,template_filename)

		def diffOfApiCleaned = JsonDiff.removeDiffByPath(diffOfApi, "/json_detail/preparation_list", "/consignee/update_date")
		diffOfApiCleaned = JsonDiff.removeDiffByPath(diffOfApiCleaned, "/server_information/environment", "/server_information/environment")
		//println "apiReply : " + receivedJson
		//assert apiReply.getResponseText().contains('"environment":"' + GlobalVariable.server + '"') : "/server_information/environment n'a pas la valeur attendue "
		String expectedEnv = '"environment":"' + GlobalVariable.server + '"'

		if (receivedJson.contains('"environment":"')) {
			assert receivedJson.contains(expectedEnv)
		}
		assert diffOfApiCleaned.replaceAll("[^a-zA-Z]", "").length()==0
	}

Collection is set as bellow

Test suit used are is as follow

And test case for parallel test launch is like :

String projDir = RunConfiguration.getProjectDir();
String folderName = "/Data Files/Make Tags Parallel/CompositeTagsTree.json";
TagManager tagManager = new TagManager(projDir+folderName);

String TagsTostart = tagManager.PopNewUnitaryTags();

if(TagsTostart != "") CucumberKW.runFeatureFileWithTags('Include/features/', 'not @skip and not @0_AvoidOnVersion'+ GlobalVariable.version + ' and (' +TagsTostart+ ')')

hi duyluong, any update or work arround ?

@spuygrenier

I saw many google drive link in your feature files. Is that expected?

Another solution here is to bring all your step definitions in a dedicated package and use this feature to specific the step definitions package: BDD Testing Framework (Cucumber integration) | Katalon Docs

@duyluong
No worries for those google link, they are kind of our functional documentation.
In addition, I can assure you that cucumber framework worked fine before adding tons of tests.

A strange fact, if we use Katalon on local computer, we have the full test collection result but on jenkins we get those stock over flow error (katalon runtime engine)

Test Cases/Cucumber - Parallelised test - Launch Test FAILED. 
Reason: com.kms.katalon.core.exception.StepFailedException: Keyword runFeatureFileWithTags was failed (Root cause: java.lang.StackOverflowError at cucumber.runtime.io.FileResourceIterator$FileIterator.<init>(FileResourceIterator.java:59) at 
cucumber.runtime.io.FileResourceIterator$FileIterator.next(FileResourceIterator.java:74) at cucumber.runtime.io.FlatteningIterator.moveToNext(FlatteningIterator.java:29) at 
cucumber.runtime.io.FlatteningIterator.moveToNext(FlatteningIterator.java:27) at 
cucumber.runtime.io.FlatteningIterator.moveToNext(FlatteningIterator.java:32) at 
cucumber.runtime.io.FlatteningIterator.moveToNext(FlatteningIterator.java:27) at 
cucumber.runtime.io.FlatteningIterator.moveToNext(FlatteningIterator.java:32) at 
cucumber.runtime.io.FlatteningIterator.moveToNext(FlatteningIterator.java:27) at 
cucumber.runtime.io.FlatteningIterator.moveToNext(FlatteningIterator.java:32) at 
cucumber.runtime.io.FlatteningIterator.moveToNext(FlatteningIterator.java:27) at 
cucumber.runtime.io.FlatteningIterator.moveToNext(FlatteningIterator.java:32) at 
[...]
cucumber.runtime.io.FlatteningIterator.moveToNext(FlatteningIterator.java:27) at 
cucumber.runtime.io.FlatteningIterator.moveToNext(FlatteningIterator.java:32) at 

Would it be a link to -Xss option ?
The -Xss JVM option allows us to specify the size of the frame stack used by each thread to store local variable, partial results and method calling information.

The Katlaon doc doens’t mention it and I haven’t succed to make it work by myself (jenkins running, nothing on the consol for a long time)

Hi @duyluong, it’s fix ! :partying_face:

We created dedicated package, slice big features file into several smaller file and set glue code at the correct location … And no more stock over flow error !

Could you explain why your solution worked ?

@spuygrenier

By default, Cucumber will scan all of packages to find that matched step definitions for your specified feature files that may cause performance issue when the project classpath or the feature file become large.

Limiting the scope of the step definitions (packages) will help Cucumber scan only the specified area, so it will prevent OutOfMemory error.