Support suspending functions returning Unit in WebFlux

Closes gh-27629
This commit is contained in:
Sébastien Deleuze
2022-11-13 18:53:55 +01:00
parent 3ff308403a
commit b766a49a4d
2 changed files with 22 additions and 12 deletions

View File

@@ -34,6 +34,7 @@ import org.springframework.web.reactive.result.method.annotation.ContinuationHan
import reactor.core.publisher.Mono
import reactor.test.StepVerifier
import java.lang.reflect.Method
import java.time.Duration
import kotlin.reflect.jvm.javaMethod
class KotlinInvocableHandlerMethodTests {
@@ -89,11 +90,9 @@ class KotlinInvocableHandlerMethodTests {
val response = this.exchange.response
this.resolvers.add(stubResolver(response))
val method = CoroutinesController::response.javaMethod!!
val result = invoke(CoroutinesController(), method)
val result = invokeForResult(CoroutinesController(), method, response)
StepVerifier.create(result)
.consumeNextWith { StepVerifier.create(it.returnValue as Mono<*>).verifyComplete() }
.verifyComplete()
assertThat(result).`as`("Expected no result (i.e. fully handled)").isNull()
assertThat(this.exchange.response.headers.getFirst("foo")).isEqualTo("bar")
}
@@ -105,6 +104,10 @@ class KotlinInvocableHandlerMethodTests {
assertHandlerResultValue(result, "success:foo")
}
private fun invokeForResult(handler: Any, method: Method, vararg providedArgs: Any): HandlerResult? {
return invoke(handler, method, *providedArgs).block(Duration.ofSeconds(5))
}
private fun invoke(handler: Any, method: Method, vararg providedArgs: Any?): Mono<HandlerResult> {
val invocable = InvocableHandlerMethod(handler, method)
invocable.setArgumentResolvers(this.resolvers)