Skip to content

Commit

Permalink
Use test fixtures instead of sourceSets.test.output
Browse files Browse the repository at this point in the history
This avoids the (often missing) evaluationDependsOn and fixes using
results from other projects without propagating those through
Configuration. It also reduces the number of useless classes pulled in
by down-stream tests, reducing the probability of rebuilds.

The expectation of fixtures is they help testing down-stream code that
use the classes in main. That applies to all the classes here except for
FakeClock and StaticTestingClassLoader. It would also apply to many
internal classes in grpc-testing, but let's consider cleaning that up
future work.
  • Loading branch information
ejona86 authored May 16, 2023
1 parent cd7b81c commit 29b8483
Show file tree
Hide file tree
Showing 31 changed files with 51 additions and 70 deletions.
4 changes: 1 addition & 3 deletions alts/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ plugins {

description = "gRPC: ALTS"

evaluationDependsOn(project(':grpc-core').path)

dependencies {
api project(':grpc-core')
implementation project(':grpc-auth'),
Expand All @@ -28,7 +26,7 @@ dependencies {
shadow project(path: ':grpc-netty-shaded', configuration: 'shadow')

testImplementation project(':grpc-testing'),
project(':grpc-core').sourceSets.test.output,
testFixtures(project(':grpc-core')),
project(':grpc-testing-proto'),
libraries.guava,
libraries.junit,
Expand Down
11 changes: 8 additions & 3 deletions api/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id "java-library"
id "java-test-fixtures"
id "maven-publish"

id "me.champeau.jmh"
Expand All @@ -8,15 +9,16 @@ plugins {

description = 'gRPC: API'

evaluationDependsOn(project(':grpc-context').path)

dependencies {
api project(':grpc-context'),
libraries.jsr305,
libraries.errorprone.annotations
implementation libraries.guava

testImplementation project(':grpc-context').sourceSets.test.output,
testFixturesImplementation libraries.guava,
libraries.junit,
libraries.mockito.core
testImplementation testFixtures(project(':grpc-context')),
project(':grpc-testing'),
project(':grpc-grpclb')
testImplementation (libraries.guava.testlib) {
Expand All @@ -32,3 +34,6 @@ tasks.named("javadoc").configure {
// We want io.grpc.Internal, but not io.grpc.Internal*
exclude 'io/grpc/Internal?*.java'
}

components.java.withVariantsFromConfiguration(configurations.testFixturesApiElements) { skip() }
components.java.withVariantsFromConfiguration(configurations.testFixturesRuntimeElements) { skip() }
2 changes: 1 addition & 1 deletion authz/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ dependencies {

testImplementation project(':grpc-testing'),
project(':grpc-testing-proto'),
project(':grpc-core').sourceSets.test.output // for FakeClock
testFixtures(project(':grpc-core'))
testImplementation (libraries.guava.testlib) {
exclude group: 'junit', module: 'junit'
}
Expand Down
18 changes: 2 additions & 16 deletions binder/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,6 @@ description = 'gRPC BinderChannel'

android {
namespace 'io.grpc.binder'
sourceSets {
test {
java {
srcDirs += "${projectDir}/../core/src/test/java/"
setIncludes(["io/grpc/internal/FakeClock.java",
"io/grpc/binder/**"])
}
}
androidTest {
java {
srcDirs += "${projectDir}/../core/src/test/java/"
setIncludes(["io/grpc/internal/AbstractTransportTest.java",
"io/grpc/binder/**"])
}
}
}
compileSdkVersion 31
compileOptions {
sourceCompatibility 1.8
Expand Down Expand Up @@ -72,6 +56,7 @@ dependencies {
}
testImplementation libraries.truth
testImplementation project(':grpc-testing')
testImplementation testFixtures(project(':grpc-core'))

androidTestAnnotationProcessor libraries.auto.value
androidTestImplementation project(':grpc-testing')
Expand All @@ -88,6 +73,7 @@ dependencies {
androidTestImplementation (libraries.guava.testlib) {
exclude group: 'junit', module: 'junit'
}
androidTestImplementation testFixtures(project(':grpc-core'))
}

import net.ltgt.gradle.errorprone.CheckSeverity
Expand Down
8 changes: 3 additions & 5 deletions census/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,15 @@ plugins {

description = 'gRPC: Census'

evaluationDependsOn(project(':grpc-api').path)

dependencies {
api project(':grpc-api')
implementation libraries.guava,
libraries.opencensus.api,
libraries.opencensus.contrib.grpc.metrics

testImplementation project(':grpc-api').sourceSets.test.output,
project(':grpc-context').sourceSets.test.output,
project(':grpc-core').sourceSets.test.output,
testImplementation testFixtures(project(':grpc-api')),
testFixtures(project(':grpc-context')),
testFixtures(project(':grpc-core')),
project(':grpc-testing'),
libraries.opencensus.impl

Expand Down
8 changes: 8 additions & 0 deletions context/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id "java"
id "java-test-fixtures"
id "maven-publish"

id "me.champeau.gradle.japicmp"
Expand All @@ -13,6 +14,10 @@ sourceCompatibility = 1.7
targetCompatibility = 1.7

dependencies {
testFixturesApi libraries.truth
// Explicitly choose the guava version to stay Java 7-compatible.
testFixturesImplementation 'com.google.guava:guava:30.1.1-android'
testFixturesImplementation libraries.jsr305
testImplementation libraries.jsr305
// Explicitly choose the guava version to stay Java 7-compatible. The rest of gRPC can move
// forward to Java 8-requiring versions. This is also only used for testing, so is unlikely to
Expand All @@ -23,3 +28,6 @@ dependencies {
signature "org.codehaus.mojo.signature:java17:1.0@signature"
signature "net.sf.androidscents.signature:android-api-level-14:4.0_r4@signature"
}

components.java.withVariantsFromConfiguration(configurations.testFixturesApiElements) { skip() }
components.java.withVariantsFromConfiguration(configurations.testFixturesRuntimeElements) { skip() }
16 changes: 11 additions & 5 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ buildscript {

plugins {
id "java-library"
id "java-test-fixtures"
id "maven-publish"

id "me.champeau.gradle.japicmp"
Expand All @@ -19,9 +20,6 @@ import com.google.common.primitives.Bytes;

description = 'gRPC: Core'

evaluationDependsOn(project(':grpc-context').path)
evaluationDependsOn(project(':grpc-api').path)

dependencies {
api project(':grpc-api')
implementation libraries.gson,
Expand All @@ -30,8 +28,13 @@ dependencies {
libraries.errorprone.annotations,
libraries.guava,
libraries.perfmark.api
testImplementation project(':grpc-context').sourceSets.test.output,
project(':grpc-api').sourceSets.test.output,
testFixturesApi libraries.junit
testFixturesImplementation libraries.guava,
libraries.mockito.core,
libraries.truth,
project(':grpc-testing')
testImplementation testFixtures(project(':grpc-context')),
testFixtures(project(':grpc-api')),
project(':grpc-testing'),
project(':grpc-grpclb')
testImplementation (libraries.guava.testlib) {
Expand Down Expand Up @@ -61,6 +64,9 @@ animalsniffer {
]
}

components.java.withVariantsFromConfiguration(configurations.testFixturesApiElements) { skip() }
components.java.withVariantsFromConfiguration(configurations.testFixturesRuntimeElements) { skip() }

import net.ltgt.gradle.errorprone.CheckSeverity

def replaceBytes(byte[] haystack, byte[] needle, byte[] replacement) {
Expand Down
2 changes: 1 addition & 1 deletion gcp-observability/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ dependencies {
('io.opencensus:opencensus-api:0.31.1'),
('com.google.guava:guava:31.1-jre')

testImplementation project(':grpc-context').sourceSets.test.output,
testImplementation testFixtures(project(':grpc-context')),
project(':grpc-testing'),
project(':grpc-testing-proto')
testImplementation (libraries.guava.testlib) {
Expand Down
2 changes: 1 addition & 1 deletion googleapis/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dependencies {
project(':grpc-core'),
project(path: ':grpc-xds', configuration: 'shadow'),
libraries.guava.jre // JRE required by transitive protobuf-java-util
testImplementation project(':grpc-core').sourceSets.test.output
testImplementation testFixtures(project(':grpc-core'))

signature libraries.signature.java
}
4 changes: 1 addition & 3 deletions grpclb/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ plugins {

description = "gRPC: GRPCLB LoadBalancer plugin"

evaluationDependsOn(project(':grpc-core').path)

dependencies {
implementation project(':grpc-core'),
project(':grpc-protobuf'),
Expand All @@ -21,7 +19,7 @@ dependencies {
runtimeOnly libraries.errorprone.annotations
compileOnly libraries.javax.annotation
testImplementation libraries.truth,
project(':grpc-core').sourceSets.test.output
testFixtures(project(':grpc-core'))

signature libraries.signature.java
}
Expand Down
10 changes: 3 additions & 7 deletions interop-testing/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ configurations {
alpnagent
}

evaluationDependsOn(project(':grpc-core').path)
evaluationDependsOn(project(':grpc-context').path)
evaluationDependsOn(project(':grpc-api').path)

dependencies {
implementation project(path: ':grpc-alts', configuration: 'shadow'),
project(':grpc-auth'),
Expand Down Expand Up @@ -49,9 +45,9 @@ dependencies {
libraries.netty.tcnative.classes,
project(':grpc-grpclb'),
project(':grpc-rls')
testImplementation project(':grpc-context').sourceSets.test.output,
project(':grpc-api').sourceSets.test.output,
project(':grpc-core').sourceSets.test.output,
testImplementation testFixtures(project(':grpc-context')),
testFixtures(project(':grpc-api')),
testFixtures(project(':grpc-core')),
libraries.mockito.core,
libraries.okhttp
alpnagent libraries.jetty.alpn.agent
Expand Down
8 changes: 3 additions & 5 deletions istio-interop-testing/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ configurations {
alpnagent
}

evaluationDependsOn(project(':grpc-context').path)

dependencies {
implementation project(':grpc-core'),
project(':grpc-netty'),
Expand All @@ -28,9 +26,9 @@ dependencies {

runtimeOnly libraries.netty.tcnative,
libraries.netty.tcnative.classes
testImplementation project(':grpc-context').sourceSets.test.output,
project(':grpc-api').sourceSets.test.output,
project(':grpc-core').sourceSets.test.output,
testImplementation testFixtures(project(':grpc-context')),
testFixtures(project(':grpc-api')),
testFixtures(project(':grpc-core')),
libraries.mockito.core,
libraries.junit,
libraries.truth
Expand Down
6 changes: 2 additions & 4 deletions netty/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ configurations {
alpnagent
}

evaluationDependsOn(project(':grpc-core').path)

dependencies {
api project(':grpc-core'),
libraries.netty.codec.http2
Expand All @@ -25,8 +23,8 @@ dependencies {
libraries.netty.unix.common

// Tests depend on base class defined by core module.
testImplementation project(':grpc-core').sourceSets.test.output,
project(':grpc-api').sourceSets.test.output,
testImplementation testFixtures(project(':grpc-core')),
testFixtures(project(':grpc-api')),
project(':grpc-testing'),
project(':grpc-testing-proto'),
libraries.conscrypt,
Expand Down
6 changes: 2 additions & 4 deletions okhttp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ plugins {

description = "gRPC: OkHttp"

evaluationDependsOn(project(':grpc-core').path)

dependencies {
api project(':grpc-core')
implementation libraries.okio,
Expand All @@ -18,8 +16,8 @@ dependencies {
// Make okhttp dependencies compile only
compileOnly libraries.okhttp
// Tests depend on base class defined by core module.
testImplementation project(':grpc-core').sourceSets.test.output,
project(':grpc-api').sourceSets.test.output,
testImplementation testFixtures(project(':grpc-core')),
testFixtures(project(':grpc-api')),
project(':grpc-testing'),
project(':grpc-testing-proto'),
libraries.netty.codec.http2,
Expand Down
4 changes: 1 addition & 3 deletions rls/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ plugins {

description = "gRPC: RouteLookupService Loadbalancing plugin"

evaluationDependsOn(project(':grpc-core').path)

dependencies {
implementation project(':grpc-core'),
project(':grpc-protobuf'),
Expand All @@ -22,7 +20,7 @@ dependencies {
project(':grpc-grpclb'),
project(':grpc-testing'),
project(':grpc-testing-proto'),
project(':grpc-core').sourceSets.test.output // for FakeClock
testFixtures(project(':grpc-core'))
signature libraries.signature.java
}

Expand Down
4 changes: 1 addition & 3 deletions services/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ tasks.named("compileJava").configure {
]
}

evaluationDependsOn(project(':grpc-core').path)

dependencies {
api project(':grpc-protobuf'),
project(':grpc-stub'),
Expand All @@ -30,7 +28,7 @@ dependencies {
compileOnly libraries.javax.annotation
testImplementation project(':grpc-testing'),
libraries.netty.transport.epoll, // for DomainSocketAddress
project(':grpc-core').sourceSets.test.output // for FakeClock
testFixtures(project(':grpc-core'))
testCompileOnly libraries.javax.annotation
signature libraries.signature.java
}
Expand Down
4 changes: 1 addition & 3 deletions testing/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ plugins {

description = "gRPC: Testing"

evaluationDependsOn(project(':grpc-core').path)

dependencies {
api project(':grpc-core'),
project(':grpc-stub'),
Expand All @@ -24,7 +22,7 @@ dependencies {
}

testImplementation project(':grpc-testing-proto'),
project(':grpc-core').sourceSets.test.output
testFixtures(project(':grpc-core'))

signature libraries.signature.java
signature libraries.signature.android
Expand Down
4 changes: 1 addition & 3 deletions xds/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ plugins {

description = "gRPC: XDS plugin"

evaluationDependsOn(project(':grpc-core').path)

sourceSets {
thirdparty {
java {
Expand Down Expand Up @@ -57,7 +55,7 @@ dependencies {
def nettyDependency = implementation project(':grpc-netty')

testImplementation project(':grpc-rls')
testImplementation project(':grpc-core').sourceSets.test.output
testImplementation testFixtures(project(':grpc-core'))

annotationProcessor libraries.auto.value
// At runtime use the epoll included in grpc-netty-shaded
Expand Down

0 comments on commit 29b8483

Please sign in to comment.