Skip to content
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

Migrate server tests to JUnit5 #593

Merged
merged 1 commit into from
Jan 8, 2025
Merged

Migrate server tests to JUnit5 #593

merged 1 commit into from
Jan 8, 2025

Conversation

ekharkunov
Copy link
Contributor

@ekharkunov ekharkunov commented Jan 7, 2025

  • Migrated test classes to JUnit5.
  • Made changes to docker compose to eliminate collision between AuthentificationTest and IntegrationTest. Now two sets of docker containers can be run in parallel.
  • Avoid shared resources between test cases (shared folders, etc.)

For local execution

./gradlew :server:test --info

on my Mac (Apple M3 Pro, 36 GB)
took

Single thread Parallel Diff
56m 12s 16m 6s -71.35%

Fixes #565

@@ -471,13 +453,13 @@ static void writeYaml(File file, Map<String, Object> map) throws IOException
{
Yaml yaml = new Yaml();
String text = yaml.dump(map);
FileUtils.writeStringToFile(file, text);
FileUtils.writeStringToFile(file, text, Charset.defaultCharset(), false);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix deprecation warning.

ports:
- "9000:9000"
- "9001:9001"
Copy link
Contributor Author

@ekharkunov ekharkunov Jan 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use 9001 port for authentication testing to avoid port collision during parallel test run.

# redefine helathcheck because of another port
# see the same configuration in common-services.yml
healthcheck:
test: wget --no-verbose --tries=1 --spider http://localhost:9001/actuator/health
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redefine healthcheck because port was changed.

@@ -15,6 +14,9 @@ if [ "$APPLICATION" == "" ]; then
APPLICATION="extender-test"
fi

if [ "$PORT" == "" ]; then
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read port from external variable

@@ -48,12 +50,23 @@ check_containers_health() {
all_healthy=true

for container in $(docker ps -q); do
health_field=$(docker inspect --format='{{.State.Health}}' "$container")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If during test some other containers are running - check if health status is not defined - skip container information.

name=$(docker inspect --format='{{.Name}}' "$container" | sed 's/\///')
app_name=$(docker inspect "$container" | jq -r '.[0].Config.Labels["com.docker.compose.project"]')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extract application name from Labels for further container filtering.

health_status=$(docker inspect --format='{{.State.Health.Status}}' "$container")

if [ "$app_name" != "$APPLICATION" ]; then
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When two tests suites run simultaneously (auth and integration tests) - filter containers by application name to avoid check of unrelated containers.

@@ -0,0 +1,2 @@
junit.jupiter.execution.parallel.enabled = true
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Configuration to enable parallel test execution.

private static final int EXTENDER_PORT = 9000;

private TestConfiguration configuration;
private long startTime;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need calculate execution time because JUnit measures time itself.

public static void afterClass() throws IOException, InterruptedException {
ProcessExecutor processExecutor = new ProcessExecutor();
processExecutor.putEnv("APPLICATION", "extender-test");
processExecutor.execute("scripts/stop-test-server.sh");
System.out.println(processExecutor.getOutput());
}

@Before
public void beforeTest() throws IOException {
File cachedBuild = new File(String.format("build/%s/build.zip", configuration.platform));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create temporary directory for extender's cache when doBuild is called.

@ekharkunov ekharkunov requested review from JCash and britzl January 7, 2025 21:18
@ekharkunov ekharkunov marked this pull request as ready for review January 7, 2025 21:18
@ekharkunov ekharkunov merged commit 8742e37 into dev Jan 8, 2025
@ekharkunov ekharkunov deleted the server-junit5 branch January 8, 2025 08:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move tests to JUnit 5 and enable concurency
2 participants