-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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.callSingle/callonce crashes where karate.call succeeds #1633
Comments
@zgael so I've reached the limit of my patience with #1558 and am declaring this a won't fix. you can read that thread for the gory details. but you are super-most-welcome to dive into the code and see what we may have missed. I've added tests that replicate this problem - just comment out 1 line in so please don't mix java functions into a callSingle. we struggled to get java class-types into a callSingle. why on earth do people use a call-single and mix Java methods into it >_< please don't. I'm tempted to declare that cc @joelpramos and @ericdriggs - if you can re-test your project that had the problem in the other thread that would help, because I changed things around again |
@ptrthomas it is frustrating but from a capability perspective not sure whether we should call it a Since I've revisited this piece a few times I'll try my best to check this example in the coming weeks when I have some time. |
@joelpramos sure. I still think that putting ANY kind of Java (class / or methods) does not make sense for a callSingle() |
and try to prevent occasional ci failure mentioned here: #1633 (comment)
I just realized what you meant with Java functions... The results of Java functions calls can still be stored / used it's just storing a reference to a function that does not work. I'm inclined to agree with you that's not THAT problematic in that case (if really needed store the class) :) I just tried a fix by wrapping the Java function with a Graal Proxy. Saw something similar here https://lburgazzoli.github.io/2018/08/06/Adventures-in-GraalVM-invoke-Java-code-from-JS-in-native-image.html which reminded me that I read somewhere before when investigating this that proxying calls was a viable solution. Seems to pass the unit test but would need @zgael to confirm and your review. |
@joelpramos wow, it seems to work ! that is a good find, I had no idea. re-opening for @zgael to confirm |
@joelpramos build just started failing consistently :| looks like github actions upgraded the os or jvm |
We have a workaround, that is indeed "call methods on Now that it doesn't work in 1+ versions, we obviously can use the workaround, but I prefered to open an issue to improve karate :) I'll be happy to test and confirm it works in my case, but I'm unavailable until the end of the month, so I can only test it by then. |
sure. one of the points above is that you shouldn't put Java methods and such in a for readability, you can wrap it into a feature following the instructions here: https://github.com/intuit/karate#multiple-functions-in-one-file no not too late, as of now I consider we are done with the fixes here. FWIW here is what we have in the documentation in the next version - screenshot below: https://github.com/intuit/karate/tree/develop#karatecallsingle |
ugh any ideas on how to triage that don't involve keep using github actions? do you know if there's a page where they post any sort of us / java updates? |
am only aware of pages like this @joelpramos https://jdk.java.net/java-se-ri/11 |
I'm back with good news ! Latest develop branch (commit a383a00) works for my case.
In "old" karate versions (between 1.0.0 and 1.1.0.RC2), the Plus, both of those work with latest develop branch (commit a383a00), so I guess that's a good job with all those attempts @ptrthomas @joelpramos ! Thanks for your time. |
@zgael okay, that's great to hear. but there is a catch, if you invoke |
to be clear. you can pass a "java type" around. just that "java method references" are not recommended because they retain the originating JS context. so you should be able to do this: config.fails = function(x){ return Java.type('package.CustomJavaClass').fails(x) } but again, the recommendation is that you should not return functions (even JS ones) from a |
which is to pass java functions around as Function instances not JS snippets which means they become graal host objects - which do not have the multi-threading issues added some docs to make this clear etc
attention all cc @zgael @joelpramos @aleruz I figured out a way where you can use Java functions safely even within a see doc screenshot below, and direct link is here: https://github.com/intuit/karate/tree/develop#java-function-references |
Hi,
In our karate-config, I use a lot of Java.type('XXX') to call custom Java code.
As it is somehow "heavy" (authentication against a provider), I want this to get called only once for all my tests, and not before each of my 400+ tests (thus the callSingle in karate-config, instead of having all the code in karate-config).
In karate 0.9.6, the following worked :
karate-config.js :
load-config.js :
while it crashes using the latest Karate releases (tried with both 1.0.1 and 1.1.0.RC2) with following stacktrace :
I know there have been huge changes from 0.9.6 to 1+, but what bugs me is that using
karate.call('classpath:load-config.js')
works in karate 1+ versions.So, the behavior is different between karate.call and karate.callSingle.
After some digging into karate inner sources, starting from ScenarioBridge, and some testing, the problem is due to the fact
spec
is a function, andkarate.call
andkarate.callSingle
handle functions differently.To my understanding, those functions should have the same behavior, with the latter caching the result for subsequent calls.
Am I wrong ?
I set up a minimal project in this repo for easier reproduction.
https://github.com/zgael/karateconfig
Feel free to ask for clarifications if needed !
Thanks!
The text was updated successfully, but these errors were encountered: