Skip to content

Commit

Permalink
[FIX] Connect was not properly measured
Browse files Browse the repository at this point in the history
 - False measurement of connect timings as "connect" was a noop
  • Loading branch information
chibenwa committed Apr 13, 2023
1 parent 222a197 commit 0ea4743
Showing 1 changed file with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import java.util.function.Consumer
import akka.actor.{Props, Stash}
import com.linagora.gatling.imap.protocol.command._
import com.yahoo.imapnio.async.client.ImapAsyncSession.DebugMode
import com.yahoo.imapnio.async.client.{ImapAsyncClient, ImapAsyncSession, ImapAsyncSessionConfig}
import com.yahoo.imapnio.async.client.{ImapAsyncClient, ImapAsyncSession, ImapAsyncSessionConfig, ImapFuture}
import com.yahoo.imapnio.async.internal.ImapAsyncSessionImpl
import io.gatling.core.akka.BaseActor
import io.gatling.core.util.NameGen
import javax.net.ssl.SSLContext
Expand Down Expand Up @@ -57,25 +58,25 @@ private object ImapSession {
private class ImapSession(client: => ImapAsyncClient, protocol: ImapProtocol) extends BaseActor with Stash with NameGen {
val uri = new URI(s"${protocol.protocol}://${protocol.host}:${protocol.port}")
val config: Properties = protocol.config
logger.debug(s"connecting to $uri with $config")
val session: ImapAsyncSession = {
val config = new ImapAsyncSessionConfig
config.setConnectionTimeoutMillis(50000)
config.setReadTimeoutMillis(60000)
val sniNames = null

val localAddress = null
client
.createSession(uri, config, localAddress, sniNames, DebugMode.DEBUG_OFF, "ImapSession", ImapSession.sslContext)
.get()
.getSession
}
var session: ImapAsyncSession = null

override def receive: Receive = disconnected

def disconnected: Receive = {
case Command.Connect(userId) =>
logger.debug(s"got connect request, $userId connecting to $uri")

val config = new ImapAsyncSessionConfig
config.setConnectionTimeoutMillis(50000)
config.setReadTimeoutMillis(60000)
val sniNames = null
val localAddress = null

session = client
.createSession(uri, config, localAddress, sniNames, DebugMode.DEBUG_OFF, "ImapSession", ImapSession.sslContext)
.get()
.getSession

context.become(connected)
sender() ! Response.Connected(ImapResponses.empty)
case Response.Disconnected(_) => ()
Expand Down Expand Up @@ -207,6 +208,7 @@ private class ImapSession(client: => ImapAsyncClient, protocol: ImapProtocol) ex
case Command.Disconnect(userId) =>
context.become(disconnected)
val responseCallback: Consumer[java.lang.Boolean] = _ => {
session = null
sender() ! Response.Disconnected(s"Disconnected command for ${userId.value}")
}
val future = session.close()
Expand Down

0 comments on commit 0ea4743

Please sign in to comment.