mirror of
https://github.com/digital-asset/daml.git
synced 2024-09-19 16:57:40 +03:00
sandbox: fail on already existing port-file. (#7929)
Fixes #7806. This aligns the port file behaviour of the sandbox with the HTTP JSON API. CHANGELOG_BEGIN CHANGELOG_END
This commit is contained in:
parent
9bf4ef9ba6
commit
5bfff4e9ba
@ -24,7 +24,7 @@ import System.Environment (getEnvironment)
|
||||
import System.Exit (exitFailure)
|
||||
import System.FilePath ((</>))
|
||||
import System.IO.Error (isDoesNotExistError)
|
||||
import System.IO.Extra (Handle, IOMode (..), hClose, newTempFile, openBinaryFile, stderr)
|
||||
import System.IO.Extra (Handle, IOMode (..), hClose, newTempDir, openBinaryFile, stderr)
|
||||
import System.Info.Extra (isWindows)
|
||||
import System.Process
|
||||
import Test.Tasty (TestTree, withResource)
|
||||
@ -113,9 +113,10 @@ createSandbox portFile sandboxOutput conf = do
|
||||
withSandbox :: IO SandboxConfig -> (IO Int -> TestTree) -> TestTree
|
||||
withSandbox getConf f =
|
||||
withResource (openBinaryFile nullDevice ReadWriteMode) hClose $ \getDevNull ->
|
||||
withResource newTempFile snd $ \getPortFile ->
|
||||
withResource newTempDir snd $ \getTempDir ->
|
||||
let createSandbox' = do
|
||||
(portFile, _) <- getPortFile
|
||||
(tempDir, _) <- getTempDir
|
||||
let portFile = tempDir </> "sandbox-portfile"
|
||||
devNull <- getDevNull
|
||||
conf <- getConf
|
||||
createSandbox portFile devNull conf
|
||||
|
@ -60,7 +60,9 @@ main = do
|
||||
-- pulling apart functions like `withGrpcClient`. Therefore we just
|
||||
-- allocate the resources before handing over to tasty and accept that
|
||||
-- it will spin up sandbox and the repl client.
|
||||
withTempFile $ \portFile ->
|
||||
withTempDir $ \tmpDir ->
|
||||
let portFile = tmpDir </> "sandbox-portfile"
|
||||
in
|
||||
withBinaryFile nullDevice WriteMode $ \devNull ->
|
||||
bracket (createSandbox portFile devNull defaultSandboxConf { dars = testDars }) destroySandbox $ \SandboxResource{sandboxPort} ->
|
||||
ReplClient.withReplClient (ReplClient.Options replJar (Just ("localhost", show sandboxPort)) Nothing Nothing Nothing Nothing ReplClient.ReplWallClock CreatePipe) $ \replHandle mbServiceOut processHandle ->
|
||||
|
@ -100,7 +100,8 @@ navigatorURL :: NavigatorPort -> String
|
||||
navigatorURL (NavigatorPort p) = "http://localhost:" <> show p
|
||||
|
||||
withSandbox :: SandboxClassic -> SandboxPortSpec -> [String] -> (Process () () () -> SandboxPort -> IO a) -> IO a
|
||||
withSandbox (SandboxClassic classic) portSpec extraArgs a = withTempFile $ \portFile -> do
|
||||
withSandbox (SandboxClassic classic) portSpec extraArgs a = withTempDir $ \tempDir -> do
|
||||
let portFile = tempDir </> "sandbox-portfile"
|
||||
let sandbox = if classic then "sandbox-classic" else "sandbox"
|
||||
let args = [ sandbox
|
||||
, "--port", show (fromSandboxPortSpec portSpec)
|
||||
|
@ -26,8 +26,9 @@ trait MultiParticipantFixture
|
||||
with AkkaBeforeAndAfterAll {
|
||||
self: Suite =>
|
||||
private def darFile = Paths.get(rlocation("daml-script/test/script-test.dar"))
|
||||
private val participant1Portfile = Files.createTempFile("participant1", "port")
|
||||
private val participant2Portfile = Files.createTempFile("participant2", "port")
|
||||
private val tmpDir = Files.createTempDirectory("testMultiParticipantFixture")
|
||||
private val participant1Portfile = tmpDir.resolve("participant1-portfile")
|
||||
private val participant2Portfile = tmpDir.resolve("participant2-portfile")
|
||||
|
||||
override protected def afterAll(): Unit = {
|
||||
Files.delete(participant1Portfile)
|
||||
|
@ -4,7 +4,6 @@
|
||||
package com.daml.platform.apiserver
|
||||
|
||||
import java.io.File
|
||||
import java.nio.file.Files
|
||||
import java.time.{Clock, Instant}
|
||||
|
||||
import akka.actor.ActorSystem
|
||||
@ -26,6 +25,7 @@ import com.daml.platform.configuration.{
|
||||
PartyConfiguration,
|
||||
ServerRole
|
||||
}
|
||||
import com.daml.ports.{PortFiles}
|
||||
import com.daml.platform.index.JdbcIndex
|
||||
import com.daml.platform.packages.InMemoryPackageStore
|
||||
import com.daml.platform.services.time.TimeProviderType
|
||||
@ -33,7 +33,6 @@ import com.daml.platform.store.dao.events.LfValueTranslation
|
||||
import com.daml.ports.Port
|
||||
import io.grpc.{BindableService, ServerInterceptor}
|
||||
|
||||
import scala.collection.JavaConverters._
|
||||
import scala.collection.immutable
|
||||
|
||||
// Main entry point to start an index server that also hosts the ledger API.
|
||||
@ -150,6 +149,6 @@ final class StandaloneApiServer(
|
||||
|
||||
private def writePortFile(port: Port): Unit =
|
||||
config.portFile.foreach { path =>
|
||||
Files.write(path, Seq(port.toString).asJava)
|
||||
PortFiles.write(path, port)
|
||||
}
|
||||
}
|
||||
|
@ -90,9 +90,10 @@ createSandbox portFile sandboxOutput conf = do
|
||||
|
||||
withSandbox :: SandboxConfig -> (IO Int -> TestTree) -> TestTree
|
||||
withSandbox conf f =
|
||||
withResource newTempFile snd $ \getPortFile ->
|
||||
withResource newTempDir snd $ \getTmpDir ->
|
||||
let createSandbox' = do
|
||||
(portFile, _) <- getPortFile
|
||||
(tempDir, _) <- getTmpDir
|
||||
let portFile = tempDir </> "sandbox-portfile"
|
||||
createSandbox portFile stdout conf
|
||||
in withResource createSandbox' destroySandbox (f . fmap sandboxPort)
|
||||
|
||||
|
@ -36,9 +36,10 @@ object PortFiles {
|
||||
}
|
||||
|
||||
private def writeUnsafe(path: Path, port: Port): Unit = {
|
||||
import java.nio.file.StandardOpenOption.CREATE_NEW
|
||||
val lines: java.lang.Iterable[String] = List(port.value.toString).asJava
|
||||
val created = Files.write(path, lines, CREATE_NEW)
|
||||
val tmpFile = Files.createTempFile("portfile", "")
|
||||
Files.write(tmpFile, lines)
|
||||
val created = Files.move(tmpFile, path)
|
||||
created.toFile.deleteOnExit()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user