Skip to content

Add support for running Testkit as part of Maven build #965

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

Merged
merged 1 commit into from
Jul 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,41 @@ Testkit is a tooling that is used to run integration tests for all of the driver
Some older tests still rely on [`boltkit`](https://github.com/neo4j-drivers/boltkit), the predecessor to Testkit.
If `boltkit` is not installed, then all tests that requires `boltkit` will be ignored and will not be executed.

In case you want or can verify contributions with unit tests alone, use the following command to skip all integration tests:
In case you want or can verify contributions with unit tests alone, use the following command to skip all integration and Testkit tests:

```
mvn clean install -DskipITs
mvn clean install -DskipITs -P skip-testkit
```

Otherwise, if you have Git, Python3 and Docker installed, please go ahead and clone Testkit and run as follows:
There are 2 ways of running Testkit tests:
1. Using the `testkit-tests` module of this project.
2. Manually cloning Testkit and running it directly.

##### Using the testkit-tests module

The `testkit-tests` module will automatically checkout Testkit and run it during Maven build.

Prerequisites:
- Docker
- `/var/run/docker.sock` available to be passed through to running containers.
This is required because Testkit needs access to Docker in order to launch additional containers.
- The driver project location must be sharable with Docker containers as Testkit container needs to have access to it.

Make sure to run build for the whole project and not just for `testkit-tests` module. Sample commands:
- `mvn clean verify` - runs all tests.
- `mvn clean verify -DskipTests` - skips all tests.
- `mvn clean verify -DtestkitArgs='--tests STUB_TESTS'` - runs all project tests and Testkit stub tests.
- `mvn clean verify -DskipTests -P testkit-tests` - skips all project tests and runs Testkit tests.
- `mvn clean verify -DskipTests -DtestkitArgs='--tests STUB_TESTS'` - skips all project tests and runs Testkit stub tests.

##### Running Testkit manually

Prerequisites:
- Docker
- Python3
- Git

Clone Testkit and run as follows:

```
git clone [email protected]:neo4j/neo4j-java-driver.git
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<module>driver</module>
<module>examples</module>
<module>testkit-backend</module>
<module>testkit-tests</module>
</modules>

<licenses>
Expand Down
179 changes: 179 additions & 0 deletions testkit-tests/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
<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>

<parent>
<groupId>org.neo4j.driver</groupId>
<artifactId>neo4j-java-driver-parent</artifactId>
<version>4.3-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>

<artifactId>testkit-tests</artifactId>

<name>Neo4j Java Driver Testkit Tests</name>
<description>Tests this driver using Testkit.</description>

<properties>
<rootDir>${project.basedir}/..</rootDir>

<testkit.url>https://github.com/neo4j-drivers/testkit.git</testkit.url>
<testkit.version>4.3</testkit.version>
<!-- See the testkit-custom-args profile if you want to customize this on individual runs. -->
<testkit.args>--tests TESTKIT_TESTS INTEGRATION_TESTS STUB_TESTS STRESS_TESTS TLS_TESTS</testkit.args>
<testkit.timeout>7200000</testkit.timeout>

<docker-maven-plugin.version>0.36.1</docker-maven-plugin.version>
<docker.showLogs>true</docker.showLogs>
</properties>

<build>
<plugins>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
</plugin>
</plugins>

<pluginManagement>
<plugins>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>${docker-maven-plugin.version}</version>

<configuration>
<images>
<image>
<name>testkit-launcher:%v</name>

<build>
<contextDir>${project.basedir}/src/main/docker</contextDir>
</build>

<run>
<!--
A sanitized version of the image’s short name from which this container is created.
As this Maven plugin does not currently remove Docker containers when Maven build is interrupted,
a unique name should prevent running multiple concurrent builds.
-->
<containerNamePattern>%n</containerNamePattern>
<wait>
<exit>0</exit>
<time>${testkit.timeout}</time>
</wait>
<env>
<TESTKIT_URL>${testkit.url}</TESTKIT_URL>
<TESTKIT_CHECKOUT_PATH>${project.build.directory}/testkit</TESTKIT_CHECKOUT_PATH>
<TESTKIT_VERSION>${testkit.version}</TESTKIT_VERSION>
<TESTKIT_ARGS>${testkit.args}</TESTKIT_ARGS>
<TEST_DRIVER_NAME>java</TEST_DRIVER_NAME>
<TEST_DRIVER_REPO>${rootDir}</TEST_DRIVER_REPO>
<TEST_SKIP_BUILD>true</TEST_SKIP_BUILD>
</env>
<volumes>
<bind>
<!--
Testkit requires access to Docker to launch other containers.
This is achieved by passing through the host's Docker socket.
-->
<volume>/var/run/docker.sock:/var/run/docker.sock</volume>
<!--
Testkit launches other containers and shares sources with them via volumes.
Given that Testkit runs in the container and uses the host's Docker instance,
the filesystem paths it uses must exist on the host system.
This is achieved by using the same path as on the host system.
-->
<volume>${rootDir}:${rootDir}</volume>
</bind>
</volumes>
</run>
</image>
</images>
</configuration>

<executions>
<execution>
<id>build-testkit-launcher</id>
<phase>pre-integration-test</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
<execution>
<id>run-testkit</id>
<phase>integration-test</phase>
<goals>
<!-- Testkit is expected to exit automatically. -->
<goal>start</goal>
</goals>
</execution>
<execution>
<id>remove-testkit-launcher</id>
<phase>post-integration-test</phase>
<goals>
<!-- This is to remove the stopped container. -->
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>

<profiles>
<!-- Skips running Testkit when tests are skipped. -->
<profile>
<id>skip-testkit</id>
<activation>
<property>
<name>skipTests</name>
</property>
</activation>
<properties>
<docker.skip>true</docker.skip>
</properties>
</profile>
<!-- Skips running Testkit in TeamCity as it is launched separately. -->
<profile>
<id>skip-testkit-teamcity</id>
<activation>
<property>
<name>env.TEAMCITY_VERSION</name>
</property>
</activation>
<properties>
<docker.skip>true</docker.skip>
</properties>
</profile>
<!-- Enables running Testkit when other tests are skipped. -->
<profile>
<id>testkit-tests</id>
<properties>
<docker.skip>false</docker.skip>
</properties>
</profile>
<!-- Enables passing custom arguments to Testkit and also enables running Testkit when other tests are skipped. -->
<profile>
<id>testkit-custom-args</id>
<activation>
<property>
<name>testkitArgs</name>
</property>
</activation>
<properties>
<docker.skip>false</docker.skip>
<testkit.args>${testkitArgs}</testkit.args>
</properties>
</profile>
<!-- Enables docker maven plugin verbose output. For instance, this can be useful for checking build logs. -->
<profile>
<id>testkit-docker-verbose</id>
<properties>
<docker.verbose>true</docker.verbose>
</properties>
</profile>
</profiles>
</project>
22 changes: 22 additions & 0 deletions testkit-tests/src/main/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM python:3.10.0b4-buster

RUN apt-get update && apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
gnupg \
lsb-release

RUN curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

RUN echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" \
| tee /etc/apt/sources.list.d/docker.list > /dev/null

RUN apt-get update && apt-get install -y \
docker-ce-cli

COPY /entrypoint.sh /

RUN chmod +x /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]
11 changes: 11 additions & 0 deletions testkit-tests/src/main/docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh

set -e

rm -rf $TESTKIT_CHECKOUT_PATH
git clone $TESTKIT_URL $TESTKIT_CHECKOUT_PATH
cd $TESTKIT_CHECKOUT_PATH
git checkout $TESTKIT_VERSION

echo "Testkit args: '$TESTKIT_ARGS'"
python main.py $TESTKIT_ARGS
3 changes: 2 additions & 1 deletion testkit/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
Responsible for building driver and test backend.
"""
import subprocess
import os


def run(args):
subprocess.run(
args, universal_newlines=True, stderr=subprocess.STDOUT, check=True)


if __name__ == "__main__":
if __name__ == "__main__" and "TEST_SKIP_BUILD" not in os.environ:
run(["mvn", "clean", "install", "-P", "!determine-revision", "-DskipTests"])