Skip to content

Commit b6c2534

Browse files
committed
Add support for running Testkit as part of Maven build
1 parent 3bf4add commit b6c2534

File tree

6 files changed

+238
-4
lines changed

6 files changed

+238
-4
lines changed

README.md

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

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

111111
```
112-
mvn clean install -DskipITs
112+
mvn clean install -DskipITs -P skip-testkit
113113
```
114114

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

117145
```
118146
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: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
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+
</executions>
113+
</plugin>
114+
</plugins>
115+
</pluginManagement>
116+
</build>
117+
118+
<profiles>
119+
<!-- Skips running Testkit when tests are skipped. -->
120+
<profile>
121+
<id>skip-testkit</id>
122+
<activation>
123+
<property>
124+
<name>skipTests</name>
125+
</property>
126+
</activation>
127+
<properties>
128+
<docker.skip>true</docker.skip>
129+
</properties>
130+
</profile>
131+
<!-- Skips running Testkit in TeamCity as it is launched separately. -->
132+
<profile>
133+
<id>skip-testkit-teamcity</id>
134+
<activation>
135+
<property>
136+
<name>env.TEAMCITY_VERSION</name>
137+
</property>
138+
</activation>
139+
<properties>
140+
<docker.skip>true</docker.skip>
141+
</properties>
142+
</profile>
143+
<!-- Enables running Testkit when other tests are skipped. -->
144+
<profile>
145+
<id>testkit-tests</id>
146+
<properties>
147+
<docker.skip>false</docker.skip>
148+
</properties>
149+
</profile>
150+
<!-- Enables passing custom arguments to Testkit and also enables running Testkit when other tests are skipped. -->
151+
<profile>
152+
<id>testkit-custom-args</id>
153+
<activation>
154+
<property>
155+
<name>testkitArgs</name>
156+
</property>
157+
</activation>
158+
<properties>
159+
<docker.skip>false</docker.skip>
160+
<testkit.args>${testkitArgs}</testkit.args>
161+
</properties>
162+
</profile>
163+
<!-- Enables docker maven plugin verbose output. For instance, this can be useful for checking build logs. -->
164+
<profile>
165+
<id>testkit-docker-verbose</id>
166+
<properties>
167+
<docker.verbose>true</docker.verbose>
168+
</properties>
169+
</profile>
170+
</profiles>
171+
</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)