Skip to content

Commit 80d2db3

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

File tree

6 files changed

+236
-4
lines changed

6 files changed

+236
-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: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
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.version>4.3</testkit.version>
22+
<!-- See the testkit-custom-args profile if you want to customize this on individual runs. -->
23+
<testkit.args>--tests TESTKIT_TESTS INTEGRATION_TESTS STUB_TESTS STRESS_TESTS TLS_TESTS</testkit.args>
24+
<testkit.timeout>7200000</testkit.timeout>
25+
26+
<docker-maven-plugin.version>0.36.1</docker-maven-plugin.version>
27+
<docker.showLogs>true</docker.showLogs>
28+
</properties>
29+
30+
<build>
31+
<plugins>
32+
<plugin>
33+
<groupId>io.fabric8</groupId>
34+
<artifactId>docker-maven-plugin</artifactId>
35+
</plugin>
36+
</plugins>
37+
38+
<pluginManagement>
39+
<plugins>
40+
<plugin>
41+
<groupId>io.fabric8</groupId>
42+
<artifactId>docker-maven-plugin</artifactId>
43+
<version>${docker-maven-plugin.version}</version>
44+
45+
<configuration>
46+
<images>
47+
<image>
48+
<name>testkit-launcher:%v</name>
49+
50+
<build>
51+
<contextDir>${project.basedir}/src/main/docker</contextDir>
52+
</build>
53+
54+
<run>
55+
<!--
56+
A sanitized version of the image’s short name from which this container is created.
57+
As this Maven plugin does not currently remove Docker containers when Maven build is interrupted,
58+
a unique name should prevent running multiple concurrent builds.
59+
-->
60+
<containerNamePattern>%n</containerNamePattern>
61+
<wait>
62+
<exit>0</exit>
63+
<time>${testkit.timeout}</time>
64+
</wait>
65+
<env>
66+
<TESTKIT_CHECKOUT_PATH>${project.build.directory}/testkit</TESTKIT_CHECKOUT_PATH>
67+
<TESTKIT_VERSION>${testkit.version}</TESTKIT_VERSION>
68+
<TESTKIT_ARGS>${testkit.args}</TESTKIT_ARGS>
69+
<TEST_DRIVER_NAME>java</TEST_DRIVER_NAME>
70+
<TEST_DRIVER_REPO>${rootDir}</TEST_DRIVER_REPO>
71+
<TEST_SKIP_BUILD>true</TEST_SKIP_BUILD>
72+
</env>
73+
<volumes>
74+
<bind>
75+
<!--
76+
Testkit requires access to Docker to launch other containers.
77+
This is achieved by passing through the host's Docker socket.
78+
-->
79+
<volume>/var/run/docker.sock:/var/run/docker.sock</volume>
80+
<!--
81+
Testkit launches other containers and shares sources with them via volumes.
82+
Given that Testkit runs in the container and uses the host's Docker instance,
83+
the filesystem paths it uses must exist on the host system.
84+
This is achieved by using the same path as on the host system.
85+
-->
86+
<volume>${rootDir}:${rootDir}</volume>
87+
</bind>
88+
</volumes>
89+
</run>
90+
</image>
91+
</images>
92+
</configuration>
93+
94+
<executions>
95+
<execution>
96+
<id>build-testkit-launcher</id>
97+
<phase>pre-integration-test</phase>
98+
<goals>
99+
<goal>build</goal>
100+
</goals>
101+
</execution>
102+
<execution>
103+
<id>run-testkit</id>
104+
<phase>integration-test</phase>
105+
<goals>
106+
<!-- Testkit is expected to exit automatically. -->
107+
<goal>start</goal>
108+
</goals>
109+
</execution>
110+
</executions>
111+
</plugin>
112+
</plugins>
113+
</pluginManagement>
114+
</build>
115+
116+
<profiles>
117+
<!-- Skips running Testkit when tests are skipped. -->
118+
<profile>
119+
<id>skip-testkit</id>
120+
<activation>
121+
<property>
122+
<name>skipTests</name>
123+
</property>
124+
</activation>
125+
<properties>
126+
<docker.skip>true</docker.skip>
127+
</properties>
128+
</profile>
129+
<!-- Skips running Testkit in TeamCity as it is launched separately. -->
130+
<profile>
131+
<id>skip-testkit-teamcity</id>
132+
<activation>
133+
<property>
134+
<name>env.TEAMCITY_VERSION</name>
135+
</property>
136+
</activation>
137+
<properties>
138+
<docker.skip>true</docker.skip>
139+
</properties>
140+
</profile>
141+
<!-- Enables running Testkit when other tests are skipped. -->
142+
<profile>
143+
<id>testkit-tests</id>
144+
<properties>
145+
<docker.skip>false</docker.skip>
146+
</properties>
147+
</profile>
148+
<!-- Enables passing custom arguments to Testkit and also enables running Testkit when other tests are skipped. -->
149+
<profile>
150+
<id>testkit-custom-args</id>
151+
<activation>
152+
<property>
153+
<name>testkitArgs</name>
154+
</property>
155+
</activation>
156+
<properties>
157+
<docker.skip>false</docker.skip>
158+
<testkit.args>${testkitArgs}</testkit.args>
159+
</properties>
160+
</profile>
161+
<!-- Enables docker maven plugin verbose output. For instance, this can be useful for checking build logs. -->
162+
<profile>
163+
<id>testkit-docker-verbose</id>
164+
<properties>
165+
<docker.verbose>true</docker.verbose>
166+
</properties>
167+
</profile>
168+
</profiles>
169+
</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 https://github.com/neo4j-drivers/testkit.git $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)