orville-postgresql 1.1.0.0 → 1.1.1.0
raw patch · 3 files changed
+77/−6 lines, 3 filesdep ~resource-poolPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: resource-pool
API changes (from Hackage documentation)
+ Orville.PostgreSQL.Raw.Connection: destroyIdleConnections :: ConnectionPool -> IO ()
Files
- orville-postgresql.cabal +3/−3
- src/Orville/PostgreSQL/Raw/Connection.hs +19/−2
- test/Test/Connection.hs +55/−1
orville-postgresql.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack name: orville-postgresql-version: 1.1.0.0+version: 1.1.1.0 synopsis: A Haskell library for PostgreSQL description: Orville's goal is to provide a powerful API for applications to access PostgreSQL databases with minimal use of sophisticated language techniques or extensions. See https://github.com/flipstone/orville for more details. category: database, library, postgresql@@ -184,7 +184,7 @@ , network-uri ==2.6.* , postgresql-libpq >=0.9.4.2 && <0.12 , random >=1.0 && <2- , resource-pool <0.3 || >=0.4 && <0.6+ , resource-pool >=0.2.2.0 && <0.3 || >=0.4 && <0.6 , safe-exceptions >=0.1.7 && <0.2 , text >=1.2 && <1.3 || >=2.0 && <2.2 , time >=1.9.1 && <1.16@@ -267,7 +267,7 @@ , hedgehog >=1.0.5 && <1.7 , orville-postgresql , postgresql-libpq >=0.9.4.2 && <0.12- , resource-pool <0.3 || >=0.4 && <0.6+ , resource-pool >=0.2.2.0 && <0.3 || >=0.4 && <0.6 , safe-exceptions >=0.1.7 && <0.2 , text >=1.2 && <1.3 || >=2.0 && <2.2 , time >=1.9.1 && <1.16
src/Orville/PostgreSQL/Raw/Connection.hs view
@@ -22,6 +22,7 @@ , StripeOption (OneStripePerCapability, StripeCount) , ConnectionPool , createConnectionPool+ , destroyIdleConnections , Connection , withPoolConnection , executeRaw@@ -44,9 +45,9 @@ import Data.IORef (IORef, newIORef, readIORef, writeIORef) import Data.Maybe (fromMaybe) #if MIN_VERSION_resource_pool(0,4,0)-import Data.Pool (Pool, newPool, defaultPoolConfig, setNumStripes, withResource)+import Data.Pool (Pool, newPool, defaultPoolConfig, setNumStripes, withResource, destroyAllResources) #else-import Data.Pool (Pool, createPool, withResource)+import Data.Pool (Pool, createPool, withResource, destroyAllResources) #endif import qualified Data.Text as T import qualified Data.Text.Encoding as Enc@@ -119,6 +120,22 @@ linger connPerStripe #endif++{- | Destroy (close) connections currently in the connection pool, proactively+freeing the associated resources and returning the pool to an empty state. This+can be useful when it is known that all connections have become invalid or are+no longer needed.++Connections in use, such as in 'withPoolConnection', are not considered /in/ the+pool and will not be immediately affected by 'destroyIdleConnections'.++Any exceptions thrown by the destroy function are ignored.++@since 1.1.1.0+-}+destroyIdleConnections :: ConnectionPool -> IO ()+destroyIdleConnections (ConnectionPool pool) =+ destroyAllResources pool {- | Values for the 'connectionPoolStripes' field of 'ConnectionOptions'.
test/Test/Connection.hs view
@@ -28,6 +28,8 @@ , prop_truncateValuesAtUnsafeNulByte pool , prop_errorOnInvalidSql pool , prop_returningAConnectionToPoolWithOpenTransactionCausesException pool+ , prop_acquiredConnectionNotDestroyed pool+ , prop_poolUsableAfterDestroyingConnections pool ] prop_safeOrUnsafeNonNullBytes :: Property.NamedDBProperty@@ -137,7 +139,7 @@ Conn.sqlExecutionErrorSqlState err === Just syntaxErrorState Right _ -> do- HH.footnote "Expected 'executeRow' to return failure, but it did not"+ HH.footnote "Expected 'executeRaw' to return failure, but it did not" HH.failure prop_returningAConnectionToPoolWithOpenTransactionCausesException :: Property.NamedDBProperty@@ -156,3 +158,55 @@ Right _ -> do HH.footnote "Expected 'withPoolConnection' to return failure, but it did not" HH.failure++prop_acquiredConnectionNotDestroyed :: Property.NamedDBProperty+prop_acquiredConnectionNotDestroyed =+ Property.namedDBProperty "destroying idle connections in the pool does not affect connections already acquired" $ \pool -> do+ textBytes <- fmap Enc.encodeUtf8 . HH.forAll $ PgGen.pgText (Range.linear 0 256)++ value <-+ MIO.liftIO . Conn.withPoolConnection pool $ \connection -> do+ Conn.destroyIdleConnections pool+ result <-+ Conn.executeRaw+ connection+ (B8.pack "SELECT $1::text")+ [ Just $ PgTextFormatValue.fromByteString textBytes+ ]++ LibPQ.getvalue' result 0 0++ value === Just textBytes++prop_poolUsableAfterDestroyingConnections :: Property.NamedDBProperty+prop_poolUsableAfterDestroyingConnections =+ Property.namedDBProperty "the connection pool can be used after destroying idle connections" $ \pool -> do+ textBytes1 <- fmap Enc.encodeUtf8 . HH.forAll $ PgGen.pgText (Range.linear 0 256)+ textBytes2 <- fmap Enc.encodeUtf8 . HH.forAll $ PgGen.pgText (Range.linear 0 256)++ value1 <-+ MIO.liftIO . Conn.withPoolConnection pool $ \connection -> do+ result <-+ Conn.executeRaw+ connection+ (B8.pack "SELECT $1::text")+ [ Just $ PgTextFormatValue.fromByteString textBytes1+ ]++ LibPQ.getvalue' result 0 0++ MIO.liftIO $ Conn.destroyIdleConnections pool++ value2 <-+ MIO.liftIO . Conn.withPoolConnection pool $ \connection -> do+ result <-+ Conn.executeRaw+ connection+ (B8.pack "SELECT $1::text")+ [ Just $ PgTextFormatValue.fromByteString textBytes2+ ]++ LibPQ.getvalue' result 0 0++ value1 === Just textBytes1+ value2 === Just textBytes2