packages feed

postgres-embedded 0.1.1 → 0.1.2

raw patch · 2 files changed

+22/−20 lines, 2 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

postgres-embedded.cabal view
@@ -1,5 +1,5 @@ name:                postgres-embedded-version:             0.1.1+version:             0.1.2 description:         Library for easily running embedded PostgreSQL server for tests homepage:            https://github.com/ilya-murzinov/postgres-embedded license:             MIT
src/Database/PostgreSQL/Embedded/Postgres.hs view
@@ -6,29 +6,28 @@  import           Control.Concurrent                    (threadDelay) import           Control.Exception                     (SomeException, try)-import           Data.Conduit.Shell                    (rm, run, shell)+import           Data.Conduit.Shell                    (grep, rm, run, shell,+                                                        ($|))+import           Data.Conduit.Shell.Segments           (strings) import           Data.List                             (isInfixOf) import           Data.Monoid                           ((<>))-import           Network                               (PortID (..), connectTo) import           System.FilePath.Posix                 ((</>)) import           System.Info                           (os)-import           System.IO                             (Handle) -- import           Database.PostgreSQL.Embedded.Download import           Database.PostgreSQL.Embedded.Types  startPostgres :: StartupConfig -> DBConfig -> IO RuntimeConfig-startPostgres (StartupConfig version_ t) dConfig@(DBConfig p u) = do+startPostgres (StartupConfig version_ t) (DBConfig p u) = do     e <- downloadPostgres getOS version_     let d = e </> "data"     run $ do         shell $ e </> "bin" </> "initdb" <> " -A trust -U " <> u <> " -D " <> d <> " -E UTF-8"         shell $ e </> "bin" </> "pg_ctl" <> " -D " <> d <> " -o \"-F -p " <>             (show p) <> "\"" <> " -l " <> (e </> "log") <> " start"-    checkPostgresStarted dConfig t-    return $ RuntimeConfig e d+    let r = RuntimeConfig e d+    checkPostgresStarted r t+    return $ r     where         getOS | "darwin" `isInfixOf` os = OSX               | "linux" `isInfixOf` os = Linux@@ -40,19 +39,22 @@         shell $ e </> "bin" </> "pg_ctl" <> " -D " <> d <> " stop"         rm "-rf" d -checkPostgresStarted :: DBConfig -> Int -> IO ()+checkPostgresStarted :: RuntimeConfig -> Int -> IO () checkPostgresStarted config secs = checkPostgresStarted_ config secs >>= \_ -> return ()     where-        checkPostgresStarted_ :: DBConfig -> Int -> IO Bool-        checkPostgresStarted_ (DBConfig p _) n = do+        checkPostgresStarted_ :: RuntimeConfig -> Int -> IO Bool+        checkPostgresStarted_ (RuntimeConfig e d) n = do             let oneSec = 1000000+            let check = run $+                        strings (+                            shell (e </> "bin" </> "pg_ctl" <> " -D " <> d <> " status")+                            $| grep "running") >>= \s -> return $ null s -            res <- try $ connectTo "localhost" (PortNumber $ fromInteger p) :: IO (Either SomeException Handle)-            case res of-                Left e -> if (n > 0) then-                    print e >>=-                        \_ -> threadDelay oneSec >>=+            res <- try check :: IO (Either SomeException Bool)+            let retry = if n > 0 then threadDelay oneSec >>=                             \_ -> checkPostgresStarted_ config (n - 1)-                else-                    return False-                Right _ -> return True+                        else+                            return False+            case res of+                Left err   -> print err >>= \_ -> retry+                Right res1 -> if res1 then retry else return True