[FunkLoad] Random tests for benchmarking

I've recently started using FunkLoad to do benchmarking of websites. It works quite okay and I love the fact that it's Python, since that's my language of choice.

One thing that kept bugging me was that since FunkLoad is more a unittester, it can by default only run a single run multiple times against a site. That won't do. You want several different kinds of users visiting your website when you're benchmarking. But since everything is Python, I was able to solve that like this:

-- coding: iso-8859-15 --

"""loadtest FunkLoad test

$Id: $

"""

import unittest, random, sys

from funkload.FunkLoadTestCase import FunkLoadTestCase

from webunit.utility import Upload

from funkload.utils import Data

from funkload.utils import xmlrpc_get_credential

class LoadTest(FunkLoadTestCase): """ Loadtest for website.

This test use a configuration file LoadTest.conf.
"""

def setUp(self):
    """Setting up test."""
    self.logd("setUp")
    self.server_url = self.conf_get('main', 'url')

def doTest(self):
    # Picks a test at random
    tests = ["8081","8082","8083","8084","8085","8086"]
    rnd = random.choice(tests)
    return getattr(self, "test_"+str(rnd))()

def test_8081(self):
    # The description should be set in the configuration file
    server_url = self.server_url
    # begin of test ---------------------------------------------
    # end of test---------------------------------------------

def test_8082(self):
    # The description should be set in the configuration file
    server_url = self.server_url
    # begin of test ---------------------------------------------
    # end of test---------------------------------------------

(I left out the test themselves, but I'm sure you can find where to place them.)

The recorded tests are in the same class, and they're called test_8081, test_8082, etc. up to test_8086. These corresponded to the proxy ports on which fl-record was listening when the session was recorded. Line 27 makes sure that the test that was chosen gets run.

You can of course expand this as much as you like, for example adding weights for certain tests. Kinda neat, python.

Comments

Comments powered by Disqus