From cf8b9c12ff5cbdc77d3b8866af2c761a546ec8fc Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Sun, 22 Oct 2023 10:50:36 +0100 Subject: [PATCH] remove test dependencies (#861) * remove test dependencies * .hlint.yaml --- .hlint.yaml | 1 + package.yaml | 3 +- simplexmq.cabal | 24 +++--------- src/Simplex/FileTransfer/Protocol.hs | 4 -- src/Simplex/Messaging/Agent/Protocol.hs | 14 ------- src/Simplex/Messaging/Notifications/Server.hs | 6 +-- src/Simplex/Messaging/Protocol.hs | 6 --- src/Simplex/Messaging/Transport.hs | 6 --- tests/AgentTests/FunctionalAPITests.hs | 2 +- tests/AgentTests/NotificationTests.hs | 2 +- tests/CoreTests/ProtocolErrorTests.hs | 38 ++++++++++++++++--- tests/NtfServerTests.hs | 1 - 12 files changed, 45 insertions(+), 62 deletions(-) create mode 100644 .hlint.yaml diff --git a/.hlint.yaml b/.hlint.yaml new file mode 100644 index 000000000..edf6d20ff --- /dev/null +++ b/.hlint.yaml @@ -0,0 +1 @@ +- ignore: {name: "Use underscore"} diff --git a/package.yaml b/package.yaml index 6fdda401b..3b00c8552 100644 --- a/package.yaml +++ b/package.yaml @@ -44,7 +44,6 @@ dependencies: - hourglass == 0.2.* - http-types == 0.12.* - http2 >= 4.1.4 && < 4.2 - - generic-random == 1.5.* - ini == 0.4.1 - iproute == 1.7.* - iso8601-time == 0.1.* @@ -53,7 +52,6 @@ dependencies: - network >= 3.1.2.7 && < 3.2 - network-transport == 0.5.6 - optparse-applicative >= 0.15 && < 0.17 - - QuickCheck == 2.14.* - process == 1.6.* - random >= 1.1 && < 1.3 - simple-logger == 0.1.* @@ -143,6 +141,7 @@ tests: dependencies: - simplexmq - deepseq == 1.4.* + - generic-random == 1.5.* - hspec == 2.11.* - hspec-core == 2.11.* - HUnit == 1.6.* diff --git a/simplexmq.cabal b/simplexmq.cabal index 7ebbb8c6e..c95e4ff05 100644 --- a/simplexmq.cabal +++ b/simplexmq.cabal @@ -146,8 +146,7 @@ library src ghc-options: -Wall -Wcompat -Werror=incomplete-patterns -Wredundant-constraints -Wincomplete-record-updates -Wincomplete-uni-patterns -Wunused-type-patterns build-depends: - QuickCheck ==2.14.* - , aeson ==2.2.* + aeson ==2.2.* , ansi-terminal >=0.10 && <0.12 , asn1-encoding ==0.9.* , asn1-types ==0.3.* @@ -166,7 +165,6 @@ library , direct-sqlcipher ==2.3.* , directory ==1.3.* , filepath ==1.4.* - , generic-random ==1.5.* , hourglass ==0.2.* , http-types ==0.12.* , http2 >=4.1.4 && <4.2 @@ -211,8 +209,7 @@ executable ntf-server apps/ntf-server ghc-options: -Wall -Wcompat -Werror=incomplete-patterns -Wredundant-constraints -Wincomplete-record-updates -Wincomplete-uni-patterns -Wunused-type-patterns -threaded -rtsopts build-depends: - QuickCheck ==2.14.* - , aeson ==2.2.* + aeson ==2.2.* , ansi-terminal >=0.10 && <0.12 , asn1-encoding ==0.9.* , asn1-types ==0.3.* @@ -231,7 +228,6 @@ executable ntf-server , direct-sqlcipher ==2.3.* , directory ==1.3.* , filepath ==1.4.* - , generic-random ==1.5.* , hourglass ==0.2.* , http-types ==0.12.* , http2 >=4.1.4 && <4.2 @@ -277,8 +273,7 @@ executable smp-agent apps/smp-agent ghc-options: -Wall -Wcompat -Werror=incomplete-patterns -Wredundant-constraints -Wincomplete-record-updates -Wincomplete-uni-patterns -Wunused-type-patterns -threaded -rtsopts build-depends: - QuickCheck ==2.14.* - , aeson ==2.2.* + aeson ==2.2.* , ansi-terminal >=0.10 && <0.12 , asn1-encoding ==0.9.* , asn1-types ==0.3.* @@ -297,7 +292,6 @@ executable smp-agent , direct-sqlcipher ==2.3.* , directory ==1.3.* , filepath ==1.4.* - , generic-random ==1.5.* , hourglass ==0.2.* , http-types ==0.12.* , http2 >=4.1.4 && <4.2 @@ -343,8 +337,7 @@ executable smp-server apps/smp-server ghc-options: -Wall -Wcompat -Werror=incomplete-patterns -Wredundant-constraints -Wincomplete-record-updates -Wincomplete-uni-patterns -Wunused-type-patterns -threaded -rtsopts build-depends: - QuickCheck ==2.14.* - , aeson ==2.2.* + aeson ==2.2.* , ansi-terminal >=0.10 && <0.12 , asn1-encoding ==0.9.* , asn1-types ==0.3.* @@ -363,7 +356,6 @@ executable smp-server , direct-sqlcipher ==2.3.* , directory ==1.3.* , filepath ==1.4.* - , generic-random ==1.5.* , hourglass ==0.2.* , http-types ==0.12.* , http2 >=4.1.4 && <4.2 @@ -409,8 +401,7 @@ executable xftp apps/xftp ghc-options: -Wall -Wcompat -Werror=incomplete-patterns -Wredundant-constraints -Wincomplete-record-updates -Wincomplete-uni-patterns -Wunused-type-patterns -threaded -rtsopts build-depends: - QuickCheck ==2.14.* - , aeson ==2.2.* + aeson ==2.2.* , ansi-terminal >=0.10 && <0.12 , asn1-encoding ==0.9.* , asn1-types ==0.3.* @@ -429,7 +420,6 @@ executable xftp , direct-sqlcipher ==2.3.* , directory ==1.3.* , filepath ==1.4.* - , generic-random ==1.5.* , hourglass ==0.2.* , http-types ==0.12.* , http2 >=4.1.4 && <4.2 @@ -475,8 +465,7 @@ executable xftp-server apps/xftp-server ghc-options: -Wall -Wcompat -Werror=incomplete-patterns -Wredundant-constraints -Wincomplete-record-updates -Wincomplete-uni-patterns -Wunused-type-patterns -threaded -rtsopts build-depends: - QuickCheck ==2.14.* - , aeson ==2.2.* + aeson ==2.2.* , ansi-terminal >=0.10 && <0.12 , asn1-encoding ==0.9.* , asn1-types ==0.3.* @@ -495,7 +484,6 @@ executable xftp-server , direct-sqlcipher ==2.3.* , directory ==1.3.* , filepath ==1.4.* - , generic-random ==1.5.* , hourglass ==0.2.* , http-types ==0.12.* , http2 >=4.1.4 && <4.2 diff --git a/src/Simplex/FileTransfer/Protocol.hs b/src/Simplex/FileTransfer/Protocol.hs index 7c8ee4cbf..84627ee0c 100644 --- a/src/Simplex/FileTransfer/Protocol.hs +++ b/src/Simplex/FileTransfer/Protocol.hs @@ -26,7 +26,6 @@ import Data.Maybe (isNothing) import Data.Type.Equality import Data.Word (Word32) import GHC.Generics (Generic) -import Generic.Random (genericArbitraryU) import qualified Simplex.Messaging.Crypto as C import Simplex.Messaging.Encoding import Simplex.Messaging.Encoding.String @@ -59,7 +58,6 @@ import Simplex.Messaging.Protocol import Simplex.Messaging.Transport (SessionId, TransportError (..)) import Simplex.Messaging.Util (bshow, (<$?>)) import Simplex.Messaging.Version -import Test.QuickCheck (Arbitrary (..)) currentXFTPVersion :: Version currentXFTPVersion = 1 @@ -370,8 +368,6 @@ instance StrEncoding XFTPErrorType where e -> bshow e strP = "CMD " *> (CMD <$> parseRead1) <|> parseRead1 -instance Arbitrary XFTPErrorType where arbitrary = genericArbitraryU - instance Encoding XFTPErrorType where smpEncode = \case BLOCK -> "BLOCK" diff --git a/src/Simplex/Messaging/Agent/Protocol.hs b/src/Simplex/Messaging/Agent/Protocol.hs index 5da809033..321149538 100644 --- a/src/Simplex/Messaging/Agent/Protocol.hs +++ b/src/Simplex/Messaging/Agent/Protocol.hs @@ -177,7 +177,6 @@ import Data.Word (Word32) import Database.SQLite.Simple.FromField import Database.SQLite.Simple.ToField import GHC.Generics (Generic) -import Generic.Random (genericArbitraryU) import Simplex.FileTransfer.Description import Simplex.FileTransfer.Protocol (FileParty (..), XFTPErrorType) import Simplex.Messaging.Agent.QueryString @@ -213,7 +212,6 @@ import Simplex.Messaging.Transport (Transport (..), TransportError, serializeTra import Simplex.Messaging.Transport.Client (TransportHost, TransportHosts_ (..)) import Simplex.Messaging.Util import Simplex.Messaging.Version -import Test.QuickCheck (Arbitrary (..)) import Text.Read import UnliftIO.Exception (Exception) @@ -1620,18 +1618,6 @@ instance StrEncoding AgentErrorType where where text = encodeUtf8 . T.pack -instance Arbitrary AgentErrorType where arbitrary = genericArbitraryU - -instance Arbitrary CommandErrorType where arbitrary = genericArbitraryU - -instance Arbitrary ConnectionErrorType where arbitrary = genericArbitraryU - -instance Arbitrary BrokerErrorType where arbitrary = genericArbitraryU - -instance Arbitrary SMPAgentError where arbitrary = genericArbitraryU - -instance Arbitrary AgentCryptoError where arbitrary = genericArbitraryU - cryptoErrToSyncState :: AgentCryptoError -> RatchetSyncState cryptoErrToSyncState = \case DECRYPT_AES -> RSAllowed diff --git a/src/Simplex/Messaging/Notifications/Server.hs b/src/Simplex/Messaging/Notifications/Server.hs index 8cb6be4e5..6d1b55d6f 100644 --- a/src/Simplex/Messaging/Notifications/Server.hs +++ b/src/Simplex/Messaging/Notifications/Server.hs @@ -16,7 +16,6 @@ import Control.Logger.Simple import Control.Monad import Control.Monad.Except import Control.Monad.Reader -import Data.Bifunctor (second) import Data.ByteString.Char8 (ByteString) import qualified Data.ByteString.Char8 as B import Data.Functor (($>)) @@ -205,7 +204,7 @@ ntfSubscriber NtfSubscriber {smpSubscribers, newSubQ, smpAgent = ca@SMPClientAge Just err -> (subs, oks, err : errs) -- permanent error, log and don't retry subscription Nothing -> (sub : subs, oks, errs) -- temporary error, retry subscription - -- | Subscribe to queues. The list of results can have a different order. + -- \| Subscribe to queues. The list of results can have a different order. subscribeQueues :: SMPServer -> NonEmpty NtfSubData -> IO (NonEmpty (NtfSubData, Either SMPClientError ())) subscribeQueues srv subs = L.zipWith (\s r -> (s, snd r)) subs <$> subscribeQueuesNtfs ca srv (L.map sub subs) @@ -346,7 +345,8 @@ runNtfClientTransport th@THandle {sessionId} = do raceAny_ ([liftIO $ send th c, client c s ps, receive th c] <> disconnectThread_ c expCfg) `finally` liftIO (clientDisconnected c) where - disconnectThread_ c expCfg = maybe [] ((: []) . liftIO . disconnectTransport th c activeAt) expCfg + disconnectThread_ c (Just expCfg) = [liftIO $ disconnectTransport th c activeAt expCfg] + disconnectThread_ _ _ = [] clientDisconnected :: NtfServerClient -> IO () clientDisconnected NtfServerClient {connected} = atomically $ writeTVar connected False diff --git a/src/Simplex/Messaging/Protocol.hs b/src/Simplex/Messaging/Protocol.hs index 52611215a..44d33a381 100644 --- a/src/Simplex/Messaging/Protocol.hs +++ b/src/Simplex/Messaging/Protocol.hs @@ -172,7 +172,6 @@ import Data.Time.Clock.System (SystemTime (..)) import Data.Type.Equality import GHC.Generics (Generic) import GHC.TypeLits (ErrorMessage (..), TypeError, type (+)) -import Generic.Random (genericArbitraryU) import Network.Socket (HostName, ServiceName) import qualified Simplex.Messaging.Crypto as C import Simplex.Messaging.Encoding @@ -182,7 +181,6 @@ import Simplex.Messaging.Transport import Simplex.Messaging.Transport.Client (TransportHost, TransportHosts (..)) import Simplex.Messaging.Util (bshow, eitherToMaybe, (<$?>)) import Simplex.Messaging.Version -import Test.QuickCheck (Arbitrary (..)) currentSMPClientVersion :: Version currentSMPClientVersion = 2 @@ -1037,10 +1035,6 @@ instance ToJSON CommandError where instance FromJSON CommandError where parseJSON = J.genericParseJSON $ sumTypeJSON id -instance Arbitrary ErrorType where arbitrary = genericArbitraryU - -instance Arbitrary CommandError where arbitrary = genericArbitraryU - -- | SMP transmission parser. transmissionP :: Parser RawTransmission transmissionP = do diff --git a/src/Simplex/Messaging/Transport.hs b/src/Simplex/Messaging/Transport.hs index 08e13b033..2281dce87 100644 --- a/src/Simplex/Messaging/Transport.hs +++ b/src/Simplex/Messaging/Transport.hs @@ -76,7 +76,6 @@ import Data.Functor (($>)) import Data.Version (showVersion) import GHC.Generics (Generic) import GHC.IO.Handle.Internals (ioe_EOF) -import Generic.Random (genericArbitraryU) import Network.Socket import qualified Network.TLS as T import qualified Network.TLS.Extra as TE @@ -87,7 +86,6 @@ import Simplex.Messaging.Parsers (dropPrefix, parse, parseRead1, sumTypeJSON) import Simplex.Messaging.Transport.Buffer import Simplex.Messaging.Util (bshow, catchAll, catchAll_) import Simplex.Messaging.Version -import Test.QuickCheck (Arbitrary (..)) import UnliftIO.Exception (Exception) import qualified UnliftIO.Exception as E import UnliftIO.STM @@ -310,10 +308,6 @@ instance ToJSON HandshakeError where instance FromJSON HandshakeError where parseJSON = J.genericParseJSON $ sumTypeJSON id -instance Arbitrary TransportError where arbitrary = genericArbitraryU - -instance Arbitrary HandshakeError where arbitrary = genericArbitraryU - -- | SMP encrypted transport error parser. transportErrorP :: Parser TransportError transportErrorP = diff --git a/tests/AgentTests/FunctionalAPITests.hs b/tests/AgentTests/FunctionalAPITests.hs index ab9989bde..8f19c776e 100644 --- a/tests/AgentTests/FunctionalAPITests.hs +++ b/tests/AgentTests/FunctionalAPITests.hs @@ -1161,7 +1161,7 @@ testBatchedSubscriptions nCreate nDel t = do a <- getSMPAgentClient' agentCfg initAgentServers2 testDB b <- getSMPAgentClient' agentCfg initAgentServers2 testDB2 conns <- runServers $ do - conns <- forM [1 .. nCreate :: Int] . const $ makeConnection a b + conns <- replicateM (nCreate :: Int) $ makeConnection a b forM_ conns $ \(aId, bId) -> exchangeGreetings a bId b aId let (aIds', bIds') = unzip $ take nDel conns delete a bIds' diff --git a/tests/AgentTests/NotificationTests.hs b/tests/AgentTests/NotificationTests.hs index 0b1755d02..da9f4c322 100644 --- a/tests/AgentTests/NotificationTests.hs +++ b/tests/AgentTests/NotificationTests.hs @@ -504,7 +504,7 @@ testNotificationsSMPRestartBatch n t APNSMockServer {apnsQ} = do a <- getSMPAgentClient' agentCfg initAgentServers2 testDB b <- getSMPAgentClient' agentCfg initAgentServers2 testDB2 conns <- runServers $ do - conns <- forM [1 .. n :: Int] . const $ makeConnection a b + conns <- replicateM (n :: Int) $ makeConnection a b _ <- registerTestToken a "abcd" NMInstant apnsQ liftIO $ threadDelay 1500000 forM_ conns $ \(aliceId, bobId) -> do diff --git a/tests/CoreTests/ProtocolErrorTests.hs b/tests/CoreTests/ProtocolErrorTests.hs index 39a00eb88..e653ab43a 100644 --- a/tests/CoreTests/ProtocolErrorTests.hs +++ b/tests/CoreTests/ProtocolErrorTests.hs @@ -1,14 +1,19 @@ {-# LANGUAGE LambdaCase #-} {-# LANGUAGE ScopedTypeVariables #-} +{-# OPTIONS_GHC -Wno-orphans #-} module CoreTests.ProtocolErrorTests where import qualified Data.ByteString.Char8 as B import qualified Data.Text as T import Data.Text.Encoding (encodeUtf8) -import Simplex.Messaging.Agent.Protocol (AgentErrorType (..), BrokerErrorType (..)) +import Generic.Random (genericArbitraryU) +import Simplex.FileTransfer.Protocol (XFTPErrorType) +import Simplex.Messaging.Agent.Protocol +import Simplex.Messaging.Encoding import Simplex.Messaging.Encoding.String -import Simplex.Messaging.Parsers (parseAll) +import Simplex.Messaging.Protocol (CommandError, ErrorType) +import Simplex.Messaging.Transport (HandshakeError, TransportError) import Test.Hspec import Test.Hspec.QuickCheck (modifyMaxSuccess) import Test.QuickCheck @@ -16,15 +21,36 @@ import Test.QuickCheck protocolErrorTests :: Spec protocolErrorTests = modifyMaxSuccess (const 1000) $ do describe "errors parsing / serializing" $ do - it "should parse SMP protocol errors" . property $ \(err :: AgentErrorType) -> - errHasSpaces err - || parseAll strP (strEncode err) == Right err + it "should parse SMP protocol errors" . property $ \(err :: ErrorType) -> + smpDecode (smpEncode err) == Right err it "should parse SMP agent errors" . property $ \(err :: AgentErrorType) -> errHasSpaces err - || parseAll strP (strEncode err) == Right err + || strDecode (strEncode err) == Right err where errHasSpaces = \case BROKER srv (RESPONSE e) -> hasSpaces srv || hasSpaces e BROKER srv _ -> hasSpaces srv _ -> False hasSpaces s = ' ' `B.elem` encodeUtf8 (T.pack s) + +instance Arbitrary AgentErrorType where arbitrary = genericArbitraryU + +instance Arbitrary CommandErrorType where arbitrary = genericArbitraryU + +instance Arbitrary ConnectionErrorType where arbitrary = genericArbitraryU + +instance Arbitrary BrokerErrorType where arbitrary = genericArbitraryU + +instance Arbitrary SMPAgentError where arbitrary = genericArbitraryU + +instance Arbitrary AgentCryptoError where arbitrary = genericArbitraryU + +instance Arbitrary ErrorType where arbitrary = genericArbitraryU + +instance Arbitrary CommandError where arbitrary = genericArbitraryU + +instance Arbitrary TransportError where arbitrary = genericArbitraryU + +instance Arbitrary HandshakeError where arbitrary = genericArbitraryU + +instance Arbitrary XFTPErrorType where arbitrary = genericArbitraryU diff --git a/tests/NtfServerTests.hs b/tests/NtfServerTests.hs index d06ededa9..77a4b1945 100644 --- a/tests/NtfServerTests.hs +++ b/tests/NtfServerTests.hs @@ -139,7 +139,6 @@ testNotificationSubscription (ATransport t) = mTs `shouldBe` msgTs (msgBody, "hello") #== "delivered from queue" Resp "6" _ OK <- signSendRecv rh rKey ("6", rId, ACK mId1) - pure () -- replace token let tkn' = DeviceToken PPApnsTest "efgh" RespNtf "7" tId' NROk <- signSendRecvNtf nh tknKey ("7", tId, TRPL tkn')