Skip to content

Commit b1dbb1d

Browse files
committed
wontfix for #1558 and adding docs for callSingle() limitations
1 parent f29ad40 commit b1dbb1d

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ function fn() {
794794
}
795795
```
796796

797-
> Here above, you see the [`karate.log()`](#karate-log), [`karate.env`](#karate-env) and [`karate.configure()`](#karate-configure) "helpers" being used. Note that the `karate-config.js` is re-processed for *every* `Scenario` and in rare cases, you may want to initialize (e.g. auth tokens) only once for all of your tests. This can be achieved using [`karate.callSingle()`](#karate-callsingle).
797+
> Here above, you see the [`karate.log()`](#karate-log), [`karate.env`](#karate-env) and [`karate.configure()`](#karate-configure) "helpers" being used. Note that the `karate-config.js` is re-processed for *every* `Scenario` and in rare cases, you may want to initialize (e.g. auth tokens) only once for all of your tests. This can be achieved using [`karate.callSingle()`](#karatecallsingle).
798798
799799
A common requirement is to pass dynamic parameter values via the command line, and you can use the [`karate.properties['some.name']`](#karate-properties) syntax for getting a system property passed via JVM options in the form `-Dsome.name=foo`. Refer to the section on [dynamic port numbers](#dynamic-port-numbers) for an example.
800800

@@ -3913,6 +3913,8 @@ Refer to this example:
39133913

39143914
You *can* use `karate.callSingle()` directly in a `*.feature` file, but it logically fits better in the global "bootstrap". Ideally it should return "pure JSON" and note that you always get a "deep clone" of the cached result object.
39153915

3916+
IMPORTANT: There are some restrictions when using `karate.callSingle()` especially within [`karate-config.js`](#karate-configjs). Ideally you should return only *pure* JSON data (or a primitive string, number etc.). Keep in mind that the reason this exists is to "cache" data, and *not* behavior. So if you return complex objects such as a custom Java instance or a JS function that depends on complex objects, this [will cause issues when you run in parallel](https://github.com/intuit/karate/issues/1558).
3917+
39163918
#### `configure callSingleCache`
39173919
When re-running tests in development mode and when your test suite depends on say an `Authorization` header set by [`karate.callSingle()`](#karatecallsingle), you can cache the results locally to a file, which is very convenient when your "auth token" is valid for a period of a few minutes - which typically is the case. This means that as long as the token "on file" is valid, you can save time by not having to make the one or two HTTP calls needed to "sign-in" or create "throw-away" users in your SSO store.
39183920

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.intuit.karate.core.parallel;
2+
3+
/**
4+
*
5+
* @author pthomas3
6+
*/
7+
public class Hello {
8+
9+
public static String sayHello(String message) {
10+
return "hello " + message;
11+
}
12+
13+
}

karate-core/src/test/java/com/intuit/karate/core/parallel/call-single-from-config.feature

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ Scenario:
88
* match response == { message: 'from config' }
99

1010
* def functionFromCallSingleFromConfig = function(){ return 'resultFromFunctionFromCallSingleFromConfig' }
11+
* def Hello = Java.type('com.intuit.karate.core.parallel.Hello')

karate-core/src/test/java/com/intuit/karate/core/parallel/karate-config.js

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ function fn() {
55
};
66
var result = karate.callSingle('call-single-from-config.feature', config);
77
config.message = result.response.message;
8+
// this will throw the [Multi threaded access requested by thread xxx but is not allowed for language(s) js.] error
9+
// config.Hello = result.Hello;
810
var result2 = karate.callSingle('call-single-from-config2.feature', result);
911
config.message2 = result2.message;
1012
return config;

0 commit comments

Comments
 (0)