Fix unit tests

This commit is contained in:
Andrey Pohilko 2012-10-26 14:26:45 +04:00
parent 59f17269a9
commit 39c2108cd9
2 changed files with 12 additions and 4 deletions

View File

@ -14,6 +14,7 @@ class JMeterPlugin(AbstractPlugin):
''' JMeter tank plugin ''' ''' JMeter tank plugin '''
SECTION = 'jmeter' SECTION = 'jmeter'
def __init__(self, core): def __init__(self, core):
AbstractPlugin.__init__(self, core) AbstractPlugin.__init__(self, core)
self.jmeter_process = None self.jmeter_process = None
@ -25,9 +26,11 @@ class JMeterPlugin(AbstractPlugin):
self.jmeter_path = None self.jmeter_path = None
self.jmeter_log = None self.jmeter_log = None
@staticmethod @staticmethod
def get_key(): def get_key():
return __file__ return __file__
def configure(self): def configure(self):
self.original_jmx = self.get_option("jmx") self.original_jmx = self.get_option("jmx")
@ -41,6 +44,7 @@ class JMeterPlugin(AbstractPlugin):
self.jmeter_log = self.core.mkstemp('.log', 'jmeter_') self.jmeter_log = self.core.mkstemp('.log', 'jmeter_')
self.core.add_artifact_file(self.jmeter_log, True) self.core.add_artifact_file(self.jmeter_log, True)
def prepare_test(self): def prepare_test(self):
self.args = [self.jmeter_path, "-n", "-t", self.jmx, '-j', self.jmeter_log, '-Jjmeter.save.saveservice.default_delimiter=\\t'] self.args = [self.jmeter_path, "-n", "-t", self.jmx, '-j', self.jmeter_log, '-Jjmeter.save.saveservice.default_delimiter=\\t']
self.args += tankcore.splitstring(self.user_args) self.args += tankcore.splitstring(self.user_args)
@ -123,6 +127,7 @@ class JMeterPlugin(AbstractPlugin):
return new_file return new_file
class JMeterReader(AbstractReader): class JMeterReader(AbstractReader):
''' JTL files reader ''' ''' JTL files reader '''
KNOWN_EXC = { KNOWN_EXC = {

View File

@ -44,7 +44,7 @@ class Custom_TestCase(unittest.TestCase):
def test_custom_nodiff(self): def test_custom_nodiff(self):
tail_fd, tailfile = tempfile.mkstemp() tail_fd, tailfile = tempfile.mkstemp()
tail = ["%s:%s:%s" % (base64.b64encode('lbl'), base64.b64encode(tailfile), 0)] tail = ["%s:%s:%s" % (base64.b64encode('lbl'), base64.b64encode(tailfile), 0)]
call = ['ZGlmZkV4:aWZjb25maWcgLXMgZXRoMCB8IGF3ayAnJDE9PSJldGgwIiB7cHJpbnQgJDR9Jw==:0'] call = ["%s:%s:%s" % (base64.b64encode('lbl2'), base64.b64encode("date +%s"), 0)]
self.foo = Custom(call, tail) self.foo = Custom(call, tail)
x = self.foo.check() x = self.foo.check()
@ -59,7 +59,7 @@ class Custom_TestCase(unittest.TestCase):
self.assertNotEquals(x[1], y[1]) self.assertNotEquals(x[1], y[1])
self.assertEquals(tailval, y[0]) self.assertEquals(tailval, y[0])
time.sleep(0.5) time.sleep(2)
tailval = str(time.time()) tailval = str(time.time())
os.write(tail_fd, "%s\n" % tailval) os.write(tail_fd, "%s\n" % tailval)
z = self.foo.check() z = self.foo.check()
@ -67,10 +67,13 @@ class Custom_TestCase(unittest.TestCase):
self.assertNotEquals(y[1], z[1]) self.assertNotEquals(y[1], z[1])
def test_custom_fail(self): def test_custom_fail(self):
custom_config = {'tail': [], 'call': ['cXVlcnkgY291bnQ=:cXVlcnlfY2xhc3NpZnlfY2xpZW50IGZzdGF0cyB8IGdyZXAgY2xhc3MtY21kIHwgY3V0IC1mIDM=:1']} tail = ["%s:%s:%s" % (base64.b64encode('lbl'), base64.b64encode("notexistent"), 0)]
self.foo = Custom(**custom_config) call = ["%s:%s:%s" % (base64.b64encode('lbl2'), base64.b64encode("notexistent"), 0)]
self.foo = Custom(call, tail)
x = self.foo.check() x = self.foo.check()
self.assertEquals("0", x[0])
self.assertEquals("0", x[1])
def test_custom_fail2(self): def test_custom_fail2(self):
custom_config = {'tail': [], 'call': ['TnVtUGhyYXNlcw==:Y2F0IC92YXIvdG1wL3N0YXQx:0']} custom_config = {'tail': [], 'call': ['TnVtUGhyYXNlcw==:Y2F0IC92YXIvdG1wL3N0YXQx:0']}