Browse Source

Allow dockerTest tasks to be run in parallel through configuration

Closes gh-44913
pull/44942/head
Andy Wilkinson 9 months ago
parent
commit
86d11c90e2
  1. 19
      buildSrc/src/main/java/org/springframework/boot/build/test/DockerTestBuildService.java

19
buildSrc/src/main/java/org/springframework/boot/build/test/DockerTestBuildService.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2024 the original author or authors. * Copyright 2012-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -22,8 +22,10 @@ import org.gradle.api.services.BuildService;
import org.gradle.api.services.BuildServiceParameters; import org.gradle.api.services.BuildServiceParameters;
/** /**
* Build service for Docker-based tests. Configured to only allow serial execution, * Build service for Docker-based tests. The maximum number of {@code dockerTest} tasks
* thereby ensuring that Docker-based tests do not run in parallel. * that can run in parallel can be configured using
* {@code org.springframework.boot.dockertest.max-parallel-tasks}. By default, only a
* single {@code dockerTest} task will run at a time.
* *
* @author Andy Wilkinson * @author Andy Wilkinson
*/ */
@ -32,7 +34,16 @@ abstract class DockerTestBuildService implements BuildService<BuildServiceParame
static Provider<DockerTestBuildService> registerIfNecessary(Project project) { static Provider<DockerTestBuildService> registerIfNecessary(Project project) {
return project.getGradle() return project.getGradle()
.getSharedServices() .getSharedServices()
.registerIfAbsent("dockerTest", DockerTestBuildService.class, (spec) -> spec.getMaxParallelUsages().set(1)); .registerIfAbsent("dockerTest", DockerTestBuildService.class,
(spec) -> spec.getMaxParallelUsages().set(maxParallelTasks(project)));
}
private static int maxParallelTasks(Project project) {
Object property = project.findProperty("org.springframework.boot.dockertest.max-parallel-tasks");
if (property == null) {
return 1;
}
return Integer.parseInt(property.toString());
} }
} }

Loading…
Cancel
Save