gameServer/stresstest2.hs
branch0.9.14
changeset 4242 5e3c5fe2cb14
parent 3947 709fdb89f76c
child 4295 1f5604cd99be
equal deleted inserted replaced
4241:835fd7a0e1bf 4242:5e3c5fe2cb14
     4 
     4 
     5 import IO
     5 import IO
     6 import System.IO
     6 import System.IO
     7 import Control.Concurrent
     7 import Control.Concurrent
     8 import Network
     8 import Network
     9 import Control.OldException
     9 import Control.Exception
    10 import Control.Monad
    10 import Control.Monad
    11 import System.Random
    11 import System.Random
    12 
    12 
    13 #if !defined(mingw32_HOST_OS)
    13 #if !defined(mingw32_HOST_OS)
    14 import System.Posix
    14 import System.Posix
    15 #endif
    15 #endif
    16 
    16 
    17 session1 nick room = ["NICK", nick, "", "PROTO", "32", ""]
    17 testing = Control.Exception.handle print $ do
       
    18     delay <- randomRIO (100::Int, 300)
       
    19     threadDelay delay
       
    20     sock <- connectTo "127.0.0.1" (PortNumber 46631)
       
    21     hClose sock
    18 
    22 
    19 
    23 forks i = do
    20 
    24     delay <- randomRIO (50::Int, 190)
    21 testing = Control.OldException.handle print $ do
    25     if i `mod` 10 == 0 then putStr (show i) else putStr "."
    22     putStrLn "Start"
    26     hFlush stdout
    23     sock <- connectTo "127.0.0.1" (PortNumber 46631)
    27     threadDelay delay
    24 
    28     forkIO testing
    25     num1 <- randomRIO (70000::Int, 70100)
    29     forks (i + 1)
    26     num2 <- randomRIO (0::Int, 2)
       
    27     num3 <- randomRIO (0::Int, 5)
       
    28     let nick1 = 'n' : show num1
       
    29     let room1 = 'r' : show num2
       
    30     mapM_ (\x -> hPutStrLn sock x >> hFlush sock >> randomRIO (300::Int, 590) >>= threadDelay) $ session1 nick1 room1
       
    31     mapM_ (\x -> hPutStrLn sock x >> hFlush sock) $ concatMap (\x -> ["CHAT_MSG", show x, ""]) [1..]
       
    32     hClose sock
       
    33     putStrLn "Finish"
       
    34 
       
    35 forks = testing
       
    36 
    30 
    37 main = withSocketsDo $ do
    31 main = withSocketsDo $ do
    38 #if !defined(mingw32_HOST_OS)
    32 #if !defined(mingw32_HOST_OS)
    39     installHandler sigPIPE Ignore Nothing;
    33     installHandler sigPIPE Ignore Nothing;
    40 #endif
    34 #endif
    41     forks
    35     forks 1