Skip to content

Commit

Permalink
Review feedback including unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverse-da committed Nov 8, 2021
1 parent f9ce0ec commit 34222b0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ private[apiserver] final class ApiSubmissionService private[services] (
)
} yield submissionResult
}

// Takes the whole transaction to ensure to traverse it only if necessary
private[services] def allocateMissingInformees(
transaction: SubmittedTransaction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import com.daml.ledger.participant.state.index.v2.{
IndexPartyManagementService,
IndexSubmissionService,
}
import com.daml.ledger.participant.state.v2.WriteService
import com.daml.ledger.participant.state.v2.{SubmissionResult, WriteService}
import com.daml.ledger.participant.state.{v2 => state}
import com.daml.lf
import com.daml.lf.command.{Commands => LfCommands}
Expand All @@ -35,15 +35,15 @@ import com.daml.platform.apiserver.services.ApiSubmissionServiceSpec._
import com.daml.platform.apiserver.SeedService
import com.daml.telemetry.{NoOpTelemetryContext, TelemetryContext}
import com.google.rpc.status.{Status => RpcStatus}
import io.grpc.Status
import io.grpc.{Status, StatusRuntimeException}
import org.mockito.{ArgumentMatchersSugar, MockitoSugar}
import org.scalatest.flatspec.AsyncFlatSpec
import org.scalatest.matchers.should.Matchers
import org.scalatest.{Assertion, Inside}

import java.time.Duration
import java.util.concurrent.CompletableFuture.completedFuture
import java.util.concurrent.atomic.AtomicInteger

import scala.concurrent.{ExecutionContext, Future}
import scala.util.{Failure, Success, Try}

Expand Down Expand Up @@ -413,6 +413,32 @@ class ApiSubmissionServiceSpec
Success(succeed)
})
}

it should "rate-limit when configured to do so" in {
val grpcError = RpcStatus.of(Status.Code.ABORTED.value(), s"Quota Exceeded", Seq.empty)

val service =
newSubmissionService(
mock[state.WriteService],
mock[IndexPartyManagementService],
implicitPartyAllocation = true,
deduplicationEnabled = false,
mockIndexSubmissionService = mock[IndexSubmissionService],
commandExecutor = mock[CommandExecutor],
checkOverloaded = _ => Some(SubmissionResult.SynchronousError(grpcError)),
)

val submitRequest = newSubmitRequest()
service
.submit(submitRequest)
.transform {
case Failure(e: StatusRuntimeException)
if e.getStatus.getCode.value == grpcError.code && e.getStatus.getDescription == grpcError.message =>
Success(succeed)
case result =>
Try(fail(s"Expected submission to be aborted, but got ${result}"))
}
}
}

object ApiSubmissionServiceSpec {
Expand Down Expand Up @@ -449,6 +475,7 @@ object ApiSubmissionServiceSpec {
deduplicationEnabled: Boolean = true,
mockIndexSubmissionService: IndexSubmissionService = mock[IndexSubmissionService],
useSelfServiceErrorCodes: Boolean = false,
checkOverloaded: TelemetryContext => Option[SubmissionResult] = _ => None,
)(implicit
executionContext: ExecutionContext,
loggingContext: LoggingContext,
Expand Down Expand Up @@ -489,7 +516,7 @@ object ApiSubmissionServiceSpec {
errorCodesVersionSwitcher = new ErrorCodesVersionSwitcher(
enableSelfServiceErrorCodes = useSelfServiceErrorCodes
),
checkOverloaded = _ => None, // Used and tested in Canton
checkOverloaded = checkOverloaded,
)
}
}

0 comments on commit 34222b0

Please sign in to comment.