curryer-rpc 0.3.3 → 0.3.4
raw patch · 5 files changed
+53/−9 lines, 5 filesdep +textdep ~streamlydep ~streamly-bytestringdep ~streamly-core
Dependencies added: text
Dependency ranges changed: streamly, streamly-bytestring, streamly-core
Files
- Changelog.markdown +4/−0
- curryer-rpc.cabal +5/−4
- src/Network/RPC/Curryer/Server.hs +11/−4
- src/Network/RPC/Curryer/StreamlyAdditions.hs +6/−1
- test/Curryer/Test/Basic.hs +27/−0
Changelog.markdown view
@@ -1,3 +1,7 @@+# v0.3.4 (2024-01-12)++* revert to streamly 0.9.0 due to corruption bug in streamly-0.10.0+ # v0.3.3 (2024-01-07) * use streamly 0.10.0 and streamly-core 0.2.0
curryer-rpc.cabal view
@@ -1,5 +1,5 @@ Name: curryer-rpc-Version: 0.3.3+Version: 0.3.4 License: PublicDomain Build-Type: Simple Homepage: https://github.com/agentm/curryer@@ -21,9 +21,9 @@ Build-Depends: base >= 4.12 && < 4.19 , winery , bytestring- , streamly >= 0.10.0- , streamly-core >= 0.2.0- , streamly-bytestring >= 0.2.1+ , streamly == 0.9.0+ , streamly-core >= 0.1.0+ , streamly-bytestring >= 0.2.0 , network , exceptions , async@@ -53,6 +53,7 @@ build-depends: tasty , tasty-hunit , base+ , text , curryer-rpc , winery , network
src/Network/RPC/Curryer/Server.hs view
@@ -3,9 +3,17 @@ {- HLINT ignore "Use lambda-case" -} module Network.RPC.Curryer.Server where import qualified Streamly.Data.Stream.Prelude as SP-import Streamly.Data.Stream as Stream hiding (foldr)+#if MIN_VERSION_streamly(0,9,0)+import Streamly.Internal.Data.Stream.Concurrent as Stream+import Streamly.Internal.Serialize.FromBytes (word32be)+import qualified Streamly.Internal.Data.Array.Type as Arr+#else+import qualified Streamly.Data.Array as Arr import Streamly.Data.Stream.Prelude as Stream hiding (foldr) import Streamly.Internal.Data.Binary.Parser (word32be)+#endif+import Streamly.Data.Stream as Stream hiding (foldr)+ import Streamly.Network.Socket as SSock import Network.Socket as Socket import Network.Socket.ByteString as Socket@@ -37,11 +45,10 @@ import Data.Hashable import System.Timeout import qualified Network.ByteOrder as BO-import qualified Streamly.Data.Array as Arr -#define CURRYER_SHOW_BYTES 0-#define CURRYER_PASS_SCHEMA 0+#define CURRYER_SHOW_BYTES 1+#define CURRYER_PASS_SCHEMA 1 #if CURRYER_SHOW_BYTES == 1 import Debug.Trace
src/Network/RPC/Curryer/StreamlyAdditions.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP #-} module Network.RPC.Curryer.StreamlyAdditions where import Control.Monad.IO.Class import Network.Socket (Socket, PortNumber, SocketOption, SockAddr(..), maxListenQueue, Family(..), SocketType(..), defaultProtocol, tupleToHostAddress, withSocketsDo, socket, setSocketOption, bind, getSocketName)@@ -7,9 +8,13 @@ import Data.Word import qualified Streamly.Internal.Data.Unfold as UF import Streamly.Network.Socket hiding (acceptor)---import qualified Streamly.Internal.Data.Stream.StreamD as D+#if MIN_VERSION_streamly(0,9,0)+import qualified Streamly.Internal.Data.Stream.StreamD as D+import Streamly.Internal.Data.Unfold.Type (Unfold(..))+#else import qualified Streamly.Internal.Data.Stream as D import Streamly.Internal.Data.Unfold (Unfold(..))+#endif acceptorOnAddr :: MonadIO m
test/Curryer/Test/Basic.hs view
@@ -12,6 +12,7 @@ import Control.Concurrent.STM import Control.Exception import Data.List+import Data.Text (Text, pack) import Network.RPC.Curryer.Server import Network.RPC.Curryer.Client@@ -21,6 +22,7 @@ testTree :: TestTree testTree = testGroup "basic" [ testCase "simple request and response" testSimpleCall+ ,testCase "complex ADT" testComplexADT ,testCase "client async" testAsyncServerCall ,testCase "server async" testAsyncClientCall ,testCase "client sync timeout" testSyncClientCallTimeout@@ -68,6 +70,10 @@ deriving (Generic, Show) deriving Serialise via WineryVariant ThrowTimeout +data RoundtripSomeADTReq = RoundtripSomeADTReq SomeADT+ deriving (Generic, Show)+ deriving Serialise via WineryVariant RoundtripSomeADTReq+ testServerRequestHandlers :: Maybe (MVar String) -> RequestHandlers () testServerRequestHandlers mAsyncMVar = [ RequestHandler $ \_ (AddTwoNumbersReq x y) -> pure (x + y)@@ -88,6 +94,7 @@ , RequestHandler $ \_ ThrowServerSideExceptionReq -> do _ <- error "test server exception" pure ()+ , RequestHandler $ \_ (RoundtripSomeADTReq s) -> pure s ] -- test a simple client-to-server round-trip function execution@@ -224,5 +231,25 @@ conn <- connect [] localHostAddr port ret <- call @_ @Int conn ThrowTimeout assertEqual "handler timeout exception" (Left TimeoutError) ret+ close conn+ cancel server++data SomeADT = SomeTextCon Text SomeADT+ | SomeIntCon Integer SomeADT+ | EndCon+ deriving (Generic, Show, Eq)+ deriving Serialise via WineryVariant SomeADT++testComplexADT :: Assertion+testComplexADT = do+ let arg = SomeTextCon (pack "sduofhsldkfsldkfjsldkfjsdlkfjsdlfksdjlfksjdflksdjflksdjfjlsdjlfjdklskfjlsdlfk") (SomeIntCon 0 (EndCon))+ readyVar <- newEmptyMVar+ server <- async (serve (testServerRequestHandlers Nothing) emptyServerState localHostAddr 0 (Just readyVar))+ --wait for server to be ready+ (SockAddrInet port _) <- takeMVar readyVar+ conn <- connect [] localHostAddr port+ replicateM_ 5 $ do --make five AddTwo calls to shake out parallelism bugs+ res <- call conn (RoundtripSomeADTReq arg)+ assertEqual "complex ADT" (Right arg) res close conn cancel server