Skip to content

Commit

Permalink
Stress test PosixPluginFrontendSpec
Browse files Browse the repository at this point in the history
  • Loading branch information
bell-db committed Sep 13, 2024
1 parent d423554 commit e65622d
Showing 1 changed file with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package protocbridge.frontend

import org.apache.commons.io.IOUtils
import org.scalatest.exceptions.TestFailedException
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.must.Matchers
import protocbridge.{ExtraEnv, ProtocCodeGenerator}

import java.io.ByteArrayOutputStream
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration.DurationInt
import scala.concurrent.{Await, Future, TimeoutException}
import scala.sys.process.ProcessIO
import scala.util.Random

Expand Down Expand Up @@ -40,7 +44,13 @@ class OsSpecificFrontendSpec extends AnyFlatSpec with Matchers {
}
)
)
process.exitValue()
try {
Await.result(Future { process.exitValue() }, 5.seconds)
} catch {
case _: TimeoutException =>
System.err.println(s"Timeout")
process.destroy()
}
frontend.cleanup(state)
(state, actualOutput.toByteArray)
}
Expand All @@ -59,9 +69,27 @@ class OsSpecificFrontendSpec extends AnyFlatSpec with Matchers {
toReceive
}
}
// Repeat 100,000 times since named pipes on macOS are flaky.
val repeatCount = 100000
for (i <- 1 until repeatCount) {
if (i % 100 == 1) println(s"Running iteration $i of $repeatCount")
val (state, response) =
testPluginFrontend(frontend, fakeGenerator, env, toSend)
try {
response mustBe toReceive
} catch {
case e: TestFailedException =>
System.err.println(s"""Failed on iteration $i of $repeatCount: ${e.getMessage}""")
}
}
val (state, response) =
testPluginFrontend(frontend, fakeGenerator, env, toSend)
response mustBe toReceive
try {
response mustBe toReceive
} catch {
case e: TestFailedException =>
System.err.println(s"""Failed on iteration $repeatCount of $repeatCount: ${e.getMessage}""")
}
state
}

Expand Down

0 comments on commit e65622d

Please sign in to comment.