-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Doing a parallel load test #32
Comments
You will need to run your monad stack. Here is one for Yesod's test monad. -- | Lifted version of 'mapConcurrently'. The state from
-- of all inner computations are discarded.
mapConcurrentlyTest :: Traversable t => (a -> YesodExample site b) -> t a -> YesodExample site (t b)
mapConcurrentlyTest f xs =
StateT $ \s -> (, s) <$> mapConcurrently (\x -> evalStateT (f x) s) xs |
@begriffs sorry for replying late. By default {-# LANGUAGE OverloadedStrings #-}
module Main (main) where
import Test.Hspec
import Test.Hspec.Wai
import Test.Hspec.Wai.Http (withServer)
import Test.Hspec.Wai.Internal
import Control.Monad.Trans.Reader
import Control.Concurrent.Async
import Network.Wai (Application)
import qualified Web.Scotty as S
main :: IO ()
main = hspec spec
app :: IO Application
app = S.scottyApp $ do
S.get "/foo" $ do
S.text "hello"
spec :: Spec
spec = withServer app $ do
describe "GET /" $ do
it "can handle concurrent requests" $ do
req <- WaiSession ask
xs <- liftIO $ do
mapConcurrently (const $ req "GET" "/foo" [] "") [1..100]
mapM_ ((`shouldRespondWith` "hello") . return) xs I don't have many free cycles I can spent on #31, help would be much welcome. |
@jwiegley found another way to do this: instance MonadBaseControl IO WaiSession where
type StM WaiSession a = StM Session a
liftBaseWith f = WaiSession $
liftBaseWith $ \runInBase ->
f $ \k -> runInBase (unWaiSession k)
restoreM = WaiSession . restoreM
{-# INLINE liftBaseWith #-}
{-# INLINE restoreM #-}
instance MonadBase IO WaiSession where
liftBase = liftIO This allows me to make a test like this concurrently :: Int -> WaiExpectation -> WaiExpectation
concurrently times = liftBaseDiscard go
where
go test = void $ mapConcurrently (const test) [1..times]
spec :: SpecWith Application
spec =
describe "Queryiny in parallel" $
it "gets lots of foo" $
concurrently 10 $
get "/foo" `shouldRespondWith` 200 Right now the |
A user discovered a problem in my web server that causes it to freeze under certain types of concurrent traffic. I'm trying to model the situation in a test but having trouble with the types.
My problem is that once I'm inside of the concurrent map I'm in IO and I don't know how to get back into WaiSession in order to make a get request. Is it possible to do this?
The text was updated successfully, but these errors were encountered: