diff options
Diffstat (limited to 'clientserver')
-rw-r--r-- | clientserver/src/mill/clientserver/Server.scala | 31 | ||||
-rw-r--r-- | clientserver/test/src/mill/clientserver/ClientServerTests.scala | 4 |
2 files changed, 22 insertions, 13 deletions
diff --git a/clientserver/src/mill/clientserver/Server.scala b/clientserver/src/mill/clientserver/Server.scala index 2b8ad39f..04ddbf0c 100644 --- a/clientserver/src/mill/clientserver/Server.scala +++ b/clientserver/src/mill/clientserver/Server.scala @@ -35,21 +35,26 @@ class Server[T](lockBase: String, def run() = { locks.processLock.tryLockBlock{ var running = true - while (running) locks.serverLock.lockBlock{ - new File(ioPath).delete() - val ioSocket = new UnixDomainServerSocket(ioPath) - val sockOpt = ClientServer.interruptWith( - acceptTimeout, - new UnixDomainSocket(ioPath).close(), - ioSocket.accept() - ) + while (running) { + locks.serverLock.lockBlock{ + new File(ioPath).delete() + val ioSocket = new UnixDomainServerSocket(ioPath) + val sockOpt = ClientServer.interruptWith( + acceptTimeout, + new UnixDomainSocket(ioPath).close(), + ioSocket.accept() + ) - sockOpt match{ - case None => running = false - case Some(sock) => - try handleRun(sock) - catch{case e: Throwable => e.printStackTrace(originalStdout) } + sockOpt match{ + case None => running = false + case Some(sock) => + try handleRun(sock) + catch{case e: Throwable => e.printStackTrace(originalStdout) } + } } + // Make sure you give an opportunity for the client to probe the lock + // and realize the server has released it to signal completion + Thread.sleep(10) } }.getOrElse(throw new Exception("PID already present")) } diff --git a/clientserver/test/src/mill/clientserver/ClientServerTests.scala b/clientserver/test/src/mill/clientserver/ClientServerTests.scala index f9f76f9a..a02e2733 100644 --- a/clientserver/test/src/mill/clientserver/ClientServerTests.scala +++ b/clientserver/test/src/mill/clientserver/ClientServerTests.scala @@ -82,6 +82,10 @@ object ClientServerTests extends TestSuite{ err1 == "HELLOworld\n" ) + // Give a bit of time for the server to release the lock and + // re-acquire it to signal to the client that it's done + Thread.sleep(100) + assert( locks.clientLock.probe(), !locks.serverLock.probe(), |