Skip to content

Commit

Permalink
Issue #26: implement @effectfully's feedback on testing a sequence of…
Browse files Browse the repository at this point in the history
… requests
  • Loading branch information
Marko Dimjašević committed Nov 26, 2019
1 parent 5de5ff8 commit ae9a2f2
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions test/Fencer/Server/Test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ where

import BasePrelude

import Control.Monad (replicateM_)
import Data.ByteString (ByteString)
import qualified Data.Vector as Vector
import GHC.Exts (fromList)
Expand Down Expand Up @@ -103,11 +104,15 @@ test_serverResponseNoRules =
server <- serverIO
atomically (setRules (serverAppState server) []) -- an empty rule list
withService server $ \service -> do
response <- Proto.rateLimitServiceShouldRateLimit service $
Grpc.ClientNormalRequest request 1 mempty
expectSuccess
(expectedResponse, Grpc.StatusOk)
response
let communicationRoundtrip = do
response <- Proto.rateLimitServiceShouldRateLimit service $
Grpc.ClientNormalRequest request 1 mempty
expectSuccess
(genericOKResponse, Grpc.StatusOk)
response
-- Test that having a sequence of requests does not change the
-- server state
replicateM_ 5 communicationRoundtrip
where
request :: Proto.RateLimitRequest
request = Proto.RateLimitRequest
Expand All @@ -120,20 +125,6 @@ test_serverResponseNoRules =
, Proto.rateLimitRequestHitsAddend = 0
}

expectedResponse :: Proto.RateLimitResponse
expectedResponse = Proto.RateLimitResponse
{ rateLimitResponseOverallCode =
Enumerated $ Right Proto.RateLimitResponse_CodeOK
, rateLimitResponseStatuses = Vector.singleton
Proto.RateLimitResponse_DescriptorStatus
{ rateLimitResponse_DescriptorStatusCode =
Enumerated $ Right Proto.RateLimitResponse_CodeOK
, rateLimitResponse_DescriptorStatusCurrentLimit = Nothing
, rateLimitResponse_DescriptorStatusLimitRemaining = 0
}
, rateLimitResponseHeaders = Vector.empty
}

-- | Test that requests with an empty domain name result in an error.
--
-- This behavior matches @lyft/ratelimit@.
Expand Down

0 comments on commit ae9a2f2

Please sign in to comment.