packages feed

zeromq4-patterns 0.3.0.0 → 0.3.1.0

raw patch · 4 files changed

+33/−2 lines, 4 files

Files

src/System/ZMQ4/Patterns/Clone.hs view
@@ -37,6 +37,7 @@   -- * Server and client   publisher , subscriber+, queryLastState ) where -import System.ZMQ4.Patterns.Clone.Internal (publisher, subscriber)+import System.ZMQ4.Patterns.Clone.Internal (publisher, subscriber, queryLastState)
src/System/ZMQ4/Patterns/Clone/Internal.hs view
@@ -14,6 +14,7 @@    -- * Client , subscriber+, queryLastState ) where  import Control.Concurrent.Async (Async, waitBoth, uninterruptibleCancel)@@ -166,6 +167,22 @@         when (messageVersion env' > messageVersion env) $             liftIO $ putMVar chan a' +-- | Only request the most recent state from the server.+--+-- This function will query the ROUTER port for the latest state, and return+-- it.+queryLastState :: Binary a+               => String    -- ^ Address of the server's ROUTER socket+               -> IO a+queryLastState !routerAddr = runZMQ $ do+    dealer <- socket Dealer+    connect dealer routerAddr++    send dealer [] iSTATE_REQUEST+    msg <- receive dealer+    let !env = decode (BL.fromStrict msg)+        !a = messageValue env+    return a  -- | Helper function withAsync :: ZMQ z a -> (Async a -> ZMQ z b) -> ZMQ z b
test/Test/System/ZMQ4/Patterns/Clone/Internal.hs view
@@ -18,6 +18,7 @@ tests = testGroup "System.ZMQ4.Patterns.Clone.Internal" [     testProperty "binary message" prop_binary_message   , testProperty "server client" prop_server_client+  , testProperty "server queryLastState" prop_server_queryLastState   ]  newtype TestMessage = TestMessage (Message Int) deriving (Eq, Show)@@ -74,3 +75,15 @@                                             else                                                next s'         next initSeq++prop_server_queryLastState :: Word64 -> Property+prop_server_queryLastState val = within (10*1000*1000) $ ioProperty $ do+    let pubAddr    = "ipc:///tmp/zeromq4-clone-pattern-test-pub.socket"+        routerAddr = "ipc:///tmp/zeromq4-clone-pattern-test-router.socket"++    pushC <- newEmptyMVar++    withAsync (publisher pubAddr routerAddr pushC) $ \_ ->+      withAsync (putMVar pushC val) $ \_ -> do+        m <- queryLastState routerAddr+        return $ property (m == val)
zeromq4-patterns.cabal view
@@ -1,5 +1,5 @@ name:           zeromq4-patterns-version:        0.3.0.0+version:        0.3.1.0 synopsis:       Haskell implementation of several ZeroMQ patterns. description:     Haskell implementation of several ZeroMQ patterns that you can find in the