|
18 | 18 | import org.elasticsearch.gradle.Version; |
19 | 19 | import org.elasticsearch.gradle.VersionProperties; |
20 | 20 | import org.elasticsearch.gradle.distribution.ElasticsearchDistributionTypes; |
| 21 | +import org.elasticsearch.gradle.internal.BwcVersions; |
21 | 22 | import org.elasticsearch.gradle.internal.ElasticsearchJavaBasePlugin; |
22 | 23 | import org.elasticsearch.gradle.internal.InternalDistributionDownloadPlugin; |
23 | 24 | import org.elasticsearch.gradle.internal.test.ClusterFeaturesMetadataPlugin; |
|
44 | 45 | import org.gradle.api.file.FileCollection; |
45 | 46 | import org.gradle.api.file.FileTree; |
46 | 47 | import org.gradle.api.internal.artifacts.dependencies.ProjectDependencyInternal; |
| 48 | +import org.gradle.api.plugins.JavaBasePlugin; |
| 49 | +import org.gradle.api.plugins.JvmTestSuitePlugin; |
| 50 | +import org.gradle.api.plugins.jvm.JvmTestSuiteTarget; |
47 | 51 | import org.gradle.api.provider.ProviderFactory; |
48 | 52 | import org.gradle.api.tasks.ClasspathNormalizer; |
49 | 53 | import org.gradle.api.tasks.PathSensitivity; |
| 54 | +import org.gradle.api.tasks.testing.Test; |
50 | 55 | import org.gradle.api.tasks.util.PatternFilterable; |
| 56 | +import org.gradle.testing.base.TestingExtension; |
51 | 57 |
|
52 | 58 | import java.util.Collection; |
53 | 59 | import java.util.Iterator; |
@@ -94,6 +100,8 @@ public RestTestBasePlugin(ProviderFactory providerFactory) { |
94 | 100 | public void apply(Project project) { |
95 | 101 | project.getPluginManager().apply(ElasticsearchJavaBasePlugin.class); |
96 | 102 | project.getPluginManager().apply(InternalDistributionDownloadPlugin.class); |
| 103 | + project.getPluginManager().apply(JvmTestSuitePlugin.class); |
| 104 | + |
97 | 105 | var bwcVersions = loadBuildParams(project).get().getBwcVersions(); |
98 | 106 |
|
99 | 107 | // Register integ-test and default distributions |
@@ -153,104 +161,154 @@ public void apply(Project project) { |
153 | 161 |
|
154 | 162 | }); |
155 | 163 |
|
156 | | - project.getTasks().withType(StandaloneRestIntegTestTask.class).configureEach(task -> { |
157 | | - SystemPropertyCommandLineArgumentProvider nonInputSystemProperties = task.getExtensions() |
158 | | - .getByType(SystemPropertyCommandLineArgumentProvider.class); |
159 | | - |
160 | | - task.dependsOn(integTestDistro, modulesConfiguration); |
161 | | - registerDistributionInputs(task, integTestDistro); |
162 | | - |
163 | | - // Pass feature metadata on to tests |
164 | | - task.getInputs().files(featureMetadataConfig).withPathSensitivity(PathSensitivity.NONE); |
165 | | - nonInputSystemProperties.systemProperty(TESTS_FEATURES_METADATA_PATH, () -> featureMetadataConfig.getAsPath()); |
166 | | - |
167 | | - // Enable parallel execution for these tests since each test gets its own cluster |
168 | | - task.setMaxParallelForks(task.getProject().getGradle().getStartParameter().getMaxWorkerCount() / 2); |
169 | | - nonInputSystemProperties.systemProperty(TESTS_MAX_PARALLEL_FORKS_SYSPROP, () -> String.valueOf(task.getMaxParallelForks())); |
170 | | - |
171 | | - // Disable test failure reporting since this stuff is now captured in build scans |
172 | | - task.getExtensions().getByType(ErrorReportingTestListener.class).setDumpOutputOnFailure(false); |
173 | | - |
174 | | - // Disable the security manager and syscall filter since the test framework needs to fork processes |
175 | | - task.systemProperty("tests.security.manager", "false"); |
176 | | - task.systemProperty("tests.system_call_filter", "false"); |
| 164 | + TestingExtension testing = project.getExtensions().getByType(TestingExtension.class); |
| 165 | + testing.getSuites() |
| 166 | + .withType(RestTestSuite.class) |
| 167 | + .configureEach( |
| 168 | + restTestSuite -> restTestSuite.getTargets() |
| 169 | + .configureEach((Action<JvmTestSuiteTarget>) jvmTestSuiteTarget -> jvmTestSuiteTarget.getTestTask().configure(test -> { |
| 170 | + configureRegisteredRestTask( |
| 171 | + project, |
| 172 | + test, |
| 173 | + integTestDistro, |
| 174 | + modulesConfiguration, |
| 175 | + featureMetadataConfig, |
| 176 | + bwcVersions, |
| 177 | + pluginsConfiguration, |
| 178 | + extractedPluginsConfiguration, |
| 179 | + defaultDistro, |
| 180 | + defaultDistroFeatureMetadataConfig |
| 181 | + ); |
| 182 | + test.setGroup(JavaBasePlugin.VERIFICATION_GROUP); |
| 183 | + test.setDescription("Runs the REST tests against an external cluster"); |
177 | 184 |
|
178 | | - // Pass minimum wire compatible version which is used by upgrade tests |
179 | | - task.systemProperty(MINIMUM_WIRE_COMPATIBLE_VERSION_SYSPROP, bwcVersions.getMinimumWireCompatibleVersion()); |
| 185 | + })) |
| 186 | + ); |
180 | 187 |
|
181 | | - // Register plugins and modules as task inputs and pass paths as system properties to tests |
182 | | - var modulePath = project.getObjects().fileCollection().from(modulesConfiguration); |
183 | | - nonInputSystemProperties.systemProperty(TESTS_CLUSTER_MODULES_PATH_SYSPROP, modulePath::getAsPath); |
184 | | - registerConfigurationInputs(task, modulesConfiguration.getName(), modulePath); |
185 | | - var pluginPath = project.getObjects().fileCollection().from(pluginsConfiguration); |
186 | | - nonInputSystemProperties.systemProperty(TESTS_CLUSTER_PLUGINS_PATH_SYSPROP, pluginPath::getAsPath); |
187 | | - registerConfigurationInputs( |
| 188 | + project.getTasks().withType(StandaloneRestIntegTestTask.class).configureEach(task -> { |
| 189 | + configureRegisteredRestTask( |
| 190 | + project, |
188 | 191 | task, |
189 | | - extractedPluginsConfiguration.getName(), |
190 | | - project.getObjects().fileCollection().from(extractedPluginsConfiguration) |
| 192 | + integTestDistro, |
| 193 | + modulesConfiguration, |
| 194 | + featureMetadataConfig, |
| 195 | + bwcVersions, |
| 196 | + pluginsConfiguration, |
| 197 | + extractedPluginsConfiguration, |
| 198 | + defaultDistro, |
| 199 | + defaultDistroFeatureMetadataConfig |
191 | 200 | ); |
| 201 | + }); |
| 202 | + } |
192 | 203 |
|
193 | | - // Wire up integ-test distribution by default for all test tasks |
194 | | - FileCollection extracted = integTestDistro.getExtracted(); |
195 | | - nonInputSystemProperties.systemProperty(INTEG_TEST_DISTRIBUTION_SYSPROP, () -> extracted.getSingleFile().getPath()); |
196 | | - |
197 | | - // Add `usesDefaultDistribution()` extension method to test tasks to indicate they require the default distro |
198 | | - task.getExtensions().getExtraProperties().set("usesDefaultDistribution", new Closure<Void>(task) { |
199 | | - @Override |
200 | | - public Void call(Object... args) { |
201 | | - if (reasonForUsageProvided(args) == false) { |
202 | | - throw new IllegalArgumentException( |
203 | | - "Reason for using `usesDefaultDistribution` required.\nUse usesDefaultDistribution(\"reason why default distro is required here\")." |
204 | | - ); |
205 | | - } |
206 | | - task.dependsOn(defaultDistro); |
207 | | - registerDistributionInputs(task, defaultDistro); |
| 204 | + private void configureRegisteredRestTask( |
| 205 | + Project project, |
| 206 | + Test task, |
| 207 | + ElasticsearchDistribution integTestDistro, |
| 208 | + Configuration modulesConfiguration, |
| 209 | + FileCollection featureMetadataConfig, |
| 210 | + BwcVersions bwcVersions, |
| 211 | + Configuration pluginsConfiguration, |
| 212 | + Configuration extractedPluginsConfiguration, |
| 213 | + ElasticsearchDistribution defaultDistro, |
| 214 | + FileCollection defaultDistroFeatureMetadataConfig |
| 215 | + ) { |
| 216 | + SystemPropertyCommandLineArgumentProvider nonInputSystemProperties = task.getExtensions() |
| 217 | + .getByType(SystemPropertyCommandLineArgumentProvider.class); |
| 218 | + |
| 219 | + task.dependsOn(integTestDistro, modulesConfiguration); |
| 220 | + registerDistributionInputs(task, integTestDistro); |
| 221 | + |
| 222 | + // Pass feature metadata on to tests |
| 223 | + task.getInputs().files(featureMetadataConfig).withPathSensitivity(PathSensitivity.NONE); |
| 224 | + nonInputSystemProperties.systemProperty(TESTS_FEATURES_METADATA_PATH, () -> featureMetadataConfig.getAsPath()); |
| 225 | + |
| 226 | + // Enable parallel execution for these tests since each test gets its own cluster |
| 227 | + task.setMaxParallelForks(task.getProject().getGradle().getStartParameter().getMaxWorkerCount() / 2); |
| 228 | + nonInputSystemProperties.systemProperty(TESTS_MAX_PARALLEL_FORKS_SYSPROP, () -> String.valueOf(task.getMaxParallelForks())); |
| 229 | + |
| 230 | + // Disable test failure reporting since this stuff is now captured in build scans |
| 231 | + task.getExtensions().getByType(ErrorReportingTestListener.class).setDumpOutputOnFailure(false); |
| 232 | + |
| 233 | + // Disable the security manager and syscall filter since the test framework needs to fork processes |
| 234 | + task.systemProperty("tests.security.manager", "false"); |
| 235 | + task.systemProperty("tests.system_call_filter", "false"); |
| 236 | + |
| 237 | + // Pass minimum wire compatible version which is used by upgrade tests |
| 238 | + task.systemProperty(MINIMUM_WIRE_COMPATIBLE_VERSION_SYSPROP, bwcVersions.getMinimumWireCompatibleVersion()); |
| 239 | + |
| 240 | + // Register plugins and modules as task inputs and pass paths as system properties to tests |
| 241 | + var modulePath = project.getObjects().fileCollection().from(modulesConfiguration); |
| 242 | + nonInputSystemProperties.systemProperty(TESTS_CLUSTER_MODULES_PATH_SYSPROP, modulePath::getAsPath); |
| 243 | + registerConfigurationInputs(task, modulesConfiguration.getName(), modulePath); |
| 244 | + var pluginPath = project.getObjects().fileCollection().from(pluginsConfiguration); |
| 245 | + nonInputSystemProperties.systemProperty(TESTS_CLUSTER_PLUGINS_PATH_SYSPROP, pluginPath::getAsPath); |
| 246 | + registerConfigurationInputs( |
| 247 | + task, |
| 248 | + extractedPluginsConfiguration.getName(), |
| 249 | + project.getObjects().fileCollection().from(extractedPluginsConfiguration) |
| 250 | + ); |
208 | 251 |
|
209 | | - nonInputSystemProperties.systemProperty( |
210 | | - DEFAULT_DISTRIBUTION_SYSPROP, |
211 | | - providerFactory.provider(() -> defaultDistro.getExtracted().getSingleFile().getPath()) |
| 252 | + // Wire up integ-test distribution by default for all test tasks |
| 253 | + FileCollection extracted = integTestDistro.getExtracted(); |
| 254 | + nonInputSystemProperties.systemProperty(INTEG_TEST_DISTRIBUTION_SYSPROP, () -> extracted.getSingleFile().getPath()); |
| 255 | + |
| 256 | + // Add `usesDefaultDistribution()` extension method to test tasks to indicate they require the default distro |
| 257 | + task.getExtensions().getExtraProperties().set("usesDefaultDistribution", new Closure<Void>(task) { |
| 258 | + @Override |
| 259 | + public Void call(Object... args) { |
| 260 | + if (reasonForUsageProvided(args) == false) { |
| 261 | + throw new IllegalArgumentException( |
| 262 | + "Reason for using `usesDefaultDistribution` required.\nUse usesDefaultDistribution(\"reason why default distro is required here\")." |
212 | 263 | ); |
| 264 | + } |
| 265 | + task.dependsOn(defaultDistro); |
| 266 | + registerDistributionInputs(task, defaultDistro); |
213 | 267 |
|
214 | | - // If we are using the default distribution we need to register all module feature metadata |
215 | | - task.getInputs().files(defaultDistroFeatureMetadataConfig).withPathSensitivity(PathSensitivity.NONE); |
216 | | - nonInputSystemProperties.systemProperty(TESTS_FEATURES_METADATA_PATH, defaultDistroFeatureMetadataConfig::getAsPath); |
| 268 | + nonInputSystemProperties.systemProperty( |
| 269 | + DEFAULT_DISTRIBUTION_SYSPROP, |
| 270 | + providerFactory.provider(() -> defaultDistro.getExtracted().getSingleFile().getPath()) |
| 271 | + ); |
217 | 272 |
|
218 | | - return null; |
219 | | - } |
| 273 | + // If we are using the default distribution we need to register all module feature metadata |
| 274 | + task.getInputs().files(defaultDistroFeatureMetadataConfig).withPathSensitivity(PathSensitivity.NONE); |
| 275 | + nonInputSystemProperties.systemProperty(TESTS_FEATURES_METADATA_PATH, defaultDistroFeatureMetadataConfig::getAsPath); |
220 | 276 |
|
221 | | - private static boolean reasonForUsageProvided(Object[] args) { |
222 | | - return args.length == 1 && args[0] instanceof String && ((String) args[0]).isBlank() == false; |
223 | | - } |
224 | | - }); |
| 277 | + return null; |
| 278 | + } |
225 | 279 |
|
226 | | - // Add `usesBwcDistribution(version)` extension method to test tasks to indicate they require a BWC distribution |
227 | | - task.getExtensions().getExtraProperties().set("usesBwcDistribution", new Closure<Void>(task) { |
228 | | - @Override |
229 | | - public Void call(Object... args) { |
230 | | - if (args.length != 1 || args[0] instanceof Version == false) { |
231 | | - throw new IllegalArgumentException("Expected exactly one argument of type org.elasticsearch.gradle.Version"); |
232 | | - } |
| 280 | + private static boolean reasonForUsageProvided(Object[] args) { |
| 281 | + return args.length == 1 && args[0] instanceof String && ((String) args[0]).isBlank() == false; |
| 282 | + } |
| 283 | + }); |
233 | 284 |
|
234 | | - Version version = (Version) args[0]; |
235 | | - boolean isReleased = bwcVersions.unreleasedInfo(version) == null && version.toString().equals("0.0.0") == false; |
236 | | - String versionString = version.toString(); |
237 | | - ElasticsearchDistribution bwcDistro = createDistribution(project, "bwc_" + versionString, versionString); |
| 285 | + // Add `usesBwcDistribution(version)` extension method to test tasks to indicate they require a BWC distribution |
| 286 | + task.getExtensions().getExtraProperties().set("usesBwcDistribution", new Closure<Void>(task) { |
| 287 | + @Override |
| 288 | + public Void call(Object... args) { |
| 289 | + if (args.length != 1 || args[0] instanceof Version == false) { |
| 290 | + throw new IllegalArgumentException("Expected exactly one argument of type org.elasticsearch.gradle.Version"); |
| 291 | + } |
238 | 292 |
|
239 | | - task.dependsOn(bwcDistro); |
240 | | - registerDistributionInputs(task, bwcDistro); |
| 293 | + Version version = (Version) args[0]; |
| 294 | + boolean isReleased = bwcVersions.unreleasedInfo(version) == null && version.toString().equals("0.0.0") == false; |
| 295 | + String versionString = version.toString(); |
| 296 | + ElasticsearchDistribution bwcDistro = createDistribution(project, "bwc_" + versionString, versionString); |
241 | 297 |
|
242 | | - nonInputSystemProperties.systemProperty( |
243 | | - (isReleased ? BWC_RELEASED_DISTRIBUTION_SYSPROP_PREFIX : BWC_SNAPSHOT_DISTRIBUTION_SYSPROP_PREFIX) + versionString, |
244 | | - providerFactory.provider(() -> bwcDistro.getExtracted().getSingleFile().getPath()) |
245 | | - ); |
| 298 | + task.dependsOn(bwcDistro); |
| 299 | + registerDistributionInputs(task, bwcDistro); |
246 | 300 |
|
247 | | - if (version.getMajor() > 0 && version.before(bwcVersions.getMinimumWireCompatibleVersion())) { |
248 | | - // If we are upgrade testing older versions we also need to upgrade to 7.last |
249 | | - this.call(bwcVersions.getMinimumWireCompatibleVersion()); |
250 | | - } |
251 | | - return null; |
| 301 | + nonInputSystemProperties.systemProperty( |
| 302 | + (isReleased ? BWC_RELEASED_DISTRIBUTION_SYSPROP_PREFIX : BWC_SNAPSHOT_DISTRIBUTION_SYSPROP_PREFIX) + versionString, |
| 303 | + providerFactory.provider(() -> bwcDistro.getExtracted().getSingleFile().getPath()) |
| 304 | + ); |
| 305 | + |
| 306 | + if (version.getMajor() > 0 && version.before(bwcVersions.getMinimumWireCompatibleVersion())) { |
| 307 | + // If we are upgrade testing older versions we also need to upgrade to 7.last |
| 308 | + this.call(bwcVersions.getMinimumWireCompatibleVersion()); |
252 | 309 | } |
253 | | - }); |
| 310 | + return null; |
| 311 | + } |
254 | 312 | }); |
255 | 313 | } |
256 | 314 |
|
|
0 commit comments