kpschmidt
kpschmidt

Reputation: 245

Possible issue with Karate testParallel runner

I'll apologize up-front for not being able to post actual code that exhibits this possible issue as it is confidential, but I wanted to see if anyone else might have observed the same issue. I looked in the project for any open/closed issues that might be like this but did not notice any.

I noticed that when I use the Karate testParallel runner (which we have been using for a while now), that every GET, POST, DELETE request issued gets called 2x, observed in the karate logs.

It doesn't matter if the request is being directly called in a scenario or indirectly from another feature file via call/callonce.

When I do not use the Karate testParallel runner only a single request is made.

I noticed this when performing a POST to create a a data source in our application. When I went to the applications UI to verify the new data source was created, I saw 2 of them. This lead me down the path to research further what might be happening.

To possibly rule out our API was doubling up on the data source creation, a data source was created via a totally different internal tool and only 1 data source got created. This lead me back to Karate to see what might be causing the double creation and observing the issue.

Bottom-line is that I think the parallel runner is causing requests to occur twice.

Using Karate v0.9.3

When using the parallel test runner, multiple POST's get executed. The code below uses the Post Test Server V2 to submit a POST to and you can see that 2 posts are submitted.

Note the test runner is NOT using the @RunWith(Karate.class) annotation and using the junit:4.12 transient dependency from karate-junit4:0.9.3

Here is a Minimal, Complete and Verifiable example that demonstrates the issue:

Feature file:

Feature: Demonstrates multiple POST requests

Scenario: Demonstrates multiple POST requests using parallel runner
    * def REQUEST = {type: 'test-type', name: 'test-name'}
    Given url 'https://ptsv2.com/t/paowv-1563551220/post'
    And request REQUEST
    When method POST
    Then status 200

Parallel Test Runner file:

import com.intuit.karate.Results;
import com.intuit.karate.Runner;
import org.junit.Test;


public class ApiTest {
    @Test
    public void testParallel() {
        Results results = Runner.parallel(getClass(), 5, "target/surefire-reports");
        assertTrue(results.getErrorMessages(), results.getFailCount() == 0);
    }
}

After running this feature, using the parallel runner, go to https://ptsv2.com/t/paowv-1563551220/post and observe the multiple POST's.

Comment out the @Test JUnit annotation in the parallel runner and re-run feature and notice only 1 POST is requested, as expected.

Upvotes: 1

Views: 4049

Answers (2)

kpschmidt
kpschmidt

Reputation: 245

When I originally posted this question I was definitely using a JUnit 4 Parallel Execution class without the @RunWith(Karate.class) annotation. This was in conjunction with the com.intuit.karate:karate-junit4 dependency and I was definitely getting multiple POST requests sent.

In revisiting this issue, I recently updated my dependency to use com.intuit.karate:karate-junit5 and updated to use a JUnit 5 Parallel Execution class (again, without the @RunWith(Karate.class) annotation) and I'm happy to report that I'm no longer seeing multiple POST requests.

Upvotes: 1

Peter Thomas
Peter Thomas

Reputation: 58058

You most likely are using the @RunWith(Karate.class) annotation when you are not supposed to. This is mentioned in the docs. Fortunately this confusion will go away when everyone switches to JUnit 5.

Upvotes: 0

Related Questions