def test_load_modification(self): self.configure({ "execution": { "concurrency": 50, "hold-for": "30s", "scenario": { "script": get_res_path("http_simple.xml"), } } }) self.obj.settings.merge({ "path": get_res_path(TOOL_NAME), }) self.obj.prepare() original_config = TsungConfig(None) original_config.load(get_res_path("http_simple.xml")) original_load = original_config.find('//tsung/load')[0] modified_config = TsungConfig(None) modified_config.load(self.obj.tsung_config) loads = modified_config.find('//tsung/load') self.assertEqual(len(loads), 1) modified_load = loads[0] self.assertNotEqual(etree.tostring(original_load), etree.tostring(modified_load)) self.assertEqual(modified_load.get('duration'), '30')
def test_requests_headers(self): self.obj.execution.merge({ "concurrency": 50, "hold-for": "30s", "scenario": { "default-address": "http://example.com", "headers": { "X-Answer": "42", }, "requests": [{ "url": "/", "headers": { "X-Jedi": "Luke Skywalker", }, }], } }) self.obj.settings.merge({ "path": get_res_path(TOOL_NAME), }) self.obj.prepare() config = TsungConfig(None) config.load(self.obj.tsung_config) headers = config.find('//http/http_header') self.assertEqual(len(headers), 2) headers_list = [(h.get('name'), h.get('value')) for h in headers] self.assertIn(("X-Jedi", "Luke Skywalker"), headers_list) self.assertIn(("X-Answer", "42"), headers_list)
def test_sessions_thinktime(self): obj = TsungExecutor() obj.engine = EngineEmul() obj.execution.merge({ "concurrency": 50, "hold-for": "30s", "scenario": { "default-address": "http://example.com", "requests": [{ "url": "/", "think-time": "1s", }, { "url": "/reserve.php", "think-time": "2s", }], } }) obj.settings.merge({"path": get_res_path(TOOL_NAME),}) obj.prepare() config = TsungConfig(None) config.load(obj.tsung_config) thinktimes = config.find('//thinktime') self.assertEqual(len(thinktimes), 2) self.assertEqual(thinktimes[0].get("value"), "1") self.assertEqual(thinktimes[1].get("value"), "2")
def test_requests_headers(self): self.obj.execution.merge({ "concurrency": 50, "hold-for": "30s", "scenario": { "default-address": "http://example.com", "headers": { "X-Answer": "42", }, "requests": [{ "url": "/", "headers": { "X-Jedi": "Luke Skywalker", }, }], } }) self.obj.settings.merge({"path": get_res_path(TOOL_NAME),}) self.obj.prepare() config = TsungConfig(None) config.load(self.obj.tsung_config) headers = config.find('//http/http_header') self.assertEqual(len(headers), 2) headers_list = [(h.get('name'), h.get('value')) for h in headers] self.assertIn(("X-Jedi", "Luke Skywalker"), headers_list) self.assertIn(("X-Answer", "42"), headers_list)
def test_sessions_thinktime(self): self.obj.execution.merge({ "concurrency": 50, "hold-for": "30s", "scenario": { "default-address": "http://example.com", "requests": [{ "url": "/", "think-time": "1s", }, { "url": "/reserve.php", "think-time": "2s", }], } }) self.obj.settings.merge({ "path": get_res_path(TOOL_NAME), }) self.obj.prepare() config = TsungConfig(None) config.load(self.obj.tsung_config) thinktimes = config.find('//thinktime') self.assertEqual(len(thinktimes), 2) self.assertEqual(thinktimes[0].get("value"), "1") self.assertEqual(thinktimes[1].get("value"), "2")
def test_requests_custom(self): self.obj.execution.merge({ "concurrency": 50, "hold-for": "30s", "scenario": { "default-address": "http://example.com", "requests": [{ "url": "/", "think-time": "1s", "method": "GET" }, { "url": "/reserve.php", "think-time": "2s", "method": "POST", "body": "123", }, { "url": "/reserve.php", "think-time": "3s", "method": "PUT", "body-file": get_res_path("http_simple.xml"), }], } }) self.obj.settings.merge({"path": get_res_path(TOOL_NAME),}) self.obj.prepare() config = TsungConfig(None) config.load(self.obj.tsung_config) urls = config.find('//http') self.assertEqual(len(urls), 3) self.assertEqual(urls[0].get("method"), "GET") self.assertEqual(urls[1].get("method"), "POST") self.assertEqual(urls[1].get("contents"), "123") self.assertEqual(urls[2].get("method"), "PUT") self.assertEqual(urls[2].get("contents"), open(get_res_path('http_simple.xml')).read())
def test_requests_custom(self): self.obj.execution.merge({ "concurrency": 50, "hold-for": "30s", "scenario": { "default-address": "http://example.com", "requests": [{ "url": "/", "think-time": "1s", "method": "GET" }, { "url": "/reserve.php", "think-time": "2s", "method": "POST", "body": "123", }, { "url": "/reserve.php", "think-time": "3s", "method": "PUT", "body-file": get_res_path("http_simple.xml"), }], } }) self.obj.settings.merge({"path": get_res_path(TOOL_NAME),}) self.obj.prepare() config = TsungConfig(None) config.load(self.obj.tsung_config) urls = config.find('//http') self.assertEqual(len(urls), 3) self.assertEqual(urls[0].get("method"), "GET") self.assertEqual(urls[1].get("method"), "POST") self.assertEqual(urls[1].get("contents"), "123") self.assertEqual(urls[2].get("method"), "PUT") self.assertEqual(urls[2].get("contents"), open(get_res_path('http_simple.xml')).read())
def test_no_load_no_modication(self): # if load profile is not specified - original tsung config's <load> shouldn't be modified self.obj.execution.merge({ "scenario": { "script": get_res_path("http_simple.xml"), } }) self.obj.settings.merge({"path": get_res_path(TOOL_NAME),}) self.obj.prepare() original_config = TsungConfig(None) original_config.load(get_res_path("http_simple.xml")) original_load = original_config.find('//tsung/load')[0] modified_config = TsungConfig(None) modified_config.load(self.obj.tsung_config) loads = modified_config.find('//tsung/load') self.assertEqual(len(loads), 1) modified_load = loads[0] self.assertEqual(etree.tostring(original_load), etree.tostring(modified_load))
def test_no_load_no_modication(self): # if load profile is not specified - original tsung config's <load> shouldn't be modified self.obj.execution.merge({ "scenario": { "script": get_res_path("http_simple.xml"), } }) self.obj.settings.merge({"path": get_res_path(TOOL_NAME),}) self.obj.prepare() original_config = TsungConfig(None) original_config.load(get_res_path("http_simple.xml")) original_load = original_config.find('//tsung/load')[0] modified_config = TsungConfig(None) modified_config.load(self.obj.tsung_config) loads = modified_config.find('//tsung/load') self.assertEqual(len(loads), 1) modified_load = loads[0] self.assertEqual(etree.tostring(original_load), etree.tostring(modified_load))
def test_load_modification(self): self.obj.execution.merge({ "concurrency": 50, "hold-for": "30s", "scenario": { "script": get_res_path("http_simple.xml"), } }) self.obj.settings.merge({"path": get_res_path(TOOL_NAME),}) self.obj.prepare() original_config = TsungConfig(None) original_config.load(get_res_path("http_simple.xml")) original_load = original_config.find('//tsung/load')[0] modified_config = TsungConfig(None) modified_config.load(self.obj.tsung_config) loads = modified_config.find('//tsung/load') self.assertEqual(len(loads), 1) modified_load = loads[0] self.assertNotEqual(etree.tostring(original_load), etree.tostring(modified_load)) self.assertEqual(modified_load.get('duration'), '30')
def test_modify_dumpstats(self): self.obj.execution.merge({ "scenario": { "script": get_res_path("http_simple.xml"), } }) self.obj.settings.merge({"path": get_res_path(TOOL_NAME),}) self.obj.prepare() config = TsungConfig(None) config.load(self.obj.tsung_config) elements = config.find('//tsung') self.assertEqual(len(elements), 1) root = elements[0] self.assertEqual(root.get('dumptraffic'), 'protocol') self.assertEqual(root.get('backend'), 'text')
def test_modify_dumpstats(self): self.obj.execution.merge({ "scenario": { "script": get_res_path("http_simple.xml"), } }) self.obj.settings.merge({"path": get_res_path(TOOL_NAME),}) self.obj.prepare() config = TsungConfig(None) config.load(self.obj.tsung_config) elements = config.find('//tsung') self.assertEqual(len(elements), 1) root = elements[0] self.assertEqual(root.get('dumptraffic'), 'protocol') self.assertEqual(root.get('backend'), 'text')
def test_sessions_requests(self): self.obj.execution.merge({ "concurrency": 2, "hold-for": "10s", "scenario": { "default-address": "http://example.com", "requests": ["/", "/reserve.php"], } }) self.obj.settings.merge({"path": get_res_path(TOOL_NAME),}) self.obj.prepare() config = TsungConfig(None) config.load(self.obj.tsung_config) requests = config.find('//request') self.assertEquals(2, len(requests))
def test_sessions_requests(self): self.obj.execution.merge({ "concurrency": 2, "hold-for": "10s", "scenario": { "default-address": "http://example.com", "requests": ["/", "/reserve.php"], } }) self.obj.settings.merge({"path": get_res_path(TOOL_NAME),}) self.obj.prepare() config = TsungConfig(None) config.load(self.obj.tsung_config) requests = config.find('//request') self.assertEquals(2, len(requests))
def test_scenario_max_retries(self): self.obj.execution.merge({ "hold-for": "10s", "scenario": { "max-retries": "5", "requests": ["http://blazedemo.com/"] } }) self.obj.settings.merge({"path": get_res_path(TOOL_NAME),}) self.obj.prepare() config = TsungConfig(None) config.load(self.obj.tsung_config) elements = config.find('//options/option[@name="max_retries"]') self.assertEqual(len(elements), 1) thinktime = elements[0] self.assertEqual(thinktime.get('value'), '5')
def test_scenario_max_retries(self): self.obj.execution.merge({ "hold-for": "10s", "scenario": { "max-retries": "5", "requests": ["http://blazedemo.com/"] } }) self.obj.settings.merge({"path": get_res_path(TOOL_NAME),}) self.obj.prepare() config = TsungConfig(None) config.load(self.obj.tsung_config) elements = config.find('//options/option[@name="max_retries"]') self.assertEqual(len(elements), 1) thinktime = elements[0] self.assertEqual(thinktime.get('value'), '5')
def test_servers(self): self.obj.execution.merge({ "hold-for": "10s", "scenario": { "default-address": "http://example.com:8080", "requests": ["/"], } }) self.obj.settings.merge({"path": get_res_path(TOOL_NAME),}) self.obj.prepare() config = TsungConfig(None) config.load(self.obj.tsung_config) servers = config.find('//servers/server') self.assertEquals(1, len(servers)) server = servers[0] self.assertEqual(server.get('host'), 'example.com') self.assertEqual(server.get('port'), '8080')
def test_servers(self): self.obj.execution.merge({ "hold-for": "10s", "scenario": { "default-address": "http://example.com:8080", "requests": ["/"], } }) self.obj.settings.merge({"path": get_res_path(TOOL_NAME),}) self.obj.prepare() config = TsungConfig(None) config.load(self.obj.tsung_config) servers = config.find('//servers/server') self.assertEquals(1, len(servers)) server = servers[0] self.assertEqual(server.get('host'), 'example.com') self.assertEqual(server.get('port'), '8080')
def test_scenario_timeout(self): obj = TsungExecutor() obj.engine = EngineEmul() obj.execution.merge({ "hold-for": "10s", "scenario": { "timeout": "1s", "requests": ["http://blazedemo.com/"] } }) obj.settings.merge({"path": get_res_path(TOOL_NAME),}) obj.prepare() config = TsungConfig(None) config.load(obj.tsung_config) elements = config.find('//options/option[@name="connect_timeout"]') self.assertEqual(len(elements), 1) thinktime = elements[0] self.assertEqual(thinktime.get('value'), '1000')