Skip to content

Run gradle integration tests with configuration cache enabled by default #88148

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

Merged
merged 5 commits into from
Jun 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,20 @@ class LocalRepositoryFixture extends ExternalResource{

private TemporaryFolder temporaryFolder

LocalRepositoryFixture(TemporaryFolder temporaryFolder){
this.temporaryFolder = temporaryFolder
LocalRepositoryFixture(){
this.temporaryFolder = new TemporaryFolder()
}

@Override
protected void before() throws Throwable {
super.before()
temporaryFolder.before()
}

@Override
protected void after() {
super.after()
temporaryFolder.after()
}

void generateJar(String group, String module, String version, String... clazzNames){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ package org.elasticsearch.gradle.internal

import org.apache.commons.io.IOUtils
import org.elasticsearch.gradle.fixtures.AbstractGradleFuncTest
import org.elasticsearch.gradle.fixtures.LocalRepositoryFixture
import org.gradle.testkit.runner.TaskOutcome
import org.junit.ClassRule
import org.junit.rules.TemporaryFolder
import spock.lang.Shared

import java.nio.charset.StandardCharsets
import java.util.zip.ZipEntry
Expand All @@ -20,6 +24,10 @@ import static org.elasticsearch.gradle.fixtures.TestClasspathUtils.setupJarHellJ

class BuildPluginFuncTest extends AbstractGradleFuncTest {

@Shared
@ClassRule
public LocalRepositoryFixture repository = new LocalRepositoryFixture()

def EXAMPLE_LICENSE = """\
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -120,6 +128,8 @@ class BuildPluginFuncTest extends AbstractGradleFuncTest {

def "applies checks"() {
given:
repository.generateJar("org.elasticsearch", "build-conventions", "unspecified", 'org.acme.CheckstyleStuff')
repository.configureBuild(buildFile)
setupJarHellJar(dir('local-repo/org/elasticsearch/elasticsearch-core/current/'))
file("licenses/hamcrest-core-1.3.jar.sha1").text = "42a25dc3219429f0e5d060061f71acb49bf010a0"
file("licenses/hamcrest-core-LICENSE.txt").text = EXAMPLE_LICENSE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,22 @@

package org.elasticsearch.gradle.internal

import org.elasticsearch.gradle.fixtures.AbstractGradleFuncTest
import org.elasticsearch.gradle.fixtures.AbstractGradleInternalPluginFuncTest
import org.gradle.api.Plugin

class ElasticsearchJavaPluginFuncTest extends AbstractGradleFuncTest {
class ElasticsearchJavaPluginFuncTest extends AbstractGradleInternalPluginFuncTest {

Class<? extends Plugin> pluginClassUnderTest = ElasticsearchJavaPlugin.class

def "compatibility options are resolved from from build params minimum runtime version"() {
when:
buildFile.text = """
plugins {
id 'elasticsearch.global-build-info'
}
buildFile.text << """
import org.elasticsearch.gradle.Architecture
import org.elasticsearch.gradle.internal.info.BuildParams
BuildParams.init { it.setMinimumRuntimeVersion(JavaVersion.VERSION_1_10) }

apply plugin:'elasticsearch.java'

assert compileJava.sourceCompatibility == JavaVersion.VERSION_1_10.toString()
assert compileJava.targetCompatibility == JavaVersion.VERSION_1_10.toString()
assert tasks.named('compileJava').get().sourceCompatibility == JavaVersion.VERSION_1_10.toString()
assert tasks.named('compileJava').get().targetCompatibility == JavaVersion.VERSION_1_10.toString()
"""

then:
Expand All @@ -34,14 +32,10 @@ class ElasticsearchJavaPluginFuncTest extends AbstractGradleFuncTest {

def "compile option --release is configured from targetCompatibility"() {
when:
buildFile.text = """
plugins {
id 'elasticsearch.java'
}

compileJava.targetCompatibility = "1.10"
buildFile.text << """
tasks.named('compileJava').get().targetCompatibility = "1.10"
afterEvaluate {
assert compileJava.options.release.get() == 10
assert tasks.named('compileJava').get().options.release.get() == 10
}
"""
then:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import org.gradle.testkit.runner.TaskOutcome
class InternalBwcGitPluginFuncTest extends AbstractGitAwareGradleFuncTest {

def setup() {
// using LoggedExec is not cc compatible
configurationCacheCompatible = false
internalBuild()
buildFile << """
import org.elasticsearch.gradle.Version;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import spock.lang.Unroll
class InternalDistributionBwcSetupPluginFuncTest extends AbstractGitAwareGradleFuncTest {

def setup() {
// used LoggedExec task is not configuration cache compatible and
configurationCacheCompatible = false
internalBuild()
buildFile << """
apply plugin: 'elasticsearch.internal-distribution-bwc-setup'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ class JdkDownloadPluginFuncTest extends AbstractGradleFuncTest {
plugins {
id 'elasticsearch.jdk-download'
}
import org.elasticsearch.gradle.internal.Jdk
apply plugin: 'base'
apply plugin: 'elasticsearch.jdk-download'

Expand All @@ -158,11 +159,18 @@ class JdkDownloadPluginFuncTest extends AbstractGradleFuncTest {
architecture = "x64"
}
}

tasks.register("getJdk") {
tasks.register("getJdk", PrintJdk) {
dependsOn jdks.myJdk
doLast {
println "JDK HOME: " + jdks.myJdk
jdkPath = jdks.myJdk.getPath()
}

class PrintJdk extends DefaultTask {
@Input
String jdkPath

@TaskAction void print() {
println "JDK HOME: " + jdkPath
}
}
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest {

def "generates artifacts for shadowed elasticsearch plugin"() {
given:
// we use the esplugin plugin in this test that is not configuration cache compatible yet
configurationCacheCompatible = false
file('license.txt') << "License file"
file('notice.txt') << "Notice file"
buildFile << """
Expand Down Expand Up @@ -334,6 +336,8 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest {

def "generates pom for elasticsearch plugin"() {
given:
// we use the esplugin plugin in this test that is not configuration cache compatible yet
configurationCacheCompatible = false
file('license.txt') << "License file"
file('notice.txt') << "Notice file"
buildFile << """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class ElasticsearchDistributionPluginFuncTest extends AbstractGradleFuncTest {

def "copied modules are resolved from explodedBundleZip"() {
given:
// we use the esplugin plugin in this test that is not configuration cache compatible yet
configurationCacheCompatible = false
moduleSubProject()

buildFile << """plugins {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class LicenseHeadersPrecommitPluginFuncTest extends AbstractGradleInternalPlugin
Class<? extends PrecommitPlugin> pluginClassUnderTest = LicenseHeadersPrecommitPlugin.class

def setup() {
configurationCacheCompatible = true
buildFile << """
apply plugin:'java'
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,9 @@ class TestingConventionsPrecommitPluginFuncTest extends AbstractGradleInternalPl

Class<? extends PrecommitPlugin> pluginClassUnderTest = TestingConventionsPrecommitPlugin.class

@ClassRule
@Shared
public TemporaryFolder repoFolder = new TemporaryFolder()

@Shared
@ClassRule
public LocalRepositoryFixture repository = new LocalRepositoryFixture(repoFolder)
public LocalRepositoryFixture repository = new LocalRepositoryFixture()

def setupSpec() {
repository.generateJar('org.apache.lucene', 'tests.util', "1.0",
Expand All @@ -45,7 +41,6 @@ class TestingConventionsPrecommitPluginFuncTest extends AbstractGradleInternalPl
}

def setup() {
configurationCacheCompatible = true
repository.configureBuild(buildFile)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,24 @@ import net.bytebuddy.dynamic.DynamicType
import net.bytebuddy.implementation.FixedValue
import org.apache.logging.log4j.LogManager
import org.elasticsearch.gradle.fixtures.AbstractGradleFuncTest
import org.elasticsearch.gradle.fixtures.AbstractGradleInternalPluginFuncTest
import org.elasticsearch.gradle.internal.conventions.precommit.LicenseHeadersPrecommitPlugin
import org.elasticsearch.gradle.internal.conventions.precommit.PrecommitPlugin
import org.gradle.testkit.runner.TaskOutcome


import static org.elasticsearch.gradle.fixtures.TestClasspathUtils.setupJarJdkClasspath

class ThirdPartyAuditTaskFuncTest extends AbstractGradleFuncTest {
class ThirdPartyAuditTaskFuncTest extends AbstractGradleInternalPluginFuncTest {

Class<? extends PrecommitPlugin> pluginClassUnderTest = ThirdPartyAuditPrecommitPlugin.class

def setup() {
buildFile << """
import org.elasticsearch.gradle.internal.precommit.ThirdPartyAuditPrecommitPlugin
import org.elasticsearch.gradle.internal.precommit.ThirdPartyAuditTask

plugins {
id 'java'
// bring in build-tools onto the classpath
id 'elasticsearch.global-build-info'
}

plugins.apply(ThirdPartyAuditPrecommitPlugin)
apply plugin:'java'

group = 'org.elasticsearch'
version = 'current'
Expand All @@ -48,7 +47,7 @@ class ThirdPartyAuditTaskFuncTest extends AbstractGradleFuncTest {
mavenCentral()
}

tasks.register("thirdPartyCheck", ThirdPartyAuditTask) {
tasks.named("thirdPartyAudit").configure {
signatureFile = file('signature-file.txt')
}
"""
Expand All @@ -58,6 +57,7 @@ class ThirdPartyAuditTaskFuncTest extends AbstractGradleFuncTest {
given:
def group = "org.elasticsearch.gradle"
generateDummyJars(group)
setupJarJdkClasspath(dir('local-repo/org/elasticsearch/elasticsearch-core/current/'))
file('signature-file.txt') << "@defaultMessage non-public internal runtime class"

buildFile << """
Expand All @@ -68,9 +68,9 @@ class ThirdPartyAuditTaskFuncTest extends AbstractGradleFuncTest {
}
"""
when:
def result = gradleRunner("thirdPartyCheck").build()
def result = gradleRunner("thirdPartyAudit").build()
then:
result.task(":thirdPartyCheck").outcome == TaskOutcome.NO_SOURCE
result.task(":thirdPartyAudit").outcome == TaskOutcome.NO_SOURCE
assertNoDeprecationWarning(result)
}

Expand All @@ -91,9 +91,9 @@ class ThirdPartyAuditTaskFuncTest extends AbstractGradleFuncTest {
}
"""
when:
def result = gradleRunner(":thirdPartyCheck").buildAndFail()
def result = gradleRunner(":thirdPartyAudit").buildAndFail()
then:
result.task(":thirdPartyCheck").outcome == TaskOutcome.FAILED
result.task(":thirdPartyAudit").outcome == TaskOutcome.FAILED

def output = normalized(result.getOutput())
assertOutputContains(output, """\
Expand Down Expand Up @@ -127,9 +127,9 @@ class ThirdPartyAuditTaskFuncTest extends AbstractGradleFuncTest {
}
"""
when:
def result = gradleRunner(":thirdPartyCheck").buildAndFail()
def result = gradleRunner(":thirdPartyAudit").buildAndFail()
then:
result.task(":thirdPartyCheck").outcome == TaskOutcome.FAILED
result.task(":thirdPartyAudit").outcome == TaskOutcome.FAILED

def output = normalized(result.getOutput())
assertOutputContains(output, """\
Expand Down Expand Up @@ -163,9 +163,9 @@ class ThirdPartyAuditTaskFuncTest extends AbstractGradleFuncTest {
}
"""
when:
def result = gradleRunner(":thirdPartyCheck").buildAndFail()
def result = gradleRunner(":thirdPartyAudit").buildAndFail()
then:
result.task(":thirdPartyCheck").outcome == TaskOutcome.FAILED
result.task(":thirdPartyAudit").outcome == TaskOutcome.FAILED

def output = normalized(result.getOutput())
assertOutputContains(output, """\
Expand All @@ -174,7 +174,7 @@ class ThirdPartyAuditTaskFuncTest extends AbstractGradleFuncTest {
""".stripIndent())
assertOutputContains(output, """\
* What went wrong:
Execution failed for task ':thirdPartyCheck'.
Execution failed for task ':thirdPartyAudit'.
> Audit of third party dependencies failed:
Jar Hell with the JDK:
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class InternalYamlRestTestPluginFuncTest extends AbstractRestResourcesFuncTest {

def "yamlRestTest does nothing when there are no tests"() {
given:
// RestIntegTestTask not cc compatible due to
configurationCacheCompatible = false
buildFile << """
plugins {
id 'elasticsearch.internal-yaml-rest-test'
Expand All @@ -36,6 +38,8 @@ class InternalYamlRestTestPluginFuncTest extends AbstractRestResourcesFuncTest {

def "yamlRestTest executes and copies api and tests to correct source set"() {
given:
// RestIntegTestTask not cc compatible due to
configurationCacheCompatible = false
internalBuild()
buildFile << """
apply plugin: 'elasticsearch.internal-yaml-rest-test'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class RestResourcesPluginFuncTest extends AbstractRestResourcesFuncTest {
file("/build/restResources/yamlTests/rest-api-spec/test/" + coreTest).getText("UTF-8") == "replacedWithValue"

when:
result = gradleRunner("copyRestApiSpecsTask").build()
result = gradleRunner("copyRestApiSpecsTask", '--stacktrace').build()

then:
result.task(':copyRestApiSpecsTask').outcome == TaskOutcome.UP_TO_DATE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ class YamlRestCompatTestPluginFuncTest extends AbstractRestResourcesFuncTest {
def READER = MAPPER.readerFor(ObjectNode.class)
def WRITER = MAPPER.writerFor(ObjectNode.class)

def setup() {
// not cc compatible due to:
// 1. TestClustersPlugin not cc compatible due to listener registration
// 2. RestIntegTestTask not cc compatible due to
configurationCacheCompatible = false
}
def "yamlRestTestVxCompatTest does nothing when there are no tests"() {
given:
subProject(":distribution:bwc:maintenance") << """
Expand Down
Loading