Skip to content

Commit

Permalink
Resolve checkName in Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Amerousful committed Sep 20, 2021
1 parent 23fe450 commit 5cf5caa
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 15 deletions.
Expand Up @@ -30,9 +30,9 @@ object Ws {
@SuppressWarnings(Array("org.wartremover.warts.DefaultArguments"))
def apply(requestName: Expression[String], wsName: Expression[String] = DefaultWebSocketName.expressionSuccess): Ws = new Ws(requestName, wsName)

def checkTextMessage(name: Expression[String]): WsTextFrameCheck = WsTextFrameCheck(name, Nil, Nil, isSilent = false)
def checkTextMessage(name: Expression[String]): WsTextFrameCheck = WsTextFrameCheck(name, Nil, Nil, isSilent = false, name = "")

def checkBinaryMessage(name: Expression[String]): WsBinaryFrameCheck = WsBinaryFrameCheck(name, Nil, Nil, isSilent = false)
def checkBinaryMessage(name: Expression[String]): WsBinaryFrameCheck = WsBinaryFrameCheck(name, Nil, Nil, isSilent = false, name = "")
}

/**
Expand Down
Expand Up @@ -20,18 +20,34 @@ import scala.concurrent.duration.FiniteDuration

import io.gatling.commons.validation._
import io.gatling.core.session.{ Expression, Session }
import io.gatling.http.check.ws.{ WsFrameCheck, WsFrameCheckSequence }
import io.gatling.http.check.ws.{ WsBinaryFrameCheck, WsFrameCheck, WsFrameCheckSequence, WsTextFrameCheck }

object WsFrameCheckSequenceBuilder {

@SuppressWarnings(Array("org.wartremover.warts.ListAppend"))
def resolve[T <: WsFrameCheck](builders: List[WsFrameCheckSequenceBuilder[T]], session: Session): Validation[List[WsFrameCheckSequence[T]]] =
def resolve[T <: WsFrameCheck](builders: List[WsFrameCheckSequenceBuilder[T]], session: Session): Validation[List[WsFrameCheckSequence[T]]] = {
builders.foldLeft(List.empty[WsFrameCheckSequence[T]].success) { (acc, builder) =>
for {
accValue <- acc
timeout <- builder.timeout(session)
} yield accValue :+ WsFrameCheckSequence(timeout, builder.checks)
accValue <- acc
} yield accValue :+ WsFrameCheckSequence(timeout, resolveCheckName(builder.checks, session).asInstanceOf[List[T]])
}
}

@SuppressWarnings(Array("org.wartremover.warts.ListAppend"))
private def resolveCheckName[T <: WsFrameCheck](checks: List[WsFrameCheck], session: Session): List[WsFrameCheck] = {
checks
.map {
case check: WsBinaryFrameCheck =>
check.checkName(session) match {
case Success(value) => check.copy(name = value)
}
case check: WsTextFrameCheck =>
check.checkName(session) match {
case Success(value) => check.copy(name = value)
}
}
}
}

final case class WsFrameCheckSequenceBuilder[+T <: WsFrameCheck](timeout: Expression[FiniteDuration], checks: List[T])
Expand Up @@ -73,7 +73,7 @@ final case class WsPerformingCheckState(
NextWsState(this)
} else {
currentCheck match {
case WsTextFrameCheck(_, matchConditions, checks, _) =>
case WsTextFrameCheck(_, matchConditions, checks, _, _) =>
tryApplyingChecks(message, timestamp, matchConditions, checks)

case _ =>
Expand All @@ -86,7 +86,7 @@ final case class WsPerformingCheckState(

override def onBinaryFrameReceived(message: Array[Byte], timestamp: Long): NextWsState =
currentCheck match {
case WsBinaryFrameCheck(_, matchConditions, checks, _) =>
case WsBinaryFrameCheck(_, matchConditions, checks, _, _) =>
tryApplyingChecks(message, timestamp, matchConditions, checks)

case _ =>
Expand All @@ -113,9 +113,7 @@ final case class WsPerformingCheckState(
if (currentCheck.isSilent) {
sessionWithCheckUpdate
} else {
currentCheck.name(session) match {
case Success(checkName) => logResponse(sessionWithCheckUpdate, checkName, checkSequenceStart, end, status, code, reason)
}
logResponse(sessionWithCheckUpdate, currentCheck.name, checkSequenceStart, end, status, code, reason)
}

private def tryApplyingChecks[T](message: T, timestamp: Long, matchConditions: List[Check[T]], checks: List[Check[T]]): NextWsState = {
Expand Down
Expand Up @@ -27,12 +27,17 @@ final case class WsFrameCheckSequence[+T <: WsFrameCheck](timeout: FiniteDuratio
}

sealed trait WsFrameCheck {
def name: Expression[String]
def name: String
def isSilent: Boolean
}

final case class WsBinaryFrameCheck(name: Expression[String], matchConditions: List[WsBinaryCheck], checks: List[WsBinaryCheck], isSilent: Boolean)
extends WsFrameCheck {
final case class WsBinaryFrameCheck(
checkName: Expression[String],
matchConditions: List[WsBinaryCheck],
checks: List[WsBinaryCheck],
isSilent: Boolean,
name: String
) extends WsFrameCheck {

def matching(newMatchConditions: WsBinaryCheck*): WsBinaryFrameCheck = {
require(!newMatchConditions.contains(null), "Matching conditions can't contain null elements. Forward reference issue?")
Expand All @@ -48,7 +53,7 @@ final case class WsBinaryFrameCheck(name: Expression[String], matchConditions: L
copy(isSilent = true)
}

final case class WsTextFrameCheck(name: Expression[String], matchConditions: List[WsTextCheck], checks: List[WsTextCheck], isSilent: Boolean)
final case class WsTextFrameCheck(checkName: Expression[String], matchConditions: List[WsTextCheck], checks: List[WsTextCheck], isSilent: Boolean, name: String)
extends WsFrameCheck {

def matching(newMatchConditions: WsTextCheck*): WsTextFrameCheck = {
Expand Down

0 comments on commit 5cf5caa

Please sign in to comment.