Skip to content

Commit

Permalink
Merge pull request #247 from well-typed/edsko/snappy
Browse files Browse the repository at this point in the history
Remove references to `SNAPPY` from `grapesy`
  • Loading branch information
edsko authored Oct 25, 2024
2 parents af94605 + 8ee46de commit c11e39b
Show file tree
Hide file tree
Showing 18 changed files with 68 additions and 117 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/haskell-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ jobs:
compilerVersion: 9.8.2
setup-method: ghcup
allow-failure: false
- compiler: ghc-9.6.4
- compiler: ghc-9.6.6
compilerKind: ghc
compilerVersion: 9.6.4
compilerVersion: 9.6.6
setup-method: ghcup
allow-failure: false
- compiler: ghc-9.4.8
Expand Down
26 changes: 10 additions & 16 deletions grapesy/demo-client/Demo/Client/Cmdline.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module Demo.Client.Cmdline (

import Prelude

import Data.Foldable (asum)
import Data.Foldable (asum, toList)
import Data.Int
import Data.Kind
import Data.Maybe (fromMaybe)
Expand Down Expand Up @@ -181,22 +181,16 @@ parseServerValidation defaultPub =
]

parseCompression :: Opt.Parser Compression
parseCompression = asum [
Opt.flag' Compr.gzip $ mconcat [
Opt.long "gzip"
, Opt.help "Use GZip compression for all messages"
]
, Opt.flag' Compr.deflate $ mconcat [
Opt.long "deflate"
, Opt.help "Use deflate compression for all messages"
]
#ifdef SNAPPY
, Opt.flag' Compr.snappy $ mconcat [
Opt.long "snappy"
, Opt.help "Use snappy compression for all messages"
parseCompression = asum $ map go (toList Compr.allSupportedCompression)
where
go :: Compression -> Opt.Parser Compression
go compr = Opt.flag' compr $ mconcat [
Opt.long comprId
, Opt.help $ "Use " ++ comprId ++ " compression for all messages"
]
#endif
]
where
comprId :: String
comprId = show (Compr.compressionId compr)

parseAPI :: Opt.Parser API
parseAPI = asum [
Expand Down
4 changes: 1 addition & 3 deletions grapesy/grapesy.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ data-files: route_guide_db.json
tested-with: GHC==8.10.7
, GHC==9.2.8
, GHC==9.4.8
, GHC==9.6.4
, GHC==9.6.6
, GHC==9.8.2
, GHC==9.10.1

Expand Down Expand Up @@ -248,7 +248,6 @@ test-suite test-grapesy
, containers
, deepseq
, exceptions
, grpc-spec
, http-types
, http2
, mtl
Expand Down Expand Up @@ -387,7 +386,6 @@ test-suite test-stress
, async
, bytestring
, exceptions
, grpc-spec
, http2
, network
, tls
Expand Down
2 changes: 1 addition & 1 deletion grapesy/proto/Proto/API/Trivial.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Proto.API.Trivial
) where

import Network.GRPC.Common
import Network.GRPC.Spec
import Network.GRPC.Common.Binary

{-------------------------------------------------------------------------------
Trivial RPC
Expand Down
2 changes: 0 additions & 2 deletions grapesy/src/Network/GRPC/Client/Session.hs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@ instance SupportsClientRpc rpc => InitiateSession (ClientSession rpc) where
case verifyAllIf connVerifyHeaders responseHeaders of
Left err -> throwIO $ CallSetupInvalidResponseHeaders err
Right hdrs -> do
-- TODO: <https://github.com/well-typed/grapesy/issues/203>
-- If we omit this call to 'updateConnectionMeta', no tests fail.
Connection.updateConnectionMeta conn responseHeaders
cIn <- getCompression $ requiredResponseCompression hdrs
return $ FlowStartRegular $ InboundHeaders {
Expand Down
5 changes: 0 additions & 5 deletions grapesy/src/Network/GRPC/Common/Compression.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@ module Network.GRPC.Common.Compression (
Compression(..)
, CompressionId(..)
-- * Standard compression schemes
, noCompression
, gzip
, deflate
#ifdef SNAPPY
, snappy
#endif
, allSupportedCompression
-- * Negotation
, Negotation(..)
Expand Down
3 changes: 0 additions & 3 deletions grapesy/src/Network/GRPC/Util/Session/Channel.hs
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,6 @@ data RegularFlowState flow = RegularFlowState {
-- This TMVar is written to for incoming messages ('recvMessageLoop') and
-- read from for outgoing messages ('sendMessageLoop'). It acts as a
-- one-place buffer, providing backpressure in both directions.
--
-- TODO: <https://github.com/well-typed/grapesy/issues/118>.
-- It might make sense to generalize this to an @N@-place buffer.
, flowMsg :: TMVar (StreamElem (Trailers flow) (Message flow))

-- | Trailers
Expand Down
1 change: 0 additions & 1 deletion grapesy/test-grapesy/Test/Sanity/Disconnect.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import Network.GRPC.Common
import Network.GRPC.Server qualified as Server
import Network.GRPC.Server.Binary qualified as Binary
import Network.GRPC.Server.Run
import Network.GRPC.Spec

import Proto.API.Trivial

Expand Down
51 changes: 24 additions & 27 deletions grapesy/test-grapesy/Test/Sanity/StreamingType/NonStreaming.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import Network.GRPC.Server.StreamType qualified as Server
import Network.GRPC.Server.StreamType.Binary qualified as Binary

import Test.Driver.ClientServer
import Data.Foldable (toList)

tests :: TestTree
tests = testGroup "Test.Sanity.StreamingType.NonStreaming" [
Expand Down Expand Up @@ -79,33 +80,29 @@ tests = testGroup "Test.Sanity.StreamingType.NonStreaming" [
]
]
, testGroup "compression" [
testCase "gzip" $
test_increment def {
clientCompr = Compr.only Compr.gzip
, serverCompr = Compr.only Compr.gzip
}
, testCase "deflate" $
test_increment def {
clientCompr = Compr.only Compr.deflate
, serverCompr = Compr.only Compr.deflate
}
#ifdef SNAPPY
, testCase "snappy" $
test_increment def {
clientCompr = Compr.only Compr.snappy
, serverCompr = Compr.only Compr.snappy
}
#endif
, testCase "clientChoosesUnsupported" $
test_increment def {
clientInitCompr = Just Compr.gzip
, serverCompr = Compr.none
}
, testCase "serverChoosesUnsupported" $
test_increment def {
clientCompr = Compr.only Compr.gzip
, serverCompr = Compr.insist Compr.deflate
}
testGroup "supported" $
let mkTest :: Compr.Compression -> TestTree
mkTest compr = testCase comprId $
test_increment def {
clientCompr = Compr.only compr
, serverCompr = Compr.only compr
}
where
comprId :: String
comprId = show (Compr.compressionId compr)
in map mkTest (toList Compr.allSupportedCompression)
, testGroup "unsupported" [
testCase "clientChoosesUnsupported" $
test_increment def {
clientInitCompr = Just Compr.gzip
, serverCompr = Compr.none
}
, testCase "serverChoosesUnsupported" $
test_increment def {
clientCompr = Compr.none
, serverCompr = Compr.insist Compr.gzip
}
]
]
]
]
Expand Down
10 changes: 5 additions & 5 deletions grapesy/test-stress/Test/Stress/Client.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ client ::
Bool
-> Maybe ServerValidation
-> PortNumber
-> Compression
-> Maybe Compression
-> [Connect]
-> IO ()
client v mServerValidation serverPort compr =
Expand All @@ -39,7 +39,7 @@ runConnect ::
Bool
-> Maybe ServerValidation
-> PortNumber
-> Compression
-> Maybe Compression
-> Connect
-> IO ()
runConnect v mServerValidation serverPort compr Connect{..} = do
Expand All @@ -60,14 +60,14 @@ runCalls ::
Bool
-> Maybe ServerValidation
-> PortNumber
-> Compression
-> Maybe Compression
-> Int
-> (Int, [Call])
-> IO ()
runCalls v mServerValidation serverPort compr callNum (connNum, calls) = do
say' v serverPort msg
let connParams = def {
connCompression = Compr.insist compr
connCompression = maybe Compr.none Compr.insist compr
, connHTTP2Settings = def {
http2TcpAbortiveClose = True
}
Expand Down Expand Up @@ -127,7 +127,7 @@ runCalls v mServerValidation serverPort compr callNum (connNum, calls) = do
Just _ -> "secure "
Nothing -> "insecure "
++ "server at port " ++ show serverPort ++ " with compression "
++ show (Compr.compressionId compr)
++ maybe "none" (show . Compr.compressionId) compr

runCall :: Bool -> PortNumber -> Connection -> Call -> IO ()
runCall v p conn =
Expand Down
49 changes: 16 additions & 33 deletions grapesy/test-stress/Test/Stress/Cmdline.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ module Test.Stress.Cmdline
, getCmdline
) where

import Control.Applicative
import Control.Applicative ((<|>))
import Data.Foldable (asum, toList)
import Network.Socket (HostName, PortNumber)
import Options.Applicative qualified as Opt

import Network.GRPC.Client qualified as Client
import Network.GRPC.Common
import Network.GRPC.Common.Compression (Compression)
import Network.GRPC.Common.Compression qualified as Compr
import Network.GRPC.Server.Run
import Network.GRPC.Spec qualified as Spec

import Paths_grapesy

Expand All @@ -51,7 +53,7 @@ data Role =
, clientConnects :: [Connect]

-- | Insist on this compression scheme for all messages
, clientCompression :: Spec.Compression
, clientCompression :: Maybe Compression
}

-- | Run the server
Expand Down Expand Up @@ -184,7 +186,7 @@ parseClientRole defaultPub =
<$> parseClientSecurity defaultPub
<*> parseClientPort
<*> parseClientConnects
<*> parseCompression
<*> Opt.optional parseCompression

parseClientSecurity :: FilePath -> Opt.Parser (Maybe Client.ServerValidation)
parseClientSecurity defaultPub =
Expand Down Expand Up @@ -302,36 +304,17 @@ parseCall =
, Opt.metavar "N"
])

parseCompression :: Opt.Parser Spec.Compression
parseCompression =
gzip
<|> deflate
#ifdef SNAPPY
<|> snappy
#endif
<|> pure Spec.noCompression
parseCompression :: Opt.Parser Compression
parseCompression = asum $ map go (toList Compr.allSupportedCompression)
where
gzip :: Opt.Parser Spec.Compression
gzip =
Opt.flag' Spec.gzip $ mconcat [
Opt.long "gzip"
, Opt.help "Insist on gzip compression"
]

deflate :: Opt.Parser Spec.Compression
deflate =
Opt.flag' Spec.deflate $ mconcat [
Opt.long "deflate"
, Opt.help "Insist on deflate compression"
]
#ifdef SNAPPY
snappy :: Opt.Parser Spec.Compression
snappy =
Opt.flag' Spec.snappy $ mconcat [
Opt.long "snappy"
, Opt.help "Insist on snappy compression"
]
#endif
go :: Compression -> Opt.Parser Compression
go compr = Opt.flag' compr $ mconcat [
Opt.long comprId
, Opt.help $ "Insist on " ++ comprId ++ " compression "
]
where
comprId :: String
comprId = show (Compr.compressionId compr)

-------------------------------------------------------------------------------
-- Server option parsers
Expand Down
2 changes: 1 addition & 1 deletion grpc-spec/grpc-spec.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ extra-doc-files: CHANGELOG.md
tested-with: GHC==8.10.7
, GHC==9.2.8
, GHC==9.4.8
, GHC==9.6.4
, GHC==9.6.6
, GHC==9.8.2
, GHC==9.10.1

Expand Down
9 changes: 2 additions & 7 deletions grpc-spec/src/Network/GRPC/Spec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,11 @@ module Network.GRPC.Spec (
-- * Compression
, CompressionId(..)
, Compression(..)
, serializeCompressionId
, deserializeCompressionId
-- ** Compression algorithms
, noCompression
, gzip
, deflate
#ifdef SNAPPY
, snappy
#endif
, allSupportedCompression
, serializeCompressionId
, deserializeCompressionId
-- * Message metadata
, OutboundMeta(..)
, InboundMeta(..)
Expand Down
9 changes: 2 additions & 7 deletions grpc-spec/src/Network/GRPC/Spec/Compression.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,14 @@
module Network.GRPC.Spec.Compression (
-- * Definition
Compression(..)
, noCompression
, gzip
, allSupportedCompression
, compressionIsIdentity
-- ** ID
, CompressionId(..)
, serializeCompressionId
, deserializeCompressionId
-- * Specific coders
, noCompression
, gzip
, deflate
#ifdef SNAPPY
, snappy
#endif
) where

import Codec.Compression.GZip qualified as GZip
Expand Down
2 changes: 1 addition & 1 deletion tutorials/basics/basics.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ data-files: route_guide_db.json
tested-with: GHC==8.10.7
, GHC==9.2.8
, GHC==9.4.8
, GHC==9.6.4
, GHC==9.6.6
, GHC==9.8.2

custom-setup
Expand Down
2 changes: 1 addition & 1 deletion tutorials/lowlevel/lowlevel.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ data-files: route_guide_db.json
tested-with: GHC==8.10.7
, GHC==9.2.8
, GHC==9.4.8
, GHC==9.6.4
, GHC==9.6.6
, GHC==9.8.2

custom-setup
Expand Down
2 changes: 1 addition & 1 deletion tutorials/metadata/metadata.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ extra-source-files: proto/fileserver.proto
tested-with: GHC==8.10.7
, GHC==9.2.8
, GHC==9.4.8
, GHC==9.6.4
, GHC==9.6.6
, GHC==9.8.2

custom-setup
Expand Down
Loading

0 comments on commit c11e39b

Please sign in to comment.