Skip to content

Commit 13e1829

Browse files
authored
Add support for running Testkit as part of Maven build (#965)
1 parent cecaddf commit 13e1829

File tree

6 files changed

+246
-4
lines changed

6 files changed

+246
-4
lines changed

README.md

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,41 @@ Testkit is a tooling that is used to run integration tests for all of the driver
102102
Some older tests still rely on [`boltkit`](https://github.com/neo4j-drivers/boltkit), the predecessor to Testkit.
103103
If `boltkit` is not installed, then all tests that requires `boltkit` will be ignored and will not be executed.
104104

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

107107
```
108-
mvn clean install -DskipITs
108+
mvn clean install -DskipITs -P skip-testkit
109109
```
110110

111-
Otherwise, if you have Git, Python3 and Docker installed, please go ahead and clone Testkit and run as follows:
111+
There are 2 ways of running Testkit tests:
112+
1. Using the `testkit-tests` module of this project.
113+
2. Manually cloning Testkit and running it directly.
114+
115+
##### Using the testkit-tests module
116+
117+
The `testkit-tests` module will automatically checkout Testkit and run it during Maven build.
118+
119+
Prerequisites:
120+
- Docker
121+
- `/var/run/docker.sock` available to be passed through to running containers.
122+
This is required because Testkit needs access to Docker in order to launch additional containers.
123+
- The driver project location must be sharable with Docker containers as Testkit container needs to have access to it.
124+
125+
Make sure to run build for the whole project and not just for `testkit-tests` module. Sample commands:
126+
- `mvn clean verify` - runs all tests.
127+
- `mvn clean verify -DskipTests` - skips all tests.
128+
- `mvn clean verify -DtestkitArgs='--tests STUB_TESTS'` - runs all project tests and Testkit stub tests.
129+
- `mvn clean verify -DskipTests -P testkit-tests` - skips all project tests and runs Testkit tests.
130+
- `mvn clean verify -DskipTests -DtestkitArgs='--tests STUB_TESTS'` - skips all project tests and runs Testkit stub tests.
131+
132+
##### Running Testkit manually
133+
134+
Prerequisites:
135+
- Docker
136+
- Python3
137+
- Git
138+
139+
Clone Testkit and run as follows:
112140

113141
```
114142
git clone [email protected]:neo4j/neo4j-java-driver.git

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
<module>driver</module>
5151
<module>examples</module>
5252
<module>testkit-backend</module>
53+
<module>testkit-tests</module>
5354
</modules>
5455

5556
<licenses>

testkit-tests/pom.xml

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
3+
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<parent>
7+
<groupId>org.neo4j.driver</groupId>
8+
<artifactId>neo4j-java-driver-parent</artifactId>
9+
<version>4.3-SNAPSHOT</version>
10+
<relativePath>..</relativePath>
11+
</parent>
12+
13+
<artifactId>testkit-tests</artifactId>
14+
15+
<name>Neo4j Java Driver Testkit Tests</name>
16+
<description>Tests this driver using Testkit.</description>
17+
18+
<properties>
19+
<rootDir>${project.basedir}/..</rootDir>
20+
21+
<testkit.url>https://github.com/neo4j-drivers/testkit.git</testkit.url>
22+
<testkit.version>4.3</testkit.version>
23+
<!-- See the testkit-custom-args profile if you want to customize this on individual runs. -->
24+
<testkit.args>--tests TESTKIT_TESTS INTEGRATION_TESTS STUB_TESTS STRESS_TESTS TLS_TESTS</testkit.args>
25+
<testkit.timeout>7200000</testkit.timeout>
26+
27+
<docker-maven-plugin.version>0.36.1</docker-maven-plugin.version>
28+
<docker.showLogs>true</docker.showLogs>
29+
</properties>
30+
31+
<build>
32+
<plugins>
33+
<plugin>
34+
<groupId>io.fabric8</groupId>
35+
<artifactId>docker-maven-plugin</artifactId>
36+
</plugin>
37+
</plugins>
38+
39+
<pluginManagement>
40+
<plugins>
41+
<plugin>
42+
<groupId>io.fabric8</groupId>
43+
<artifactId>docker-maven-plugin</artifactId>
44+
<version>${docker-maven-plugin.version}</version>
45+
46+
<configuration>
47+
<images>
48+
<image>
49+
<name>testkit-launcher:%v</name>
50+
51+
<build>
52+
<contextDir>${project.basedir}/src/main/docker</contextDir>
53+
</build>
54+
55+
<run>
56+
<!--
57+
A sanitized version of the image’s short name from which this container is created.
58+
As this Maven plugin does not currently remove Docker containers when Maven build is interrupted,
59+
a unique name should prevent running multiple concurrent builds.
60+
-->
61+
<containerNamePattern>%n</containerNamePattern>
62+
<wait>
63+
<exit>0</exit>
64+
<time>${testkit.timeout}</time>
65+
</wait>
66+
<env>
67+
<TESTKIT_URL>${testkit.url}</TESTKIT_URL>
68+
<TESTKIT_CHECKOUT_PATH>${project.build.directory}/testkit</TESTKIT_CHECKOUT_PATH>
69+
<TESTKIT_VERSION>${testkit.version}</TESTKIT_VERSION>
70+
<TESTKIT_ARGS>${testkit.args}</TESTKIT_ARGS>
71+
<TEST_DRIVER_NAME>java</TEST_DRIVER_NAME>
72+
<TEST_DRIVER_REPO>${rootDir}</TEST_DRIVER_REPO>
73+
<TEST_SKIP_BUILD>true</TEST_SKIP_BUILD>
74+
</env>
75+
<volumes>
76+
<bind>
77+
<!--
78+
Testkit requires access to Docker to launch other containers.
79+
This is achieved by passing through the host's Docker socket.
80+
-->
81+
<volume>/var/run/docker.sock:/var/run/docker.sock</volume>
82+
<!--
83+
Testkit launches other containers and shares sources with them via volumes.
84+
Given that Testkit runs in the container and uses the host's Docker instance,
85+
the filesystem paths it uses must exist on the host system.
86+
This is achieved by using the same path as on the host system.
87+
-->
88+
<volume>${rootDir}:${rootDir}</volume>
89+
</bind>
90+
</volumes>
91+
</run>
92+
</image>
93+
</images>
94+
</configuration>
95+
96+
<executions>
97+
<execution>
98+
<id>build-testkit-launcher</id>
99+
<phase>pre-integration-test</phase>
100+
<goals>
101+
<goal>build</goal>
102+
</goals>
103+
</execution>
104+
<execution>
105+
<id>run-testkit</id>
106+
<phase>integration-test</phase>
107+
<goals>
108+
<!-- Testkit is expected to exit automatically. -->
109+
<goal>start</goal>
110+
</goals>
111+
</execution>
112+
<execution>
113+
<id>remove-testkit-launcher</id>
114+
<phase>post-integration-test</phase>
115+
<goals>
116+
<!-- This is to remove the stopped container. -->
117+
<goal>stop</goal>
118+
</goals>
119+
</execution>
120+
</executions>
121+
</plugin>
122+
</plugins>
123+
</pluginManagement>
124+
</build>
125+
126+
<profiles>
127+
<!-- Skips running Testkit when tests are skipped. -->
128+
<profile>
129+
<id>skip-testkit</id>
130+
<activation>
131+
<property>
132+
<name>skipTests</name>
133+
</property>
134+
</activation>
135+
<properties>
136+
<docker.skip>true</docker.skip>
137+
</properties>
138+
</profile>
139+
<!-- Skips running Testkit in TeamCity as it is launched separately. -->
140+
<profile>
141+
<id>skip-testkit-teamcity</id>
142+
<activation>
143+
<property>
144+
<name>env.TEAMCITY_VERSION</name>
145+
</property>
146+
</activation>
147+
<properties>
148+
<docker.skip>true</docker.skip>
149+
</properties>
150+
</profile>
151+
<!-- Enables running Testkit when other tests are skipped. -->
152+
<profile>
153+
<id>testkit-tests</id>
154+
<properties>
155+
<docker.skip>false</docker.skip>
156+
</properties>
157+
</profile>
158+
<!-- Enables passing custom arguments to Testkit and also enables running Testkit when other tests are skipped. -->
159+
<profile>
160+
<id>testkit-custom-args</id>
161+
<activation>
162+
<property>
163+
<name>testkitArgs</name>
164+
</property>
165+
</activation>
166+
<properties>
167+
<docker.skip>false</docker.skip>
168+
<testkit.args>${testkitArgs}</testkit.args>
169+
</properties>
170+
</profile>
171+
<!-- Enables docker maven plugin verbose output. For instance, this can be useful for checking build logs. -->
172+
<profile>
173+
<id>testkit-docker-verbose</id>
174+
<properties>
175+
<docker.verbose>true</docker.verbose>
176+
</properties>
177+
</profile>
178+
</profiles>
179+
</project>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
FROM python:3.10.0b4-buster
2+
3+
RUN apt-get update && apt-get install -y \
4+
apt-transport-https \
5+
ca-certificates \
6+
curl \
7+
gnupg \
8+
lsb-release
9+
10+
RUN curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
11+
12+
RUN echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" \
13+
| tee /etc/apt/sources.list.d/docker.list > /dev/null
14+
15+
RUN apt-get update && apt-get install -y \
16+
docker-ce-cli
17+
18+
COPY /entrypoint.sh /
19+
20+
RUN chmod +x /entrypoint.sh
21+
22+
ENTRYPOINT ["/entrypoint.sh"]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
rm -rf $TESTKIT_CHECKOUT_PATH
6+
git clone $TESTKIT_URL $TESTKIT_CHECKOUT_PATH
7+
cd $TESTKIT_CHECKOUT_PATH
8+
git checkout $TESTKIT_VERSION
9+
10+
echo "Testkit args: '$TESTKIT_ARGS'"
11+
python main.py $TESTKIT_ARGS

testkit/build.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
Responsible for building driver and test backend.
44
"""
55
import subprocess
6+
import os
67

78

89
def run(args):
910
subprocess.run(
1011
args, universal_newlines=True, stderr=subprocess.STDOUT, check=True)
1112

1213

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

0 commit comments

Comments
 (0)