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

Parallel execution is not working properly making one thread to wait for another to finish the action #2222

Closed
Shcherbakoval opened this issue Dec 19, 2022 · 4 comments
Assignees
Milestone

Comments

@Shcherbakoval
Copy link

Description:
It looks like the parallel execution of Scenarios behaves more like a blocking queue, making one thread to wait for another to finish the action it doing at the moment. The action could anything like executing JS, Java code or making an HTTP call.

Steps to reproduce:
In the attached zip run the ExampleTest.java which is set to run a single Feature file containing 2 Scenarios both doing the same thing:

  1. Print test name
  2. Sleep for 2 seconds
  3. Print wake up message

Actual result:
Both Scenarios are executed, one of them actually was sleeping for 2 seconds, another one however been sleeping for 4 seconds, thus waiting for the first Scenario to sleep and then start sleeping itself.

16:52:06.984 [pool-1-thread-1] INFO com.intuit.karate - Test 1 About to sleep for 2 seconds
16:52:06.984 [pool-1-thread-2] INFO com.intuit.karate - Test 2 About to sleep for 2 seconds
16:52:09.006 [pool-1-thread-1] INFO com.intuit.karate - Test 1 Woke up
16:52:11.010 [pool-1-thread-2] INFO com.intuit.karate - Test 2 Woke up

Expected result:
Both Scenarios should've slept for 2 seconds and not block each others execution. Producing the output like this, where difference between calls is actually 2 seconds

2022-12-19T16:49:33.850375 Thread-0 is about to sleep for 2 Seconds
2022-12-19T16:49:33.850422 Thread-1 is about to sleep for 2 Seconds
2022-12-19T16:49:35.874877 Thread-0 woke up after sleeping for 2 Seconds
2022-12-19T16:49:35.874139 Thread-1 woke up after sleeping for 2 Seconds

karateTest.zip

You can run this either from your favourite IDE or simply using mvn clean test.

@ptrthomas ptrthomas added wontfix and removed wontfix labels Dec 20, 2022
@ptrthomas
Copy link
Member

@Shcherbakoval this is good catch and thanks for this. but first let me correct you - the blocking only happens for JS code and not the other workloads (Java, normal HTTP calls). as proof try to run this test:

Feature: test sample feature

  Scenario: test1
    * karate.log("Test 1 About to sleep for 2 seconds")
    * java.lang.Thread.sleep(2000)
    * karate.log("Test 1 Woke up")

  Scenario: test2
    * karate.log("Test 2 About to sleep for 2 seconds")
    * java.lang.Thread.sleep(2000)
    * karate.log("Test 2 Woke up")

and you can look at the timeline report for confirmation:

image

So yes, we have this limitation that any JS code executed will perform a global lock. we don't like it - but there is a big history for this, refer: #2081

in my experience, and from what we hear from enterprise users, this is not an issue for normal tests as long as you ensure that any JS you use is only for utilities and business logic. if you use karate.callSingle() you can cache the results up-front and use it for all your tests.

@Shcherbakoval you are most welcome to contribute thoughts, ideas and ideally code to improve this ;) I will leave this open for a while for discussion, else close this as wontfix

@ptrthomas
Copy link
Member

closing because of no response

ptrthomas added a commit that referenced this issue Jan 31, 2023
and #2222 could be a consequence of that
so we are making sure that any js functions in a callSingle result
are re-hydrated to current context
ptrthomas added a commit that referenced this issue Feb 4, 2023
ptrthomas added a commit that referenced this issue Feb 4, 2023
This reverts commit 94d7afe.

ci failed although it worked locally, so abort this attempt
ptrthomas added a commit that referenced this issue Feb 4, 2023
ptrthomas added a commit that referenced this issue Feb 4, 2023
that was very stable for a while #2222 #2204
@ptrthomas ptrthomas self-assigned this Feb 7, 2023
@ptrthomas ptrthomas added bug and removed wontfix labels Feb 7, 2023
@ptrthomas ptrthomas added this to the 1.4.0 milestone Feb 7, 2023
@ptrthomas ptrthomas reopened this Feb 7, 2023
@ptrthomas
Copy link
Member

reopening as there is one more report of this: https://stackoverflow.com/q/75371624/143475

considering high priority. please try to build from source until we release 1.4.0.RC4: https://github.com/karatelabs/karate/wiki/Developer-Guide

ptrthomas added a commit that referenced this issue Mar 27, 2023
failing test was ParallelOutlineTest.testParallelOutline
@ptrthomas ptrthomas added the fixed label Apr 2, 2023
@ptrthomas
Copy link
Member

1.4.0 released

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