Skip to content

Fix interceptor tests #148

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 6 commits into from
Jul 22, 2020
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
30 changes: 15 additions & 15 deletions stub/src/test/java/io/grpc/kotlin/AbstractCallsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,17 @@ abstract class AbstractCallsTest {
}

/** Generates a channel to a Greeter server with the specified implementation. */
fun makeChannel(impl: BindableService): ManagedChannel {
fun makeChannel(impl: BindableService, vararg interceptors: ServerInterceptor): ManagedChannel =
makeChannel(ServerInterceptors.intercept(impl, *interceptors))

fun makeChannel(serverServiceDefinition: ServerServiceDefinition): ManagedChannel {
val serverName = InProcessServerBuilder.generateName()

grpcCleanup.register(
InProcessServerBuilder.forName(serverName)
.run { this as ServerBuilder<*> } // workaround b/123879662
.executor(executor)
.addService(impl)
.addService(serverServiceDefinition)
.build()
.start()
)
Expand All @@ -173,20 +176,17 @@ abstract class AbstractCallsTest {
fun makeChannel(
impl: ServerMethodDefinition<*, *>,
vararg interceptors: ServerInterceptor
): ManagedChannel =
makeChannel(
BindableService {
val builder = ServerServiceDefinition.builder(greeterService)
for (method in greeterService.methods) {
if (method == impl.methodDescriptor) {
builder.addMethod(impl)
} else {
builder.addMethod(method, ServerCallHandler { _, _ -> TODO() })
}
}
ServerInterceptors.intercept(builder.build(), *interceptors)
): ManagedChannel {
val builder = ServerServiceDefinition.builder(greeterService)
for (method in greeterService.methods) {
if (method == impl.methodDescriptor) {
builder.addMethod(impl)
} else {
builder.addMethod(method, ServerCallHandler { _, _ -> TODO() })
}
)
}
return makeChannel(ServerInterceptors.intercept(builder.build(), *interceptors))
}

fun <R> runBlocking(block: suspend CoroutineScope.() -> R): Unit =
kotlinx.coroutines.runBlocking(context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import kotlin.coroutines.coroutineContext
import io.grpc.Metadata as GrpcMetadata

/** Tests for [CoroutineContextServerInterceptor]. */
@RunWith(JUnit4::class) /* inserted by Copybara: */ @com.google.testing.testsize.MediumTest
@RunWith(JUnit4::class)
class CoroutineContextServerInterceptorTest : AbstractCallsTest() {
class ArbitraryContextElement(val message: String = "") : CoroutineContext.Element {
companion object Key : CoroutineContext.Key<ArbitraryContextElement>
Expand Down