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

Fix AuthorizationInterceptorSpec flake #11387

Merged
merged 1 commit into from
Oct 25, 2021
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
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