-- | Coverage for 'Pqi.setnonblocking': toggling the connection's
-- non-blocking flag.
module Pqi.Conformance.Operation.Setnonblocking
  ( spec,
  )
where

import qualified Pqi
import Pqi.Conformance.Harness
import Pqi.Conformance.Prelude
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
"setnonblocking" do
    String
-> (ByteString -> IO ()) -> SpecWith (Arg (ByteString -> IO ()))
forall a.
(HasCallStack, Example a) =>
String -> a -> SpecWith (Arg a)
it String
"turns the non-blocking flag on and off" \ByteString
conninfo ->
      Adapter
-> ByteString
-> (Connection -> IO (Bool, Bool, Bool, Bool))
-> IO ()
forall a.
(Eq a, Show a, HasCallStack) =>
Adapter -> ByteString -> (Connection -> IO a) -> IO ()
differential Adapter
adapter ByteString
conninfo \Connection
connection -> do
        setOn <- Connection -> Bool -> IO Bool
Pqi.setnonblocking Connection
connection Bool
True
        nowOn <- Pqi.isnonblocking connection
        setOff <- Pqi.setnonblocking connection False
        nowOff <- Pqi.isnonblocking connection
        pure (setOn, nowOn, setOff, nowOff)