Skip to content

Commit

Permalink
Fix AuthorizationInterceptorSpec flake (#11387)
Browse files Browse the repository at this point in the history
CHANGELOG_BEGIN
CHANGELOG_END
  • Loading branch information
tudor-da authored Oct 25, 2021
1 parent 7090f2d commit b14077a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions ledger/ledger-api-auth/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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
Expand Down Expand Up @@ -56,16 +56,19 @@ 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]

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)
}
Expand Down

0 comments on commit b14077a

Please sign in to comment.