yandex-tank/Tests/PhantomPluginTest.py

182 lines
6.7 KiB
Python
Raw Normal View History

2012-09-12 13:18:58 +00:00
import os
import time
import unittest
2014-02-11 10:49:16 +00:00
from Tank.Plugins.Aggregator import AggregatorPlugin, SecondAggregateData
from Tank.Plugins.Phantom import PhantomPlugin, PhantomReader
from Tests.TankTests import TankTestCase
2013-01-28 13:20:57 +00:00
from Tank.Plugins.PhantomUtils import StepperWrapper
2012-09-12 13:18:58 +00:00
2014-02-11 10:49:16 +00:00
class PhantomPluginTestCase(TankTestCase):
2012-09-12 13:18:58 +00:00
def setUp(self):
2012-09-21 11:47:37 +00:00
core = self.get_core()
2012-09-12 13:18:58 +00:00
core.load_configs(['config/phantom.conf'])
core.load_plugins()
core.plugins_configure()
2012-09-12 13:18:58 +00:00
core.plugins_prepare_test()
self.foo = PhantomPlugin(core)
def tearDown(self):
del self.foo
self.foo = None
if os.path.exists("ready_conf_phout.txt"):
os.remove("ready_conf_phout.txt")
def test_run(self):
self.foo.core.set_option(PhantomPlugin.SECTION, "config", '')
self.foo.configure()
self.foo.prepare_test()
2012-09-21 08:41:02 +00:00
reader = PhantomReader(AggregatorPlugin(self.foo.core), self.foo)
2014-02-11 10:49:16 +00:00
reader.phout_file = self.foo.phantom.phout_file
2012-09-12 13:18:58 +00:00
self.foo.start_test()
2014-02-11 10:49:16 +00:00
2012-09-12 13:18:58 +00:00
while self.foo.is_test_finished() < 0:
self.foo.log.debug("Not finished")
2012-09-21 08:41:02 +00:00
reader.check_open_files()
reader.get_next_sample(False)
2012-09-12 13:18:58 +00:00
time.sleep(1)
2012-09-12 15:55:59 +00:00
if self.foo.is_test_finished() != 0:
2012-09-12 13:18:58 +00:00
raise RuntimeError("RC: %s" % self.foo.is_test_finished())
self.foo.end_test(0)
2012-09-21 08:41:02 +00:00
reader.get_next_sample(True)
2012-09-12 13:18:58 +00:00
2013-01-24 13:45:45 +00:00
2012-09-12 13:18:58 +00:00
def test_run_ready_conf(self):
2013-01-24 13:56:34 +00:00
self.foo.core.set_option(PhantomPlugin.SECTION, "config", 'data/phantom_ready.conf')
2012-09-12 13:18:58 +00:00
self.foo.core.add_artifact_file("ready_conf_phout.txt")
self.foo.configure()
self.foo.prepare_test()
self.foo.start_test()
while self.foo.is_test_finished() < 0:
self.foo.log.debug("Not finished")
time.sleep(1)
2012-09-12 15:55:59 +00:00
if self.foo.is_test_finished() != 0:
2012-09-12 13:18:58 +00:00
raise RuntimeError("RC: %s" % self.foo.is_test_finished())
2014-02-11 10:49:16 +00:00
self.assertTrue(os.path.getsize("ready_conf_phout.txt") > 0)
2012-09-12 13:18:58 +00:00
self.foo.end_test(0)
2014-02-11 10:49:16 +00:00
def test_run_uri_style(self):
self.foo.set_option("ammofile", "")
self.foo.set_option("uris", "/")
self.foo.configure()
self.foo.prepare_test()
self.foo.start_test()
while self.foo.is_test_finished() < 0:
self.foo.log.debug("Not finished")
time.sleep(1)
if self.foo.is_test_finished() != 0:
raise RuntimeError("RC: %s" % self.foo.is_test_finished())
self.foo.end_test(0)
2012-09-12 13:18:58 +00:00
def test_run_interrupt(self):
self.foo.configure()
self.foo.prepare_test()
self.foo.start_test()
time.sleep(2)
self.foo.end_test(0)
2012-09-13 15:46:36 +00:00
def test_run_stepper_cache(self):
self.foo.configure()
self.foo.prepare_test()
self.foo.prepare_test()
2014-02-11 10:49:16 +00:00
2012-09-12 13:18:58 +00:00
def test_domain_name(self):
self.foo.core.set_option('phantom', 'address', 'yandex.ru')
self.foo.configure()
2012-09-12 13:18:58 +00:00
def test_domain_name_fail(self):
self.foo.core.set_option('phantom', 'address', 'ya.ru')
try:
self.foo.configure()
raise RuntimeError()
except:
pass
2014-02-11 10:49:16 +00:00
2012-09-21 08:41:02 +00:00
def test_reader(self):
2012-09-21 10:15:06 +00:00
self.foo.phantom_start_time = time.time()
2012-09-21 08:41:02 +00:00
reader = PhantomReader(AggregatorPlugin(self.foo.core), self.foo)
2013-01-24 13:45:45 +00:00
reader.phout_file = 'data/phout_timeout_mix.txt'
2012-09-21 08:41:02 +00:00
reader.check_open_files()
2014-02-11 10:49:16 +00:00
2012-09-21 10:15:06 +00:00
data = reader.get_next_sample(False)
while data:
times_sum = 0
for timing in data.overall.times_dist:
times_sum += timing['count']
2013-01-28 12:28:49 +00:00
# FIXME: kinda strange problem here
#self.assertEquals(sum(data.overall.net_codes.values()), times_sum)
2012-09-21 10:15:06 +00:00
data = reader.get_next_sample(False)
2013-01-24 13:45:45 +00:00
def test_stepper_no_steps(self):
self.foo.core.set_option('phantom', 'rps_schedule', '')
self.foo.core.set_option('phantom', 'instances_schedule', '')
2013-01-28 13:20:57 +00:00
wrapper = StepperWrapper(self.foo.core, PhantomPlugin.SECTION)
wrapper.ammo_file = 'data/dummy.ammo'
wrapper.prepare_stepper()
wrapper.prepare_stepper()
2014-02-11 10:49:16 +00:00
def test_stepper_instances_sched(self):
self.foo.core.set_option('phantom', 'instances', '1000')
self.foo.core.set_option('phantom', 'rps_schedule', '')
self.foo.core.set_option('phantom', 'instances_schedule', 'line(1,100,1m)')
2014-02-20 13:27:39 +00:00
self.foo.core.set_option('phantom', 'use_caching', '0')
self.foo.core.set_option('phantom', 'ammo_file', 'data/dummy.ammo')
2014-02-11 10:49:16 +00:00
wrapper = StepperWrapper(self.foo.core, PhantomPlugin.SECTION)
2014-02-20 13:27:39 +00:00
wrapper.read_config()
2014-02-11 10:49:16 +00:00
wrapper.prepare_stepper()
self.assertEqual(100, wrapper.instances)
2014-02-20 13:47:51 +00:00
def test_cached_stepper_instances_sched(self):
# Making cache file
self.foo.core.set_option('phantom', 'instances', '1000')
self.foo.core.set_option('phantom', 'rps_schedule', '')
self.foo.core.set_option('phantom', 'instances_schedule', 'line(1,100,1m)')
self.foo.core.set_option('phantom', 'ammo_file', 'data/dummy.ammo')
wrapper = StepperWrapper(self.foo.core, PhantomPlugin.SECTION)
wrapper.read_config()
wrapper.prepare_stepper()
self.tearDown()
self.setUp()
self.foo.core.set_option('phantom', 'instances', '1000')
self.foo.core.set_option('phantom', 'rps_schedule', '')
self.foo.core.set_option('phantom', 'instances_schedule', 'line(1,100,1m)')
self.foo.core.set_option('phantom', 'ammo_file', 'data/dummy.ammo')
wrapper = StepperWrapper(self.foo.core, PhantomPlugin.SECTION)
wrapper.read_config()
wrapper.prepare_stepper()
self.assertEqual(100, wrapper.instances)
def test_phout_import(self):
self.foo.core.set_option('phantom', 'phout_file', 'data/phout_timeout_mix.txt')
self.foo.core.set_option('phantom', 'instances', '1')
self.foo.core.set_option('phantom', 'ammo_count', '1')
self.foo.configure()
self.foo.prepare_test()
self.foo.start_test()
self.assertEqual(self.foo.is_test_finished(), -1)
sec = SecondAggregateData()
sec.overall.RPS = 1
self.foo.aggregate_second(sec)
self.assertEqual(self.foo.is_test_finished(), -1)
self.assertEqual(self.foo.is_test_finished(), 0)
self.foo.end_test(0)
self.foo.post_process(0)
2014-02-11 10:49:16 +00:00
2014-02-21 14:35:44 +00:00
def test_cached_stpd_info(self):
self.foo.core.set_option('phantom', 'stpd_file', 'data/dummy.ammo.stpd')
wrapper = StepperWrapper(self.foo.core, PhantomPlugin.SECTION)
wrapper.read_config()
wrapper.prepare_stepper()
self.assertEqual(10, wrapper.instances)
self.assertEqual(60, wrapper.duration)
2014-02-11 10:49:16 +00:00
2012-09-12 13:18:58 +00:00
if __name__ == '__main__':
unittest.main()