Skip to content

Commit

Permalink
adding more logging around Postgres fixture lifecycle (digital-asset#…
Browse files Browse the repository at this point in the history
  • Loading branch information
gabor-aranyossy authored and mergify[bot] committed Jun 18, 2019
1 parent 02e9503 commit a590b5c
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.digitalasset.daml.bazeltools.BazelRunfiles._
import com.digitalasset.ledger.api.testing.utils.Resource
import org.apache.commons.io.{FileUtils, IOUtils}
import org.scalatest.{BeforeAndAfterAll, BeforeAndAfterEach}
import org.slf4j.LoggerFactory

import scala.io.Source
import scala.util.control.NonFatal
Expand Down Expand Up @@ -75,6 +76,8 @@ object PostgresResource {

trait PostgresAround {

private val logger = LoggerFactory.getLogger(getClass)

private val IS_OS_WINDOWS: Boolean = sys.props("os.name").toLowerCase contains "windows"

protected val testUser = "test"
Expand All @@ -83,6 +86,7 @@ trait PostgresAround {
protected var postgresFixture: PostgresFixture = null

protected def startEphemeralPg(): PostgresFixture = {
logger.info("starting Postgres fixture")
val tempDir = Files.createTempDirectory("postgres_test")
val tempDirPath = tempDir.toAbsolutePath.toString
val dataDir = Paths.get(tempDirPath, "data")
Expand Down Expand Up @@ -169,11 +173,13 @@ trait PostgresAround {
}

private def waitForItOrDie(p: Process, what: String) = {
logger.info(s"waiting for '$what' to exit")
if (p.waitFor() != 0) {
val writer = new StringWriter
IOUtils.copy(p.getErrorStream, writer, "UTF-8")
sys.error(writer.toString)
}
logger.info(s"the process has been terminated")
}

private def deleteTempFolder(tempDir: Path) =
Expand All @@ -191,6 +197,7 @@ trait PostgresAround {
}

protected def stopAndCleanUp(tempDir: Path, dataDir: Path, logFile: Path): Unit = {
logger.info("stopping and cleaning up Postgres")
val command = Array(
pgToolPath("pg_ctl"),
"-w",
Expand Down

0 comments on commit a590b5c

Please sign in to comment.