1
1
package protocbridge .frontend
2
2
3
3
import org .apache .commons .io .IOUtils
4
+ import org .scalatest .exceptions .TestFailedException
4
5
import org .scalatest .flatspec .AnyFlatSpec
5
6
import org .scalatest .matchers .must .Matchers
6
7
import protocbridge .{ExtraEnv , ProtocCodeGenerator }
7
8
8
9
import java .io .ByteArrayOutputStream
10
+ import scala .concurrent .ExecutionContext .Implicits .global
11
+ import scala .concurrent .duration .DurationInt
12
+ import scala .concurrent .{Await , Future , TimeoutException }
9
13
import scala .sys .process .ProcessIO
10
14
import scala .util .Random
11
15
@@ -40,7 +44,13 @@ class OsSpecificFrontendSpec extends AnyFlatSpec with Matchers {
40
44
}
41
45
)
42
46
)
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
+ }
44
54
frontend.cleanup(state)
45
55
(state, actualOutput.toByteArray)
46
56
}
@@ -59,9 +69,27 @@ class OsSpecificFrontendSpec extends AnyFlatSpec with Matchers {
59
69
toReceive
60
70
}
61
71
}
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
+ }
62
85
val (state, response) =
63
86
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
+ }
65
93
state
66
94
}
67
95
0 commit comments