Skip to content

Commit

Permalink
Stress test with 100k * 100KB
Browse files Browse the repository at this point in the history
  • Loading branch information
bell-db committed Oct 10, 2024
1 parent 0ffb953 commit 8285b13
Showing 1 changed file with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@ import org.scalatest.matchers.must.Matchers
import protocbridge.{ExtraEnv, ProtocCodeGenerator}

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

class PosixPluginFrontendSpec extends AnyFlatSpec with Matchers {
if (!PluginFrontend.isWindows) {
it must "execute a program that forwards input and output to given stream" in {
val random = new Random()
val toSend = Array.fill(123)(random.nextInt(256).toByte)
val toReceive = Array.fill(456)(random.nextInt(256).toByte)
val toSend = Array.fill(100000)(random.nextInt(256).toByte)
val toReceive = Array.fill(100000)(random.nextInt(256).toByte)
val env = new ExtraEnv(secondaryOutputDir = "tmp")

val fakeGenerator = new ProtocCodeGenerator {
Expand All @@ -25,7 +29,7 @@ class PosixPluginFrontendSpec extends AnyFlatSpec with Matchers {
}

// Repeat 10,000 times since named pipes on macOS are flaky.
val repeatCount = 10000
val repeatCount = 100000
for (i <- 1 to repeatCount) {
if (i % 100 == 1) println(s"Running iteration $i of $repeatCount at ${java.time.LocalDateTime.now}")

Expand All @@ -42,9 +46,24 @@ class PosixPluginFrontendSpec extends AnyFlatSpec with Matchers {
}, processOutput => {
IOUtils.copy(processOutput, actualOutput)
processOutput.close()
}, _.close()))
process.exitValue()
actualOutput.toByteArray mustBe toReceive
}, processError => {
IOUtils.copy(processError, System.err)
processError.close()
}))
try {
Await.result(Future { process.exitValue() }, 15.seconds)
} catch {
case _: TimeoutException =>
System.err.println(s"Timeout on iteration $i of $repeatCount ($state)")
process.destroy()
}
val response = actualOutput.toByteArray
if (!(response sameElements toReceive)) {
System.err.println(
s"Mismatch on iteration $i of $repeatCount: " +
s"response(${response.length}) != toReceive(${toReceive.length}) ($state)"
)
}
PosixPluginFrontend.cleanup(state)
}
}
Expand Down

0 comments on commit 8285b13

Please sign in to comment.