Skip to content

Commit 82ffb5e

Browse files
committed
resolve callonce issue #1665 #1558
1 parent ad2fcee commit 82ffb5e

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

karate-core/src/main/java/com/intuit/karate/core/ScenarioEngine.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -2008,7 +2008,15 @@ private Variable callOnceResult(ScenarioCall.Result result, boolean sharedScope)
20082008
vars.clear(); // clean slate
20092009
// deep-clone so that subsequent steps don't modify data / references being passed around
20102010
if (result.vars != null) {
2011-
result.vars.forEach((k, v) -> vars.put(k, v.copy(true)));
2011+
Set<Object> seen = Collections.newSetFromMap(new IdentityHashMap());
2012+
result.vars.forEach((k, v) -> {
2013+
Object o = recurseAndAttachAndDeepClone(k, v.getValue(), seen);
2014+
try {
2015+
vars.put(k, new Variable(o));
2016+
} catch (Exception e) {
2017+
logger.warn("[*** callonce result ***] ignoring non-json value: '{}' - {}", k, e.getMessage());
2018+
}
2019+
});
20122020
}
20132021
init(); // this will attach and also insert magic variables
20142022
// re-apply config from time of snapshot

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ Scenario:
44
* print 'before configure headers'
55
* configure headers = read('headers.js')
66
* def message = 'from common'
7-
* def HelloOnce = Java.type('com.intuit.karate.core.parallel.Hello');
7+
* def HelloOnce = Java.type('com.intuit.karate.core.parallel.Hello')
8+
* def sayHelloOnce = function(name){ return 'hello ' + name }

karate-core/src/test/java/com/intuit/karate/core/parallel/parallel.feature

+7-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Background:
99
* match message2 == 'fromCallSingleFromConfig2'
1010

1111
Scenario: one
12+
* call sayHelloOnce 'one'
1213
* path 'one'
1314
* method get
1415
* status 200
@@ -19,8 +20,10 @@ Scenario: one
1920
* match HelloConfigSingle.sayHello('world') == 'hello world'
2021
* match HelloOnce.sayHello('world') == 'hello world'
2122
* match sayHello('world') == 'hello world'
23+
* match sayHelloOnce('world') == 'hello world'
2224

2325
Scenario: two
26+
* call sayHelloOnce 'two'
2427
* path 'two'
2528
* method get
2629
* status 200
@@ -31,8 +34,10 @@ Scenario: two
3134
* match HelloConfigSingle.sayHello('world') == 'hello world'
3235
* match HelloOnce.sayHello('world') == 'hello world'
3336
* match sayHello('world') == 'hello world'
37+
* match sayHelloOnce('world') == 'hello world'
3438

3539
Scenario: three
40+
* call sayHelloOnce 'three'
3641
* path 'three'
3742
* method get
3843
* status 200
@@ -42,4 +47,5 @@ Scenario: three
4247

4348
* match HelloConfigSingle.sayHello('world') == 'hello world'
4449
* match HelloOnce.sayHello('world') == 'hello world'
45-
* match sayHello('world') == 'hello world'
50+
* match sayHello('world') == 'hello world'
51+
* match sayHelloOnce('world') == 'hello world'

0 commit comments

Comments
 (0)