From 7953a64f4da9b54a65884d677ee1c20d1985bfe4 Mon Sep 17 00:00:00 2001 From: Bell Le Date: Fri, 9 Aug 2024 10:00:32 -0700 Subject: [PATCH 1/3] Add PosixPluginFrontendSpec --- .../frontend/OsSpecificFrontendSpec.scala | 56 +++++++++++++++++++ .../frontend/PosixPluginFrontendSpec.scala | 9 +++ .../frontend/WindowsPluginFrontendSpec.scala | 33 +---------- 3 files changed, 67 insertions(+), 31 deletions(-) create mode 100644 bridge/src/test/scala/protocbridge/frontend/OsSpecificFrontendSpec.scala create mode 100644 bridge/src/test/scala/protocbridge/frontend/PosixPluginFrontendSpec.scala diff --git a/bridge/src/test/scala/protocbridge/frontend/OsSpecificFrontendSpec.scala b/bridge/src/test/scala/protocbridge/frontend/OsSpecificFrontendSpec.scala new file mode 100644 index 0000000..5b158ac --- /dev/null +++ b/bridge/src/test/scala/protocbridge/frontend/OsSpecificFrontendSpec.scala @@ -0,0 +1,56 @@ +package protocbridge.frontend + +import org.scalatest.flatspec.AnyFlatSpec +import org.scalatest.matchers.must.Matchers +import protocbridge.{ExtraEnv, ProtocCodeGenerator} + +import java.io.ByteArrayOutputStream +import scala.sys.process.ProcessIO +import scala.util.Random + +class OsSpecificFrontendSpec extends AnyFlatSpec with Matchers { + + protected def testPluginFrontend(frontend: PluginFrontend): Array[Byte] = { + val random = new Random() + val toSend = Array.fill(123)(random.nextInt(256).toByte) + val toReceive = Array.fill(456)(random.nextInt(256).toByte) + val env = new ExtraEnv(secondaryOutputDir = "tmp") + + val fakeGenerator = new ProtocCodeGenerator { + override def run(request: Array[Byte]): Array[Byte] = { + request mustBe (toSend ++ env.toByteArrayAsField) + toReceive + } + } + val (path, state) = frontend.prepare( + fakeGenerator, + env + ) + val actualOutput = new ByteArrayOutputStream() + val process = sys.process + .Process(path.toAbsolutePath.toString) + .run( + new ProcessIO( + writeInput => { + writeInput.write(toSend) + writeInput.close() + }, + processOutput => { + val buffer = new Array[Byte](4096) + var bytesRead = 0 + while (bytesRead != -1) { + bytesRead = processOutput.read(buffer) + if (bytesRead != -1) { + actualOutput.write(buffer, 0, bytesRead) + } + } + processOutput.close() + }, + _.close() + ) + ) + process.exitValue() + frontend.cleanup(state) + actualOutput.toByteArray + } +} diff --git a/bridge/src/test/scala/protocbridge/frontend/PosixPluginFrontendSpec.scala b/bridge/src/test/scala/protocbridge/frontend/PosixPluginFrontendSpec.scala new file mode 100644 index 0000000..0d6d76a --- /dev/null +++ b/bridge/src/test/scala/protocbridge/frontend/PosixPluginFrontendSpec.scala @@ -0,0 +1,9 @@ +package protocbridge.frontend + +class PosixPluginFrontendSpec extends OsSpecificFrontendSpec { + if (!PluginFrontend.isWindows) { + it must "execute a program that forwards input and output to given stream" in { + testPluginFrontend(PosixPluginFrontend) + } + } +} diff --git a/bridge/src/test/scala/protocbridge/frontend/WindowsPluginFrontendSpec.scala b/bridge/src/test/scala/protocbridge/frontend/WindowsPluginFrontendSpec.scala index 6385ad7..7936141 100644 --- a/bridge/src/test/scala/protocbridge/frontend/WindowsPluginFrontendSpec.scala +++ b/bridge/src/test/scala/protocbridge/frontend/WindowsPluginFrontendSpec.scala @@ -1,38 +1,9 @@ package protocbridge.frontend -import java.io.ByteArrayInputStream - -import protocbridge.{ProtocCodeGenerator, ExtraEnv} - -import scala.sys.process.ProcessLogger -import org.scalatest.flatspec.AnyFlatSpec -import org.scalatest.matchers.must.Matchers - -class WindowsPluginFrontendSpec extends AnyFlatSpec with Matchers { +class WindowsPluginFrontendSpec extends OsSpecificFrontendSpec { if (PluginFrontend.isWindows) { it must "execute a program that forwards input and output to given stream" in { - val toSend = "ping" - val toReceive = "pong" - val env = new ExtraEnv(secondaryOutputDir = "tmp") - - val fakeGenerator = new ProtocCodeGenerator { - override def run(request: Array[Byte]): Array[Byte] = { - request mustBe (toSend.getBytes ++ env.toByteArrayAsField) - toReceive.getBytes - } - } - val (path, state) = WindowsPluginFrontend.prepare( - fakeGenerator, - env - ) - val actualOutput = scala.collection.mutable.Buffer.empty[String] - val process = sys.process - .Process(path.toAbsolutePath.toString) - .#<(new ByteArrayInputStream(toSend.getBytes)) - .run(ProcessLogger(o => actualOutput.append(o))) - process.exitValue() - actualOutput.mkString mustBe toReceive - WindowsPluginFrontend.cleanup(state) + testPluginFrontend(WindowsPluginFrontend) } } } From c576aedae92e4231588d883dba3d49170696c6fa Mon Sep 17 00:00:00 2001 From: Bell Le Date: Fri, 16 Aug 2024 16:54:29 -0700 Subject: [PATCH 2/3] Handle all failures in Future --- .../frontend/PluginFrontend.scala | 20 +++---- .../frontend/PosixPluginFrontend.scala | 5 ++ .../frontend/OsSpecificFrontendSpec.scala | 52 ++++++++++++++----- .../frontend/PosixPluginFrontendSpec.scala | 6 ++- .../frontend/WindowsPluginFrontendSpec.scala | 6 ++- 5 files changed, 63 insertions(+), 26 deletions(-) diff --git a/bridge/src/main/scala/protocbridge/frontend/PluginFrontend.scala b/bridge/src/main/scala/protocbridge/frontend/PluginFrontend.scala index 7415f06..ec7d6ca 100644 --- a/bridge/src/main/scala/protocbridge/frontend/PluginFrontend.scala +++ b/bridge/src/main/scala/protocbridge/frontend/PluginFrontend.scala @@ -5,8 +5,6 @@ import java.nio.file.{Files, Path} import protocbridge.{ProtocCodeGenerator, ExtraEnv} -import scala.util.Try - /** A PluginFrontend instance provides a platform-dependent way for protoc to * communicate with a JVM based ProtocCodeGenerator. * @@ -47,13 +45,7 @@ object PluginFrontend { gen: ProtocCodeGenerator, request: Array[Byte] ): Array[Byte] = { - Try { - gen.run(request) - }.recover { case throwable => - createCodeGeneratorResponseWithError( - throwable.toString + "\n" + getStackTrace(throwable) - ) - }.get + gen.run(request) } def createCodeGeneratorResponseWithError(error: String): Array[Byte] = { @@ -116,9 +108,17 @@ object PluginFrontend { gen: ProtocCodeGenerator, fsin: InputStream, env: ExtraEnv - ): Array[Byte] = { + ): Array[Byte] = try { val bytes = readInputStreamToByteArrayWithEnv(fsin, env) runWithBytes(gen, bytes) + } catch { + // This covers all Throwable including OutOfMemoryError, StackOverflowError, etc. + // We need to make a best effort to return a response to protoc, + // otherwise protoc can hang indefinitely. + case throwable: Throwable => + createCodeGeneratorResponseWithError( + throwable.toString + "\n" + getStackTrace(throwable) + ) } def createTempFile(extension: String, content: String): Path = { diff --git a/bridge/src/main/scala/protocbridge/frontend/PosixPluginFrontend.scala b/bridge/src/main/scala/protocbridge/frontend/PosixPluginFrontend.scala index 5f70120..ef57687 100644 --- a/bridge/src/main/scala/protocbridge/frontend/PosixPluginFrontend.scala +++ b/bridge/src/main/scala/protocbridge/frontend/PosixPluginFrontend.scala @@ -40,6 +40,11 @@ object PosixPluginFrontend extends PluginFrontend { val response = PluginFrontend.runWithInputStream(plugin, fsin, env) fsin.close() + // Note that the output pipe must be opened after the input pipe is consumed. + // Otherwise, there might be a deadlock that + // - The shell script is stuck writing to the input pipe (which has a full buffer), + // and doesn't open the write end of the output pipe. + // - This thread is stuck waiting for the write end of the output pipe to be opened. val fsout = Files.newOutputStream(outputPipe) fsout.write(response) fsout.close() diff --git a/bridge/src/test/scala/protocbridge/frontend/OsSpecificFrontendSpec.scala b/bridge/src/test/scala/protocbridge/frontend/OsSpecificFrontendSpec.scala index 5b158ac..1519857 100644 --- a/bridge/src/test/scala/protocbridge/frontend/OsSpecificFrontendSpec.scala +++ b/bridge/src/test/scala/protocbridge/frontend/OsSpecificFrontendSpec.scala @@ -10,20 +10,14 @@ import scala.util.Random class OsSpecificFrontendSpec extends AnyFlatSpec with Matchers { - protected def testPluginFrontend(frontend: PluginFrontend): Array[Byte] = { - val random = new Random() - val toSend = Array.fill(123)(random.nextInt(256).toByte) - val toReceive = Array.fill(456)(random.nextInt(256).toByte) - val env = new ExtraEnv(secondaryOutputDir = "tmp") - - val fakeGenerator = new ProtocCodeGenerator { - override def run(request: Array[Byte]): Array[Byte] = { - request mustBe (toSend ++ env.toByteArrayAsField) - toReceive - } - } + protected def testPluginFrontend( + frontend: PluginFrontend, + generator: ProtocCodeGenerator, + env: ExtraEnv, + request: Array[Byte] + ): Array[Byte] = { val (path, state) = frontend.prepare( - fakeGenerator, + generator, env ) val actualOutput = new ByteArrayOutputStream() @@ -32,7 +26,7 @@ class OsSpecificFrontendSpec extends AnyFlatSpec with Matchers { .run( new ProcessIO( writeInput => { - writeInput.write(toSend) + writeInput.write(request) writeInput.close() }, processOutput => { @@ -53,4 +47,34 @@ class OsSpecificFrontendSpec extends AnyFlatSpec with Matchers { frontend.cleanup(state) actualOutput.toByteArray } + + protected def testSuccess(frontend: PluginFrontend): Unit = { + val random = new Random() + val toSend = Array.fill(123)(random.nextInt(256).toByte) + val toReceive = Array.fill(456)(random.nextInt(256).toByte) + val env = new ExtraEnv(secondaryOutputDir = "tmp") + + val fakeGenerator = new ProtocCodeGenerator { + override def run(request: Array[Byte]): Array[Byte] = { + request mustBe (toSend ++ env.toByteArrayAsField) + toReceive + } + } + val response = testPluginFrontend(frontend, fakeGenerator, env, toSend) + response mustBe toReceive + } + + protected def testFailure(frontend: PluginFrontend): Unit = { + val random = new Random() + val toSend = Array.fill(123)(random.nextInt(256).toByte) + val env = new ExtraEnv(secondaryOutputDir = "tmp") + + val fakeGenerator = new ProtocCodeGenerator { + override def run(request: Array[Byte]): Array[Byte] = { + throw new OutOfMemoryError("test error") + } + } + val response = testPluginFrontend(frontend, fakeGenerator, env, toSend) + response.length must be > 0 + } } diff --git a/bridge/src/test/scala/protocbridge/frontend/PosixPluginFrontendSpec.scala b/bridge/src/test/scala/protocbridge/frontend/PosixPluginFrontendSpec.scala index 0d6d76a..2a3481c 100644 --- a/bridge/src/test/scala/protocbridge/frontend/PosixPluginFrontendSpec.scala +++ b/bridge/src/test/scala/protocbridge/frontend/PosixPluginFrontendSpec.scala @@ -3,7 +3,11 @@ package protocbridge.frontend class PosixPluginFrontendSpec extends OsSpecificFrontendSpec { if (!PluginFrontend.isWindows) { it must "execute a program that forwards input and output to given stream" in { - testPluginFrontend(PosixPluginFrontend) + testSuccess(PosixPluginFrontend) + } + + it must "not hang if there is an OOM in generator" in { + testFailure(PosixPluginFrontend) } } } diff --git a/bridge/src/test/scala/protocbridge/frontend/WindowsPluginFrontendSpec.scala b/bridge/src/test/scala/protocbridge/frontend/WindowsPluginFrontendSpec.scala index 7936141..4bf39de 100644 --- a/bridge/src/test/scala/protocbridge/frontend/WindowsPluginFrontendSpec.scala +++ b/bridge/src/test/scala/protocbridge/frontend/WindowsPluginFrontendSpec.scala @@ -3,7 +3,11 @@ package protocbridge.frontend class WindowsPluginFrontendSpec extends OsSpecificFrontendSpec { if (PluginFrontend.isWindows) { it must "execute a program that forwards input and output to given stream" in { - testPluginFrontend(WindowsPluginFrontend) + testSuccess(WindowsPluginFrontend) + } + + it must "not hang if there is an OOM in generator" in { + testFailure(WindowsPluginFrontend) } } } From 0ba6fcfe9eb75875e4c55497468916745667e268 Mon Sep 17 00:00:00 2001 From: Bell Le Date: Fri, 16 Aug 2024 16:55:52 -0700 Subject: [PATCH 3/3] Switch PluginFrontend to sockets on macOS --- .../frontend/MacPluginFrontend.scala | 36 +++++++++++++ .../frontend/PluginFrontend.scala | 5 ++ .../frontend/PosixPluginFrontend.scala | 7 ++- .../frontend/SocketBasedPluginFrontend.scala | 51 +++++++++++++++++++ .../frontend/WindowsPluginFrontend.scala | 46 ++--------------- .../frontend/MacPluginFrontendSpec.scala | 15 ++++++ .../frontend/OsSpecificFrontendSpec.scala | 20 +++++--- .../frontend/PosixPluginFrontendSpec.scala | 2 +- .../frontend/WindowsPluginFrontendSpec.scala | 6 ++- 9 files changed, 135 insertions(+), 53 deletions(-) create mode 100644 bridge/src/main/scala/protocbridge/frontend/MacPluginFrontend.scala create mode 100644 bridge/src/main/scala/protocbridge/frontend/SocketBasedPluginFrontend.scala create mode 100644 bridge/src/test/scala/protocbridge/frontend/MacPluginFrontendSpec.scala diff --git a/bridge/src/main/scala/protocbridge/frontend/MacPluginFrontend.scala b/bridge/src/main/scala/protocbridge/frontend/MacPluginFrontend.scala new file mode 100644 index 0000000..6f33cf8 --- /dev/null +++ b/bridge/src/main/scala/protocbridge/frontend/MacPluginFrontend.scala @@ -0,0 +1,36 @@ +package protocbridge.frontend + +import java.nio.file.attribute.PosixFilePermission +import java.nio.file.{Files, Path} +import java.{util => ju} + +/** PluginFrontend for macOS. + * + * Creates a server socket and uses `nc` to communicate with the socket. We use + * a server socket instead of named pipes because named pipes are unreliable on + * macOS: https://github.com/scalapb/protoc-bridge/issues/366. Since `nc` is + * widely available on macOS, this is the simplest and most reliable solution + * for macOS. + */ +object MacPluginFrontend extends SocketBasedPluginFrontend { + + protected def createShellScript(port: Int): Path = { + val shell = sys.env.getOrElse("PROTOCBRIDGE_SHELL", "/bin/sh") + // We use 127.0.0.1 instead of localhost for the (very unlikely) case that localhost is missing from /etc/hosts. + val scriptName = PluginFrontend.createTempFile( + "", + s"""|#!$shell + |set -e + |nc 127.0.0.1 $port + """.stripMargin + ) + val perms = new ju.HashSet[PosixFilePermission] + perms.add(PosixFilePermission.OWNER_EXECUTE) + perms.add(PosixFilePermission.OWNER_READ) + Files.setPosixFilePermissions( + scriptName, + perms + ) + scriptName + } +} diff --git a/bridge/src/main/scala/protocbridge/frontend/PluginFrontend.scala b/bridge/src/main/scala/protocbridge/frontend/PluginFrontend.scala index ec7d6ca..3b83cfa 100644 --- a/bridge/src/main/scala/protocbridge/frontend/PluginFrontend.scala +++ b/bridge/src/main/scala/protocbridge/frontend/PluginFrontend.scala @@ -131,8 +131,13 @@ object PluginFrontend { def isWindows: Boolean = sys.props("os.name").startsWith("Windows") + def isMac: Boolean = sys.props("os.name").startsWith("Mac") || sys + .props("os.name") + .startsWith("Darwin") + def newInstance: PluginFrontend = { if (isWindows) WindowsPluginFrontend + else if (isMac) MacPluginFrontend else PosixPluginFrontend } } diff --git a/bridge/src/main/scala/protocbridge/frontend/PosixPluginFrontend.scala b/bridge/src/main/scala/protocbridge/frontend/PosixPluginFrontend.scala index ef57687..65935e0 100644 --- a/bridge/src/main/scala/protocbridge/frontend/PosixPluginFrontend.scala +++ b/bridge/src/main/scala/protocbridge/frontend/PosixPluginFrontend.scala @@ -12,10 +12,13 @@ import scala.concurrent.ExecutionContext.Implicits.global import scala.sys.process._ import java.{util => ju} -/** PluginFrontend for Unix-like systems (Linux, Mac, etc) +/** PluginFrontend for Unix-like systems except macOS (Linux, FreeBSD, + * etc) * * Creates a pair of named pipes for input/output and a shell script that - * communicates with them. + * communicates with them. Compared with `SocketBasedPluginFrontend`, this + * frontend doesn't rely on `nc` that might not be available in some + * distributions. */ object PosixPluginFrontend extends PluginFrontend { case class InternalState( diff --git a/bridge/src/main/scala/protocbridge/frontend/SocketBasedPluginFrontend.scala b/bridge/src/main/scala/protocbridge/frontend/SocketBasedPluginFrontend.scala new file mode 100644 index 0000000..6d1dd59 --- /dev/null +++ b/bridge/src/main/scala/protocbridge/frontend/SocketBasedPluginFrontend.scala @@ -0,0 +1,51 @@ +package protocbridge.frontend + +import protocbridge.{ExtraEnv, ProtocCodeGenerator} + +import java.net.ServerSocket +import java.nio.file.{Files, Path} +import scala.concurrent.ExecutionContext.Implicits.global +import scala.concurrent.{Future, blocking} + +/** PluginFrontend for Windows and macOS where a server socket is used. + */ +abstract class SocketBasedPluginFrontend extends PluginFrontend { + case class InternalState(serverSocket: ServerSocket, shellScript: Path) + + override def prepare( + plugin: ProtocCodeGenerator, + env: ExtraEnv + ): (Path, InternalState) = { + val ss = new ServerSocket(0) // Bind to any available port. + val sh = createShellScript(ss.getLocalPort) + + Future { + blocking { + // Accept a single client connection from the shell script. + val client = ss.accept() + try { + val response = + PluginFrontend.runWithInputStream( + plugin, + client.getInputStream, + env + ) + client.getOutputStream.write(response) + } finally { + client.close() + } + } + } + + (sh, InternalState(ss, sh)) + } + + override def cleanup(state: InternalState): Unit = { + state.serverSocket.close() + if (sys.props.get("protocbridge.debug") != Some("1")) { + Files.delete(state.shellScript) + } + } + + protected def createShellScript(port: Int): Path +} diff --git a/bridge/src/main/scala/protocbridge/frontend/WindowsPluginFrontend.scala b/bridge/src/main/scala/protocbridge/frontend/WindowsPluginFrontend.scala index 490211d..adf9486 100644 --- a/bridge/src/main/scala/protocbridge/frontend/WindowsPluginFrontend.scala +++ b/bridge/src/main/scala/protocbridge/frontend/WindowsPluginFrontend.scala @@ -1,53 +1,15 @@ package protocbridge.frontend -import java.net.ServerSocket -import java.nio.file.{Files, Path, Paths} - -import protocbridge.ExtraEnv -import protocbridge.ProtocCodeGenerator - -import scala.concurrent.blocking - -import scala.concurrent.ExecutionContext.Implicits.global -import scala.concurrent.Future +import java.nio.file.{Path, Paths} /** A PluginFrontend that binds a server socket to a local interface. The plugin * is a batch script that invokes BridgeApp.main() method, in a new JVM with * the same parameters as the currently running JVM. The plugin will * communicate its stdin and stdout to this socket. */ -object WindowsPluginFrontend extends PluginFrontend { - - case class InternalState(batFile: Path) - - override def prepare( - plugin: ProtocCodeGenerator, - env: ExtraEnv - ): (Path, InternalState) = { - val ss = new ServerSocket(0) - val state = createWindowsScript(ss.getLocalPort) - - Future { - blocking { - val client = ss.accept() - val response = - PluginFrontend.runWithInputStream(plugin, client.getInputStream, env) - client.getOutputStream.write(response) - client.close() - ss.close() - } - } - - (state.batFile, state) - } - - override def cleanup(state: InternalState): Unit = { - if (sys.props.get("protocbridge.debug") != Some("1")) { - Files.delete(state.batFile) - } - } +object WindowsPluginFrontend extends SocketBasedPluginFrontend { - private def createWindowsScript(port: Int): InternalState = { + protected def createShellScript(port: Int): Path = { val classPath = Paths.get(getClass.getProtectionDomain.getCodeSource.getLocation.toURI) val classPathBatchString = classPath.toString.replace("%", "%%") @@ -62,6 +24,6 @@ object WindowsPluginFrontend extends PluginFrontend { ].getName} $port """.stripMargin ) - InternalState(batchFile) + batchFile } } diff --git a/bridge/src/test/scala/protocbridge/frontend/MacPluginFrontendSpec.scala b/bridge/src/test/scala/protocbridge/frontend/MacPluginFrontendSpec.scala new file mode 100644 index 0000000..6e8b972 --- /dev/null +++ b/bridge/src/test/scala/protocbridge/frontend/MacPluginFrontendSpec.scala @@ -0,0 +1,15 @@ +package protocbridge.frontend + +class MacPluginFrontendSpec extends OsSpecificFrontendSpec { + if (PluginFrontend.isMac) { + it must "execute a program that forwards input and output to given stream" in { + val state = testSuccess(MacPluginFrontend) + state.serverSocket.isClosed mustBe true + } + + it must "not hang if there is an error in generator" in { + val state = testFailure(MacPluginFrontend) + state.serverSocket.isClosed mustBe true + } + } +} diff --git a/bridge/src/test/scala/protocbridge/frontend/OsSpecificFrontendSpec.scala b/bridge/src/test/scala/protocbridge/frontend/OsSpecificFrontendSpec.scala index 1519857..619d1a8 100644 --- a/bridge/src/test/scala/protocbridge/frontend/OsSpecificFrontendSpec.scala +++ b/bridge/src/test/scala/protocbridge/frontend/OsSpecificFrontendSpec.scala @@ -15,7 +15,7 @@ class OsSpecificFrontendSpec extends AnyFlatSpec with Matchers { generator: ProtocCodeGenerator, env: ExtraEnv, request: Array[Byte] - ): Array[Byte] = { + ): (frontend.InternalState, Array[Byte]) = { val (path, state) = frontend.prepare( generator, env @@ -45,10 +45,12 @@ class OsSpecificFrontendSpec extends AnyFlatSpec with Matchers { ) process.exitValue() frontend.cleanup(state) - actualOutput.toByteArray + (state, actualOutput.toByteArray) } - protected def testSuccess(frontend: PluginFrontend): Unit = { + protected def testSuccess( + frontend: PluginFrontend + ): frontend.InternalState = { val random = new Random() val toSend = Array.fill(123)(random.nextInt(256).toByte) val toReceive = Array.fill(456)(random.nextInt(256).toByte) @@ -60,11 +62,15 @@ class OsSpecificFrontendSpec extends AnyFlatSpec with Matchers { toReceive } } - val response = testPluginFrontend(frontend, fakeGenerator, env, toSend) + val (state, response) = + testPluginFrontend(frontend, fakeGenerator, env, toSend) response mustBe toReceive + state } - protected def testFailure(frontend: PluginFrontend): Unit = { + protected def testFailure( + frontend: PluginFrontend + ): frontend.InternalState = { val random = new Random() val toSend = Array.fill(123)(random.nextInt(256).toByte) val env = new ExtraEnv(secondaryOutputDir = "tmp") @@ -74,7 +80,9 @@ class OsSpecificFrontendSpec extends AnyFlatSpec with Matchers { throw new OutOfMemoryError("test error") } } - val response = testPluginFrontend(frontend, fakeGenerator, env, toSend) + val (state, response) = + testPluginFrontend(frontend, fakeGenerator, env, toSend) response.length must be > 0 + state } } diff --git a/bridge/src/test/scala/protocbridge/frontend/PosixPluginFrontendSpec.scala b/bridge/src/test/scala/protocbridge/frontend/PosixPluginFrontendSpec.scala index 2a3481c..4a6dd99 100644 --- a/bridge/src/test/scala/protocbridge/frontend/PosixPluginFrontendSpec.scala +++ b/bridge/src/test/scala/protocbridge/frontend/PosixPluginFrontendSpec.scala @@ -1,7 +1,7 @@ package protocbridge.frontend class PosixPluginFrontendSpec extends OsSpecificFrontendSpec { - if (!PluginFrontend.isWindows) { + if (!PluginFrontend.isWindows && !PluginFrontend.isMac) { it must "execute a program that forwards input and output to given stream" in { testSuccess(PosixPluginFrontend) } diff --git a/bridge/src/test/scala/protocbridge/frontend/WindowsPluginFrontendSpec.scala b/bridge/src/test/scala/protocbridge/frontend/WindowsPluginFrontendSpec.scala index 4bf39de..db0bc65 100644 --- a/bridge/src/test/scala/protocbridge/frontend/WindowsPluginFrontendSpec.scala +++ b/bridge/src/test/scala/protocbridge/frontend/WindowsPluginFrontendSpec.scala @@ -3,11 +3,13 @@ package protocbridge.frontend class WindowsPluginFrontendSpec extends OsSpecificFrontendSpec { if (PluginFrontend.isWindows) { it must "execute a program that forwards input and output to given stream" in { - testSuccess(WindowsPluginFrontend) + val state = testSuccess(WindowsPluginFrontend) + state.serverSocket.isClosed mustBe true } it must "not hang if there is an OOM in generator" in { - testFailure(WindowsPluginFrontend) + val state = testFailure(WindowsPluginFrontend) + state.serverSocket.isClosed mustBe true } } }