diff --git a/ledger/ledger-api-auth/BUILD.bazel b/ledger/ledger-api-auth/BUILD.bazel index 99806f26e88d..80e3b40dc8c2 100644 --- a/ledger/ledger-api-auth/BUILD.bazel +++ b/ledger/ledger-api-auth/BUILD.bazel @@ -68,6 +68,7 @@ da_scala_test_suite( ":ledger-api-auth", "//ledger/error", "//ledger/test-common", + "//libs-scala/concurrent", "@maven//:com_google_api_grpc_proto_google_common_protos", "@maven//:com_google_protobuf_protobuf_java", "@maven//:io_grpc_grpc_api", diff --git a/ledger/ledger-api-auth/src/test/suite/scala/com/digitalasset/ledger/api/auth/AuthorizationInterceptorSpec.scala b/ledger/ledger-api-auth/src/test/suite/scala/com/digitalasset/ledger/api/auth/AuthorizationInterceptorSpec.scala index 1683dab1be95..8f47fd123742 100644 --- a/ledger/ledger-api-auth/src/test/suite/scala/com/digitalasset/ledger/api/auth/AuthorizationInterceptorSpec.scala +++ b/ledger/ledger-api-auth/src/test/suite/scala/com/digitalasset/ledger/api/auth/AuthorizationInterceptorSpec.scala @@ -3,9 +3,11 @@ package com.daml.ledger.api.auth +import com.daml.dec.DirectExecutionContext import com.daml.error.ErrorCodesVersionSwitcher import com.daml.ledger.api.auth.interceptor.AuthorizationInterceptor import com.google.rpc.ErrorInfo +import io.grpc.protobuf.StatusProto import io.grpc.{Metadata, ServerCall, Status} import org.mockito.captor.ArgCaptor import org.mockito.{ArgumentMatchersSugar, MockitoSugar} @@ -14,8 +16,6 @@ import org.scalatest.flatspec.AnyFlatSpec import org.scalatest.matchers.should.Matchers import java.util.concurrent.CompletableFuture -import scala.concurrent.ExecutionContext.global -import io.grpc.protobuf.StatusProto class AuthorizationInterceptorSpec extends AnyFlatSpec @@ -56,8 +56,11 @@ class AuthorizationInterceptorSpec ) val errorCodesStatusSwitcher = new ErrorCodesVersionSwitcher(usesSelfServiceErrorCodes) - val authorizationInterceptor = - AuthorizationInterceptor(authService, global, errorCodesStatusSwitcher) + val authorizationInterceptor = { + // Use parasitic execution context to ensure that all expected async calls dispatched by this constructor + // finish within the constructor's boundaries. + AuthorizationInterceptor(authService, DirectExecutionContext, errorCodesStatusSwitcher) + } val statusCaptor = ArgCaptor[Status] val metadataCaptor = ArgCaptor[Metadata] @@ -65,7 +68,7 @@ class AuthorizationInterceptorSpec when(authService.decodeMetadata(any[Metadata])).thenReturn(failedMetadataDecode) authorizationInterceptor.interceptCall[Nothing, Nothing](serverCall, new Metadata(), null) - verify(serverCall, timeout(1000)).close(statusCaptor.capture, metadataCaptor.capture) + verify(serverCall).close(statusCaptor.capture, metadataCaptor.capture) assertRpcStatus(statusCaptor.value, metadataCaptor.value) }