~ubuntu-branches/ubuntu/utopic/hedgewars/utopic

« back to all changes in this revision

Viewing changes to gameServer/stresstest.hs

  • Committer: Package Import Robot
  • Author(s): Dmitry E. Oboukhov
  • Date: 2011-09-23 10:16:55 UTC
  • mto: (19.1.2 sid) (1.3.1) (21.1.3 experimental)
  • mto: This revision was merged to the branch mainline in revision 18.
  • Revision ID: package-import@ubuntu.com-20110923101655-yrajfbj5b0v4asbt
Tags: upstream-0.9.16
ImportĀ upstreamĀ versionĀ 0.9.16

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 
3
3
module Main where
4
4
 
5
 
import IO
6
5
import System.IO
 
6
import System.IO.Error
7
7
import Control.Concurrent
8
8
import Network
9
 
import Control.Exception
 
9
import Control.OldException
10
10
import Control.Monad
11
11
import System.Random
12
12
 
14
14
import System.Posix
15
15
#endif
16
16
 
17
 
session1 nick room = ["NICK", nick, "", "PROTO", "24", "", "CHAT", "lobby 1", "", "CREATE", room, "", "CHAT", "room 1", "", "QUIT", "bye-bye", ""]
18
 
session2 nick room = ["NICK", nick, "", "PROTO", "24", "", "LIST", "", "JOIN", room, "", "CHAT", "room 2", "", "PART", "", "CHAT", "lobby after part", "", "QUIT", "bye-bye", ""]
19
 
session3 nick room = ["NICK", nick, "", "PROTO", "24", "", "LIST", "", "JOIN", room, "", "CHAT", "room 2", "", "QUIT", "bye-bye", ""]
 
17
session 0 nick room = ["NICK", nick, "", "PROTO", "38", "", "PING", "", "CHAT", "lobby 1", "", "PONG", "", "CREATE_ROOM", room, "", "CHAT", "room 1", "", "QUIT", "creator", ""]
 
18
session 1 nick room = ["NICK", nick, "", "PROTO", "38", "", "LIST", "", "JOIN_ROOM", room, "", "PONG", "", "CHAT", "room 2", "", "PART", "", "CHAT", "lobby after part", "", "QUIT", "part-quit", ""]
 
19
session 2 nick room = ["NICK", nick, "", "PROTO", "38", "", "LIST", "", "JOIN_ROOM", room, "", "PONG", "", "CHAT", "room 2", "", "QUIT", "quit", ""]
 
20
session 3 nick room = ["NICK", nick, "", "PROTO", "38", "", "CHAT", "lobby 1", "", "CREATE_ROOM", room, "", "", "PONG", "CHAT", "room 1", "", "PART", "creator", "", "QUIT", "part-quit", ""]
20
21
 
21
22
emulateSession sock s = do
22
 
    mapM_ (\x -> hPutStrLn sock x >> hFlush sock >> randomRIO (50000::Int, 90000) >>= threadDelay) s
 
23
    mapM_ (\x -> hPutStrLn sock x >> hFlush sock >> randomRIO (100000::Int, 600000) >>= threadDelay) s
23
24
    hFlush sock
24
25
    threadDelay 225000
25
26
 
26
 
testing = Control.Exception.handle print $ do
 
27
testing = Control.OldException.handle print $ do
27
28
    putStrLn "Start"
28
29
    sock <- connectTo "127.0.0.1" (PortNumber 46631)
29
30
 
30
 
    num1 <- randomRIO (70000::Int, 70100)
31
 
    num2 <- randomRIO (0::Int, 2)
32
 
    num3 <- randomRIO (0::Int, 5)
33
 
    let nick1 = show num1
34
 
    let room1 = show num2
35
 
    case num2 of 
36
 
        0 -> emulateSession sock $ session1 nick1 room1
37
 
        1 -> emulateSession sock $ session2 nick1 room1
38
 
        2 -> emulateSession sock $ session3 nick1 room1
 
31
    num1 <- randomRIO (100000::Int, 101000)
 
32
    num2 <- randomRIO (0::Int, 3)
 
33
    num3 <- randomRIO (0::Int, 1000)
 
34
    let nick1 = 'n' : show num1
 
35
    let room1 = 'r' : show num3
 
36
    emulateSession sock $ session num2 nick1 room1
39
37
    hClose sock
40
38
    putStrLn "Finish"
41
39
 
42
40
forks = forever $ do
43
 
    delay <- randomRIO (10000::Int, 19000)
44
 
    threadDelay delay
45
 
    forkIO testing
 
41
    delays <- randomRIO (0::Int, 2)
 
42
    replicateM 200 $
 
43
        do
 
44
        delay <- randomRIO (delays * 20000::Int, delays * 20000 + 50000)
 
45
        threadDelay delay
 
46
        forkIO testing
46
47
 
47
48
main = withSocketsDo $ do
48
49
#if !defined(mingw32_HOST_OS)