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 crosstests to use testcontainers #84

Merged
merged 2 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 0 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,8 @@ jobs:
cache: false
- name: Generate proto files for cross tests.
run: make generatecrosstests
- name: Start test server
run: make crosstestserverrun
- name: Run crosstests
run: make crosstestsrun
- name: Stop test server
run: make crosstestserverstop
license-headers:
runs-on: ubuntu-latest
steps:
Expand Down
16 changes: 1 addition & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ MAKEFLAGS += --no-print-directory
BIN := .tmp/bin
CACHE := .tmp/cache
LICENSE_HEADER_YEAR_RANGE := 2022-2023
CROSSTEST_VERSION := 162d496c009e2ffb1a638b4a2ea789e9cc3331bb
LICENSE_HEADER_VERSION := v1.26.1
PROTOC_VERSION ?= 24.1
GRADLE_ARGS ?=
Expand All @@ -26,7 +25,7 @@ $(BIN)/license-headers: Makefile

.PHONY: build
build: generate ## Build the entire project.
./gradlew $(GRADLE_ARGS) build -x test
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@smallsamantha - I noticed there were real compile errors in the tests which weren't getting reported in any of the CI checks as part of #79. This should resolve that.

./gradlew $(GRADLE_ARGS) build

.PHONY: buildplugin
buildplugin: ## Build the connect-kotlin protoc plugin.
Expand All @@ -45,19 +44,6 @@ clean: ## Cleans the underlying build.

rm -rf protoc-gen-connect-kotlin/src/test/java/

.PHONY: crosstestserverrun
crosstestserverrun: crosstestserverstop ## Run the server for cross tests.
docker run --rm --name serverconnect -p 8080:8080 -p 8081:8081 -d \
bufbuild/connect-crosstest:$(CROSSTEST_VERSION) \
/usr/local/bin/serverconnect --h1port "8080" --h2port "8081" --cert "cert/localhost.crt" --key "cert/localhost.key"
docker run --rm --name servergrpc -p 8083:8083 -d \
Copy link
Contributor Author

Choose a reason for hiding this comment

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

NOTE: I never saw anything connect to anything other than the h2port of the connect server. If we want to extend the tests to hit the gRPC server we should do that.

bufbuild/connect-crosstest:$(CROSSTEST_VERSION) \
/usr/local/bin/servergrpc --port "8083" --cert "cert/localhost.crt" --key "cert/localhost.key"

.PHONY: crosstestserverstop
crosstestserverstop: ## Stop the server for cross tests.
-docker container stop serverconnect servergrpc

.PHONY: crosstestsrun
crosstestsrun: crosstestsrunjava ## Run the cross tests.

Expand Down
1 change: 1 addition & 0 deletions crosstests/google-java/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ dependencies {
testImplementation(libs.assertj)
testImplementation(libs.mockito)
testImplementation(libs.kotlin.coroutines.core)
testImplementation(libs.testcontainers)
}

configure<SpotlessExtension> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@ import okhttp3.Protocol
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.fail
import org.junit.Before
import org.junit.ClassRule
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import org.junit.runners.Parameterized.Parameters
import org.testcontainers.containers.GenericContainer
import java.time.Duration
import java.util.Base64
import java.util.concurrent.CountDownLatch
Expand All @@ -63,6 +65,8 @@ class CrossTest(
private lateinit var testServiceConnectClient: TestServiceClient

companion object {
const val CROSSTEST_VERSION = "162d496c009e2ffb1a638b4a2ea789e9cc3331bb"

@JvmStatic
@Parameters(name = "protocol")
fun data(): Iterable<NetworkProtocol> {
Expand All @@ -71,12 +75,27 @@ class CrossTest(
NetworkProtocol.GRPC
)
}

@JvmField
@ClassRule
val CROSSTEST_CONTAINER = GenericContainer("bufbuild/connect-crosstest:${CROSSTEST_VERSION}")
.withExposedPorts(8080, 8081)
.withCommand(
"/usr/local/bin/serverconnect",
"--h1port",
"8080",
"--h2port",
"8081",
"--cert",
"cert/localhost.crt",
"--key",
"cert/localhost.key",
)
}

@Before
fun before() {
val port = 8081
val host = "https://localhost:$port"
val host = "https://localhost:${CROSSTEST_CONTAINER.getMappedPort(8081)}"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will use an ephemeral port so it won't fail if something else is bound to 8080/8081.

val (sslSocketFactory, trustManager) = sslContext()
val client = OkHttpClient.Builder()
.protocols(listOf(Protocol.HTTP_2, Protocol.HTTP_1_1))
Expand Down
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ protobuf-javalite = { module = "com.google.protobuf:protobuf-javalite", version.
protobuf-kotlin = { module = "com.google.protobuf:protobuf-kotlin", version.ref = "protobuf" }
protobuf-kotlinlite = { module = "com.google.protobuf:protobuf-kotlin-lite", version.ref = "protobuf" }
spotless = { module = "com.diffplug.spotless:spotless-plugin-gradle", version = "6.13.0" }
testcontainers = { module = "org.testcontainers:testcontainers", version = "1.19.0" }

[plugins]
git = { id = "com.palantir.git-version", version = "3.0.0" }
Loading