Skip to content

Commit

Permalink
Solve StressSuite flakiness
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas Chapuis committed Feb 29, 2024
1 parent 0c75de3 commit 2757d69
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
3 changes: 2 additions & 1 deletion example/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

<logger name="endless.transaction.example.app.pekko.PekkoAccountsApp" level="WARN"/>
<logger name="endless.transaction.example" level="INFO"/>
<logger name="endless.runtime.pekko.deploy" level="INFO"/>
<logger name="org.apache.pekko" level="INFO"/>
<logger name="com.zaxxer.hikari" level="WARN"/>
<logger name="slick" level="WARN"/>
<root level="DEBUG">
<root level="INFO">
<appender-ref ref="STDOUT" />
</root>
</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ object PekkoAccountsApp {
private implicit val transferParameters: TransferParameters =
TransferParameters(timeout = 30.seconds)
private implicit val askTimeout: Timeout = Timeout(30.seconds)
private val terminationTimeout = 30.seconds
private val terminationTimeout = 5.seconds
private lazy val pekkoEventAdapter = new EventAdapter[AccountEvent, events.AccountEvent] {
private val eventAdapter = new AccountEventAdapter
override def toJournal(e: AccountEvent): events.AccountEvent = eventAdapter.toJournal(e)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package endless.transaction.example

import cats.effect.{IO, Ref}
import cats.effect.IO
import cats.effect.kernel.Resource
import cats.effect.std.Random
import cats.effect.unsafe.implicits.global
Expand Down Expand Up @@ -186,20 +186,19 @@ object Common {
def restartingPassiveNode(httpPort: Port, arteryPort: Port): IO[Unit] =
Slf4jLogger.create[IO].flatMap { logger =>
lazy val restartingNode: IO[Unit] = for {
checkSuccessful <- Ref.of[IO, Boolean](false)
random <- Random.scalaUtilRandom[IO]
restartPeriod <- random
.betweenInt(minRestartDelaySeconds, maxRestartDelaySeconds)
.map(_.seconds)
_ <- IO.race(
passiveNode(httpPort, arteryPort, checkSuccessful)
result <- IO.race(
passiveNode(httpPort, arteryPort)
.handleErrorWith((error: Throwable) => logger.error(error)("Node hard fail").toResource)
.use_,
IO.sleep(restartPeriod)
IO.sleep(restartPeriod) >> logger.info("Time elapsed, shutting down...")
)
_ <- checkSuccessful.get.flatMap {
case true => logger.info("Balance check successful, terminating...")
case false =>
_ <- result match {
case Left(_) => logger.info("Balance check successful, terminating...")
case Right(_) =>
logger.info("Restarting node...") >> IO.sleep(nodeRestartWaitingTime) >> restartingNode
}
} yield ()
Expand All @@ -214,8 +213,7 @@ object Common {

private def passiveNode(
httpPort: Port,
arteryPort: Port,
checkSuccessful: Ref[IO, Boolean]
arteryPort: Port
): Resource[IO, Unit] =
for {
logger <- Slf4jLogger.create[IO].toResource
Expand All @@ -234,7 +232,6 @@ object Common {
accountsCount,
originAmount - transferAmount
).toResource
_ <- checkSuccessful.set(true).toResource
_ <- logger.info("Shutting down").toResource
} yield ()

Expand Down

0 comments on commit 2757d69

Please sign in to comment.