packages feed

tmp-postgres 1.13.1.2 → 1.14.0.0

raw patch · 5 files changed

+64/−12 lines, 5 files

Files

CHANGELOG.md view
@@ -48,3 +48,7 @@  1.13.1.2   #124 Respect database name in withNewDbConfig++1.14.0.0+  #126 Check for an empty data directory to give a better error message+  #114 Silent postgresql.conf
src/Database/Postgres/Temp/Internal.hs view
@@ -220,14 +220,44 @@     }   } --- | The same as 'defaultConfig' but all the handles are set to @/dev/null@.---   See 'silentProcessConfig' as well.------   @since 1.12.0.0++--   @since 1.14.0.0+silentPostgresConfig :: [String]+silentPostgresConfig =+  [ "shared_buffers = 12MB"+  , "fsync = off"+  , "synchronous_commit = off"+  , "full_page_writes = off"+  , "log_min_messages = PANIC"+  , "log_min_error_statement = PANIC"+  , "log_statement = none"+  , "client_min_messages = ERROR"+  ]++{-|+The similar to 'defaultConfig' but all the handles are set to @/dev/null@.+and uses a @postgresql.conf@ which disables logging:++ @+   shared_buffers = 12MB+   fsync = off+   synchronous_commit = off+   full_page_writes = off+   log_min_messages = PANIC+   log_min_error_statement = PANIC+   log_statement = none+   client_min_messages = ERROR+ @++See 'silentProcessConfig' as well.++@since 1.14.0.0+-} silentConfig :: Config silentConfig = defaultConfig <> mempty   { plan = mempty-    { initDbConfig = pure silentProcessConfig+    { postgresConfigFile = silentPostgresConfig+    , initDbConfig = pure silentProcessConfig     , postgresPlan = mempty         { postgresConfig = silentProcessConfig         }
src/Database/Postgres/Temp/Internal/Core.hs view
@@ -9,7 +9,7 @@ import           Control.Concurrent (threadDelay) import           Control.Concurrent.Async (race_, withAsync) import           Control.Exception-import           Control.Monad (forever, (>=>))+import           Control.Monad (forever, (>=>), unless) import qualified Data.ByteString.Char8 as BSC import           Data.Foldable (for_) import           Data.IORef@@ -18,6 +18,7 @@ import           Data.Typeable import qualified Database.PostgreSQL.Simple as PG import qualified Database.PostgreSQL.Simple.Options as Client+import           System.Directory import           System.Exit (ExitCode(..)) import           System.IO import           System.Posix.Signals (sigQUIT, signalProcess)@@ -77,6 +78,9 @@   | ConnectionTimedOut   -- ^ Timed out waiting for @postgres@ to accept a connection   | DeleteDbError PG.SqlError+  | EmptyDataDirectory+  -- ^ This will happen if a 'Database.Postgres.Temp.Config.Plan' is missing a+  --   'initDbConfig'.   deriving (Show, Eq, Typeable)  instance Exception StartError@@ -349,6 +353,11 @@   completePlanLogger $ StartPlan $ show $ pretty plan   for_ completePlanInitDb $ executeProcessAndTee "initdb" >=>     \(res, stdOut, stdErr) -> throwIfNotSuccess (InitDbFailed stdOut stdErr) res++  -- Try to give a better error if @initdb@ was not+  -- configured to run.+  versionFileExists <- doesFileExist $ completePlanDataDirectory <> "/PG_VERSION"+  unless versionFileExists $ throwIO EmptyDataDirectory    -- We must provide a config file before we can start postgres.   writeFile (completePlanDataDirectory <> "/postgresql.conf") completePlanConfig
test/Main.hs view
@@ -1,6 +1,6 @@ import           Control.Concurrent import           Control.Exception-import           Control.Monad ((<=<), void)+import           Control.Monad ((<=<), void, unless) import           Data.Function import qualified Data.Map.Strict as Map import           Data.Monoid@@ -35,10 +35,19 @@ withNewDbConfig' config db = either throwIO pure <=<   withNewDbConfig config db ++countPostgresProcesses :: IO Int+countPostgresProcesses = do+  -- TODO we should restrict to child process+  (exitCode, xs, _) <-  readProcessWithExitCode "pgrep" ["postgres"] []++  unless (exitCode == ExitSuccess || exitCode == ExitFailure 1) $ throwIO exitCode++  pure $ length $ lines xs+ testSuccessfulConfigNoTmp :: ConfigAndAssertion -> IO () testSuccessfulConfigNoTmp ConfigAndAssertion {..} = do-  -- ensure the count of postgres processes that are child processes before is 0-  -- for each exception location+  initialPostgresCount <- countPostgresProcesses   withConfig' cConfig $ \db -> do     cAssert db     -- check for a valid connection@@ -47,7 +56,7 @@      one `shouldBe` (1 :: Int) -  -- ensure the count of postgres processes that are child processes after is 0+  countPostgresProcesses `shouldReturn` initialPostgresCount  testSuccessfulConfig :: ConfigAndAssertion -> IO () testSuccessfulConfig configAssert = do@@ -389,7 +398,7 @@           }      withConfig dontTimeout (const $ pure ())-      `shouldReturn` Left (StartPostgresFailed $ ExitFailure 1)+      `shouldReturn` Left EmptyDataDirectory    it "initdb with non-empty data directory fails with InitDbFailed" $     withTempDirectory "/tmp" "tmp-postgres-test" $ \dirPath -> do
tmp-postgres.cabal view
@@ -1,5 +1,5 @@ name:                tmp-postgres-version:             1.13.1.2+version:             1.14.0.0 synopsis: Start and stop a temporary postgres description: Start and stop a temporary postgres. See README.md homepage:            https://github.com/jfischoff/tmp-postgres#readme