-- | Coverage for 'Pqi.unsafeFreeResult': freeing a result leaves the
-- connection usable for subsequent commands.
--
-- An observation of a freed result must not be compared: with the C-backed
-- adapter the accessors share the @PGresult@'s storage, so freeing invalidates
-- previously returned bytes. The example therefore frees and then runs a fresh
-- query, observing only the latter.
module Pqi.Conformance.Operation.UnsafeFreeResult
  ( spec,
  )
where

import qualified Pqi
import Pqi.Conformance.Harness
import Pqi.Conformance.Prelude
import Pqi.Conformance.Scenario (execScenario)
import Test.Hspec

spec :: Pqi.Adapter -> SpecWith ByteString
spec :: Adapter -> SpecWith ByteString
spec Adapter
adapter =
  String -> SpecWith ByteString -> SpecWith ByteString
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"unsafeFreeResult" do
    String
-> (ByteString -> IO ()) -> SpecWith (Arg (ByteString -> IO ()))
forall a.
(HasCallStack, Example a) =>
String -> a -> SpecWith (Arg a)
it String
"leaves the connection usable" \ByteString
conninfo ->
      Adapter
-> ByteString
-> (Connection -> IO (Maybe ResultObservation))
-> IO ()
forall a.
(Eq a, Show a, HasCallStack) =>
Adapter -> ByteString -> (Connection -> IO a) -> IO ()
differential Adapter
adapter ByteString
conninfo \Connection
connection -> do
        result <- Connection -> ByteString -> IO (Maybe Result)
Pqi.exec Connection
connection ByteString
"select 1"
        traverse_ Pqi.unsafeFreeResult result
        execScenario "select 2" connection