Skip to content

Commit 687db56

Browse files
committed
Stress test PosixPluginFrontendSpec
1 parent d423554 commit 687db56

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

bridge/src/test/scala/protocbridge/frontend/OsSpecificFrontendSpec.scala

+30-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
package protocbridge.frontend
22

33
import org.apache.commons.io.IOUtils
4+
import org.scalatest.exceptions.TestFailedException
45
import org.scalatest.flatspec.AnyFlatSpec
56
import org.scalatest.matchers.must.Matchers
67
import protocbridge.{ExtraEnv, ProtocCodeGenerator}
78

89
import java.io.ByteArrayOutputStream
10+
import scala.concurrent.ExecutionContext.Implicits.global
11+
import scala.concurrent.duration.DurationInt
12+
import scala.concurrent.{Await, Future, TimeoutException}
913
import scala.sys.process.ProcessIO
1014
import scala.util.Random
1115

@@ -40,7 +44,13 @@ class OsSpecificFrontendSpec extends AnyFlatSpec with Matchers {
4044
}
4145
)
4246
)
43-
process.exitValue()
47+
try {
48+
Await.result(Future { process.exitValue() }, 5.seconds)
49+
} catch {
50+
case _: TimeoutException =>
51+
System.err.println(s"Timeout")
52+
process.destroy()
53+
}
4454
frontend.cleanup(state)
4555
(state, actualOutput.toByteArray)
4656
}
@@ -59,9 +69,27 @@ class OsSpecificFrontendSpec extends AnyFlatSpec with Matchers {
5969
toReceive
6070
}
6171
}
72+
// Repeat 100,000 times since named pipes on macOS are flaky.
73+
val repeatCount = 100000
74+
for (i <- 1 until repeatCount) {
75+
if (i % 100 == 1) println(s"Running iteration $i of $repeatCount")
76+
val (state, response) =
77+
testPluginFrontend(frontend, fakeGenerator, env, toSend)
78+
try {
79+
response mustBe response
80+
} catch {
81+
case e: TestFailedException =>
82+
System.err.println(s"""Failed on iteration $i of $repeatCount: ${e.getMessage}""")
83+
}
84+
}
6285
val (state, response) =
6386
testPluginFrontend(frontend, fakeGenerator, env, toSend)
64-
response mustBe toReceive
87+
try {
88+
response mustBe response
89+
} catch {
90+
case e: TestFailedException =>
91+
System.err.println(s"""Failed on iteration $repeatCount of $repeatCount: ${e.getMessage}""")
92+
}
6593
state
6694
}
6795

0 commit comments

Comments
 (0)