javakarate

Connection reset error - when running mvn clean install to run features


We have generated a karate test project using the Maven archetype, to test several different API services. We have a feature file that conducts a test with an endpoint, which works fine when this endpoint is locally running on our machine. However, we would like to run these karate tests in a CI environment where we use a url to our (deployed) service on a dev environment. When we run mvn clean install on our CI pipeline, we get an error when running the feature:

 com.intuit.karate.exception.KarateException:
 MyFeatureTest.feature:8 -
 java.net.SocketException: Connection reset

Our configuration

pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.mycompany.app</groupId>
  <artifactId>our-karate-tests</artifactId>
  <version>1.0-SNAPSHOT</version>

  <properties>
    <java.version>1.8</java.version>
    <maven.compiler.version>3.6.0</maven.compiler.version>
    <karate.version>0.9.5</karate.version>
  </properties>

  <dependencies>
    <dependency>
        <groupId>com.intuit.karate</groupId>
        <artifactId>karate-apache</artifactId>
        <version>${karate.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.intuit.karate</groupId>
        <artifactId>karate-junit4</artifactId>
        <version>${karate.version}</version>
        <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
        <testResources>
            <testResource>
                <directory>src/test/java</directory>
                <excludes>
                    <exclude>**/*.java</exclude>
                </excludes>
            </testResource>
        </testResources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven.compiler.version}</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                    <compilerArgument>-Werror</compilerArgument>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.2</version>
            </plugin>            
        </plugins>        
    </build>       
</project>

MyFeatureTest.java

import com.intuit.karate.KarateOptions;
import com.intuit.karate.junit4.Karate;
import com.junit.runner.RunWith;

@RunWith(Karate.class)
@KarateOptions(features="classpath:MyFeatureTest.feature")
public class MyFeatureTest {
}

MyFeatureTest.feature

Feature: test an endpoint
    Background:
        * url 'https://dev.myapplication.com/api/signin'
        * configure ssl = true

    Scenario: test request
        Given request {"username":"john", "password":"doe"}
        When method post
        Then status 200
        And match response == {resp:"success"}

What we have tried:

We are able to call the service through Postman without any problem (both locally and the deployed service). We have also tried executing different methods, for example get. The strange part out of all this is that the connection reset error occurs in our CI environment, but when we run the feature locally, we get a org.apache.http.conn.ConnectTimeoutException: connect to https://dev.myapplication.com:443 failed: connection timeout.

We have a feeling it is related to the karate-apache client, but we have also tried to use apache-jersey. Unfortunately, we get the same problem when we use the jersey client as well. We also thought it might be related to SSL. However, even when using a non ssl service (and remove the ssl configuration from the feature), the same problem occurs. We have tried to test responses from non-https websites like web.archive.org as well as https ones like google.com, in a futile attempt as well where we simply test a GET request. Still, the same issue occurs.


Solution

  • Sounds very much like you have an HTTP proxy to deal with.

    Refer to the docs if that is the case: https://github.com/intuit/karate#configure

    * configure proxy = 'http://my.proxy.host:8080'