ephemeral-pg 0.2.0.1 → 0.2.1.0
raw patch · 5 files changed
+44/−15 lines, 5 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
+ EphemeralPg.Database: [shutdownMode] :: Database -> ShutdownMode
+ EphemeralPg.Database: [shutdownTimeoutSeconds] :: Database -> Int
- EphemeralPg: Database :: FilePath -> FilePath -> Word16 -> Text -> Text -> Maybe Text -> PostgresProcess -> IO () -> Bool -> Bool -> Database
+ EphemeralPg: Database :: FilePath -> FilePath -> Word16 -> Text -> Text -> Maybe Text -> PostgresProcess -> IO () -> Bool -> Bool -> ShutdownMode -> Int -> Database
- EphemeralPg.Database: Database :: FilePath -> FilePath -> Word16 -> Text -> Text -> Maybe Text -> PostgresProcess -> IO () -> Bool -> Bool -> Database
+ EphemeralPg.Database: Database :: FilePath -> FilePath -> Word16 -> Text -> Text -> Maybe Text -> PostgresProcess -> IO () -> Bool -> Bool -> ShutdownMode -> Int -> Database
Files
- CHANGELOG.md +13/−0
- ephemeral-pg.cabal +1/−1
- src/EphemeralPg.hs +22/−11
- src/EphemeralPg/Config.hs +2/−2
- src/EphemeralPg/Database.hs +6/−1
CHANGELOG.md view
@@ -1,5 +1,18 @@ # Changelog +## 0.2.1.0++### Bug Fixes++- Fix `stop` and `restart` ignoring configured shutdown mode and timeout — they+ were hardcoding `ShutdownGraceful` with a 30-second timeout instead of using+ the config values, causing `with`/`withCached` to block unnecessarily on shutdown++### Other Changes++- Change default shutdown mode to `ShutdownFast` (SIGINT) with a 5-second+ timeout, which is more appropriate for a testing library+ ## 0.2.0.1 ### Bug Fixes
ephemeral-pg.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: ephemeral-pg-version: 0.2.0.1+version: 0.2.1.0 synopsis: Temporary PostgreSQL databases for testing description: A modern library for creating temporary PostgreSQL instances for testing.
src/EphemeralPg.hs view
@@ -233,7 +233,9 @@ process = pgProcess, cleanup = cleanupAction, dataDirIsTemp = dataDirIsTemp,- socketDirIsTemp = socketDirIsTemp+ socketDirIsTemp = socketDirIsTemp,+ shutdownMode = resolveShutdownMode config,+ shutdownTimeoutSeconds = resolveShutdownTimeout config } where cleanup :: Bool -> FilePath -> Bool -> FilePath -> IO ()@@ -253,19 +255,26 @@ "" -> getCurrentUser u -> pure u +-- | Resolve shutdown mode from config, falling back to default.+resolveShutdownMode :: Config -> ShutdownMode+resolveShutdownMode config =+ maybe ShutdownGraceful id $ getLast config.shutdownMode++-- | Resolve shutdown timeout from config, falling back to default.+resolveShutdownTimeout :: Config -> Int+resolveShutdownTimeout config =+ maybe defaultShutdownTimeoutSeconds id $ getLast config.shutdownTimeoutSeconds+ -- | Stop a database and clean up resources. ----- This sends SIGTERM to postgres and waits for graceful shutdown,--- then removes temporary directories.+-- Uses the shutdown mode and timeout from the configuration that was+-- used to start the database. -- -- Safe to call multiple times (subsequent calls are no-ops). stop :: Database -> IO () stop db = do- let mode = ShutdownGraceful- let timeoutSecs = defaultShutdownTimeoutSeconds-- -- Stop postgres- _ <- stopPostgres db.process mode timeoutSecs+ -- Stop postgres using configured shutdown mode and timeout+ _ <- stopPostgres db.process db.shutdownMode db.shutdownTimeoutSeconds -- Run cleanup (removes temp directories) db.cleanup@@ -292,9 +301,9 @@ -- @ restart :: Database -> IO (Either StartError Database) restart db = runStartup $ do- -- Stop postgres gracefully+ -- Stop postgres using configured shutdown settings liftIO $ do- _ <- stopPostgres db.process ShutdownGraceful defaultShutdownTimeoutSeconds+ _ <- stopPostgres db.process db.shutdownMode db.shutdownTimeoutSeconds pure () -- Start postgres again with the same configuration@@ -455,7 +464,9 @@ process = pgProcess, cleanup = cleanupAction, dataDirIsTemp = dataDirIsTemp,- socketDirIsTemp = socketDirIsTemp+ socketDirIsTemp = socketDirIsTemp,+ shutdownMode = resolveShutdownMode config,+ shutdownTimeoutSeconds = resolveShutdownTimeout config } where cleanupDirs :: Bool -> FilePath -> Bool -> FilePath -> IO ()
src/EphemeralPg/Config.hs view
@@ -163,7 +163,7 @@ -- | Default shutdown timeout in seconds. defaultShutdownTimeoutSeconds :: Int-defaultShutdownTimeoutSeconds = 30+defaultShutdownTimeoutSeconds = 5 -- | Default PostgreSQL settings optimized for testing. --@@ -221,7 +221,7 @@ createDbArgs = [], connectionTimeoutSeconds = Last (Just defaultConnectionTimeoutSeconds), shutdownTimeoutSeconds = Last (Just defaultShutdownTimeoutSeconds),- shutdownMode = Last (Just ShutdownGraceful),+ shutdownMode = Last (Just ShutdownFast), stdout = Last (Just Nothing), -- Discard by default stderr = Last (Just Nothing) -- Discard by default }
src/EphemeralPg/Database.hs view
@@ -16,6 +16,7 @@ import Data.Text (Text) import Data.Text qualified as T import Data.Word (Word16)+import EphemeralPg.Config (ShutdownMode (..)) import Hasql.Connection.Settings qualified as Settings import System.Posix.Types (CPid) import System.Process.Typed (Process)@@ -56,7 +57,11 @@ -- | Whether data directory is temporary dataDirIsTemp :: Bool, -- | Whether socket directory is temporary- socketDirIsTemp :: Bool+ socketDirIsTemp :: Bool,+ -- | How to shut down postgres (from config)+ shutdownMode :: ShutdownMode,+ -- | Timeout for shutdown in seconds (from config)+ shutdownTimeoutSeconds :: Int } instance Show Database where