Example #1
0
    def test_load(self):
        parser = LoadParser()
        result = parser.parse("""
create session with weight 1 as 'test1':
    get '/foo'

create load:                
    spawn users every 4 seconds for 10 minutes up to 100 users
    spawn users every 10 seconds for 50 minutes

""")
    
        self.assertEqual(len(result.load.spawns), 2)
        spawn1, spawn2 = result.load.spawns
        self.assertEqual(spawn1.user_time, "4")
        self.assertEqual(spawn1.user_time_units, "seconds")
        self.assertEqual(spawn1.max_duration, "10")
        self.assertEqual(spawn1.max_duration_units, "minutes")
        self.assertEqual(spawn1.max_users, "100")

        self.assertEqual(spawn2.user_time, "10")
        self.assertEqual(spawn2.user_time_units, "seconds")
        self.assertEqual(spawn2.max_duration, "50")
        self.assertEqual(spawn2.max_duration_units, "minutes")
        self.assertEqual(spawn2.max_users, "")
Example #2
0
    def test_session(self):
        parser = LoadParser()
        result = parser.parse("""
create session with weight 4 as 'test1':
    get "/api"
    delete '/view/view1'
    post '/view?name=view2&value=foo'
        ensure match /^{"success": "View 'view2' created"}$/
        ensure match /success/


create session with weight 1 as 'test2':
    get '/foo'

create load:
    spawn users every 1 seconds for 1 seconds
""")
        
        self.assertEqual(len(result.sessions), 2)
        session = result.sessions[0]
        self.assertEqual(session.weight, "4")
        self.assertEqual(session.name, "test1")        
        self.assertEqual(len(session.actions), 3)
        get_action = session.actions[0]
        self.assertEqual(get_action.method, "get")
        self.assertEqual(get_action.url, "/api")
        self.assertEqual(get_action.type, "get")

        delete_action = session.actions[1]
        self.assertEqual(delete_action.method, "delete")
        self.assertEqual(delete_action.url, "/view/view1")
        post_action = session.actions[2]
        self.assertEqual(len(post_action.matches), 2)
        match = post_action.matches[1]
        self.assertEqual(match.regex, "success")
Example #3
0
    def test_no_user_count(self):
        parser = LoadParser()
        code = """
create session with weight 1 as 'test_var':
    get '/foo'
create load:                
    spawn 1 users every 2 seconds for 3 seconds
"""
        with self.assertRaises(Exception):
            result = parser.parse(code)
Example #4
0
    def test_var_no_unique_string(self):
        parser = LoadParser()
        code = """
create session with weight 1 as 'test_var':
    var user_name is a unique string of length 5 to 10
create load:                
    spawn users every 1 seconds for 1 seconds
"""
        with self.assertRaises(Exception):
            result = parser.parse(code)
Example #5
0
    def test_paue_no_float(self):
        parser = LoadParser()
        code = """
create session with weight 1 as 'test_var':
    pause between 1.5 and 3.2 seconds
create load:                
    spawn users every 1 seconds for 1 seconds
"""
        with self.assertRaises(Exception):
            result = parser.parse(code)
Example #6
0
    def test_get_all(self):
        parser = LoadParser()
        result = parser.parse("""
create session with weight 1 as 'test_file':
    post '/create' with data 'foo=bar&monkey=shoe'
create load:                
    spawn users every 1 seconds for 1 seconds
""")

        actions = result.sessions[0].actions
        post = actions[0]
        self.assertEqual(post.data, "foo=bar&monkey=shoe")
Example #7
0
    def test_comment(self):
        parser = LoadParser()
        result = parser.parse("""
# Here is a big comment
# That spans multiple lines

create session with weight 1 as 'test1':
    get '/foo'

create load:                
    spawn users every 1 seconds for 1 seconds
""")
        # as long as we got here and the above didn't die, we're good
        self.assertTrue(True) 
Example #8
0
    def test_get_all(self):
        parser = LoadParser()
        result = parser.parse("""
create session with weight 1 as 'test_file':
    get all '/full'
    get '/single/page'
create load:                
    spawn users every 1 seconds for 1 seconds
""")

        actions = result.sessions[0].actions
        full, single = actions[0], actions[1]
        self.assertTrue(full.all)
        self.assertFalse(single.all)
Example #9
0
    def test_pause(self):
        parser = LoadParser()
        result = parser.parse("""
create session with weight 1 as 'test1':
    get '/bar'
    pause between 1 and 3 seconds
    get '/foo'

create load:                
    spawn users every 1 seconds for 1 seconds
""")
        session = result.sessions[0]
        self.assertEquals(len(session.actions), 3)
        pause_action = session.actions[1]
        self.assertEqual(pause_action.type, "pause")
        self.assertEqual(pause_action.lower_time, "1")
        self.assertEqual(pause_action.upper_time, "3")
Example #10
0
    def test_file(self):

        parser = LoadParser()
        result = parser.parse("""
create session with weight 1 as 'test_file':
    using view_name, view_value from 'views.csv' randomly
    post '/view/create?name=$view_name&value=$view_value'
create load:                
    spawn users every 1 seconds for 1 seconds
""")
        
        session = result.sessions[0]
        self.assertEquals(len(session.actions), 2)
        using = session.actions[0]
        self.assertEquals(using.type, "using")
        self.assertEquals(using.vars.asList(), ["view_name", "view_value"])
        self.assertEquals(using.filename, "views.csv")
        self.assertEquals(using.ordering, "randomly")
Example #11
0
    def test_var(self):
        parser = LoadParser()
        result = parser.parse("""
create session with weight 1 as 'test_var':
    var pin is a unique number from 1000 to 9999
    var user_name is a random string of length 5
    var password is a random string of length 15
    post '/user/create?user_name=$user_name&password=$password&pin=$pin'

create load:                
    spawn users every 1 seconds for 1 seconds
""")
        session = result.sessions[0]
        self.assertEquals(len(session.actions), 4)
        self.assertEqual(session.actions[0].asDict(), dict(type="var", 
            name="pin", ordering="unique", data_type="number", 
            min="1000", max="9999"))
        self.assertEqual(session.actions[1].asDict(), dict(type="var", 
            name="user_name", ordering="random", data_type="string", 
            length="5"))
        self.assertEqual(session.actions[2].asDict(), dict(type="var", 
            name="password", ordering="random", data_type="string", 
            length="15"))
Example #12
0
import os
from tsunami import TsungBuilder
from tsunami import LoadParser

if __name__ == '__main__':
    cmd_parser = argparse.ArgumentParser('Load Testing DSL to Tsung Parser')

    cmd_parser.add_argument('--from', type=str, 
        help='.lt source file', required=True)
    cmd_parser.add_argument('--to', type=str, help='tsung .xml output file', 
        required=True)
    cmd_parser.add_argument('--output_path', type=str,
        help='path to write suplimentally generated files')

    
    args = cmd_parser.parse_args()

    # 'from' is a reserved word, so we have to use this extended syntax
    # instead of args.from
    from_file = args.__getattribute__("from") 
    with open(from_file) as f:
        code = f.read()
    lp = LoadParser()
    config = lp.parse(code) 

    if not args.output_path:
        args.output_path = os.path.splitext(args.to)[0]
    tb = TsungBuilder(config, args.output_path)
    with open(args.to, "w+") as f:
        f.write(tb.get_xml())