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

Karate test hanging when calling other feature #1225

Closed
joelpramos opened this issue Jul 22, 2020 · 6 comments
Closed

Karate test hanging when calling other feature #1225

joelpramos opened this issue Jul 22, 2020 · 6 comments

Comments

@joelpramos
Copy link
Contributor

joelpramos commented Jul 22, 2020

Hi,

I'm using Karate for testing and I also use Freemarker embedded to generate some of the larger / more complex requests.

I noticed my tests hang if I add a Freemarker method or object (eg. https://stackoverflow.com/questions/45957527/freemarker-generate-uuid-conveniently or the result of NodeModel https://www.javatips.net/api/freemarker.ext.dom.nodemodel) into a JSON argument and use it to call another feature. If I remove the reference after using it (by setting the key of the JSON to null/empty) the test doesn't hang, regardless of the other of "cleaning up" this reference (before or after the other feature call).

The test hangs waiting for completion of a thread processing regardless if the test is successful (on Runner.java:332).

Also tried to set a variable, using karate.set(), in the Background of a feature and unless I "unset" it with an afterScenario I see the same behavior.

I'm using Karate version 0.9.5 by tried with 0.9.6.RC4 with same result as well as the version 2.0.0 from the check-in associated with this thread issue #1216 . Also tried several versions of Spring Boot and Freemarker (I'm currently using Spring Boot 2.3.1 and the Freemarker version that comes with it).

Haven't encountered this issue with other Java references.

Any ideas whether I'm missing a config or misusing the framework? Couldn't get the root cause of the issue.

@ptrthomas
Copy link
Member

@joelpramos if this helps you are in luck: https://stackoverflow.com/a/63001155/143475

else sorry, unlikely we will look at this any time soon. if you just need to form JSON, Freemarker is not needed IMHO - once you understand embedded expressions. tagging this as help wanted

@ptrthomas
Copy link
Member

@joelpramos just one more thing - if you can follow the instructions here, I can take a look: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue - e.g. whittle down everything to maybe 1-2 extra deps. we've had too much trouble trying to deal with spring boot class-loading black-magic in the past: #751 - so I consider your example as "not minimal"

of course if you can dig into the code and contribute a fix + PR, that would be cool

but my suggestion is to please drop Freemarker, I don't think you have looked at embedded expressions: https://github.com/intuit/karate/blob/master/karate-demo/src/test/java/demo/cats/billie-expected.json

@joelpramos
Copy link
Contributor Author

I agree embedded expressions are very powerful (and work for the vast majority of the use cases I'm trying to provide) and but I still believe Freemarker is more powerful especially when involving loops, logical conditions and lookups. For the use case I'm currently seeing applicable is soap requests with over 500 parameters and I find it more natural to use freemarker and have all of this in-line.

Interestingly enough I am forcing the inputs to be in JSON (just for convenience of extracting from csv into a nested json) and validating them with the schema validations that you provide (which btw, kudos) to enforce accuracy of the data.

Tried both suggestions (json-smart version) and just removing spring boot altogether from my demo project and I'm still facing the same. I'll keep debugging out of curiosity and if I find the issue I'll contribute with a PR / post solution it here but I won't lose sleep over it cause I have a workaround and as you mentioned Freemarker isn't needed most of the times.

Thanks for the support!

@joelpramos
Copy link
Contributor Author

joelpramos commented Jul 22, 2020

Your mention of json-smart got me thinking and found the issue... when compiling the report and saving the stats in Json there's a NoClassDefFoundError exception when creating the JSON that's argument to the other feature, which is why it only happens when there's another feature being called.

I tried doing a "print" of the arguments and works fine so I compared the code and the code for printing a JSON object (ScriptValue.java:262) is different than the one to print the Args of the feature call args (FeatureResult.java:176). Replacing that line 176 with something similar to ScriptValue fixes the issue (JsonUtils.toPrettyJsonString(JsonPath.parse(temp));). Will review other usages and do some additional unit testing etc and will open a PR.

Something else to consider is that in the Runner class lines 316 and 323 when an Error exception class is thrown the thread hangs... although not typical might be worth considering catching a Throwable in the onFeatureDone() functions so that tests don't hang and the next line is executed ( latch.countDown() )

@ptrthomas
Copy link
Member

@joelpramos that is great news, do open a PR - you can use this ticket as a reference and I will re-open it. regarding the Runner - we have done that, but do see if it can be improved: #1216

@ptrthomas
Copy link
Member

same issue logged here, will investigate and fix there: #1231

ptrthomas added a commit that referenced this issue Jul 28, 2020
joelpramos added a commit to joelpramos/karate that referenced this issue Jul 28, 2020
…and additional tweak to pass such classes as parameters and use them
ptrthomas added a commit that referenced this issue Jul 29, 2020
Fix for issue #1225 (error printing in memory JVM classes) and additi…
joelpramos added a commit to joelpramos/karate that referenced this issue Oct 19, 2020
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

2 participants