Skip to content

Commit

Permalink
resolve callonce issue #1665 #1558
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrthomas committed Jul 1, 2021
1 parent ad2fcee commit 82ffb5e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2008,7 +2008,15 @@ private Variable callOnceResult(ScenarioCall.Result result, boolean sharedScope)
vars.clear(); // clean slate
// deep-clone so that subsequent steps don't modify data / references being passed around
if (result.vars != null) {
result.vars.forEach((k, v) -> vars.put(k, v.copy(true)));
Set<Object> seen = Collections.newSetFromMap(new IdentityHashMap());
result.vars.forEach((k, v) -> {
Object o = recurseAndAttachAndDeepClone(k, v.getValue(), seen);
try {
vars.put(k, new Variable(o));
} catch (Exception e) {
logger.warn("[*** callonce result ***] ignoring non-json value: '{}' - {}", k, e.getMessage());
}
});
}
init(); // this will attach and also insert magic variables
// re-apply config from time of snapshot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ Scenario:
* print 'before configure headers'
* configure headers = read('headers.js')
* def message = 'from common'
* def HelloOnce = Java.type('com.intuit.karate.core.parallel.Hello');
* def HelloOnce = Java.type('com.intuit.karate.core.parallel.Hello')
* def sayHelloOnce = function(name){ return 'hello ' + name }
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Background:
* match message2 == 'fromCallSingleFromConfig2'

Scenario: one
* call sayHelloOnce 'one'
* path 'one'
* method get
* status 200
Expand All @@ -19,8 +20,10 @@ Scenario: one
* match HelloConfigSingle.sayHello('world') == 'hello world'
* match HelloOnce.sayHello('world') == 'hello world'
* match sayHello('world') == 'hello world'
* match sayHelloOnce('world') == 'hello world'

Scenario: two
* call sayHelloOnce 'two'
* path 'two'
* method get
* status 200
Expand All @@ -31,8 +34,10 @@ Scenario: two
* match HelloConfigSingle.sayHello('world') == 'hello world'
* match HelloOnce.sayHello('world') == 'hello world'
* match sayHello('world') == 'hello world'
* match sayHelloOnce('world') == 'hello world'

Scenario: three
* call sayHelloOnce 'three'
* path 'three'
* method get
* status 200
Expand All @@ -42,4 +47,5 @@ Scenario: three

* match HelloConfigSingle.sayHello('world') == 'hello world'
* match HelloOnce.sayHello('world') == 'hello world'
* match sayHello('world') == 'hello world'
* match sayHello('world') == 'hello world'
* match sayHelloOnce('world') == 'hello world'

0 comments on commit 82ffb5e

Please sign in to comment.