def test_grinder_widget(self): obj = GrinderExecutor() obj.engine = EngineEmul() obj.execution.merge({"scenario": {"script": "tests/grinder/helloworld.py"}}) obj.prepare() obj.get_widget() self.assertEqual(obj.widget.script_name.text, "Script: helloworld.py")
def test_fail_on_zero_results(self): obj = GrinderExecutor() obj.engine = EngineEmul() obj.execution.merge({"concurrency": {"local": 2}, "scenario": {"script": __dir__() + "/../grinder/helloworld.py"}}) obj.prepare() self.assertRaises(RuntimeWarning, obj.post_process)
def test_grinder_widget(self): obj = GrinderExecutor() obj.engine = EngineEmul() obj.execution.merge({"scenario": {"script": __dir__() + "/../grinder/helloworld.py"}}) obj.prepare() obj.get_widget() self.assertEqual(obj.widget.widgets[0].text, "Script: helloworld.py")
def test_install_Grinder_link(self): path = os.path.abspath(BUILD_DIR + "grinder-taurus/lib/grinder.jar") shutil.rmtree(os.path.dirname(os.path.dirname(path)), ignore_errors=True) self.assertFalse(os.path.exists(path)) obj = GrinderExecutor() obj.engine = EngineEmul() link = "file:///" + RESOURCES_DIR + "grinder/grinder-3.11_3.11-binary.zip" obj.settings.merge({"download-link": link}) obj.settings.merge({"path": path}) obj.settings.merge({ "properties-file": RESOURCES_DIR + "grinder/grinder.base.properties", "properties": { "sample_prop": "some_val" } }) obj.execution.merge({ "scenario": { "script": RESOURCES_DIR + "grinder/helloworld.py", "properties-file": RESOURCES_DIR + "grinder/grinder.properties", "properties": { "grinder.useConsole": "false" } } }) obj.prepare() self.assertTrue(os.path.exists(path))
def test_install_Grinder(self): path = os.path.abspath(__dir__() + "/../../build/tmp/grinder-taurus/lib/grinder.jar") shutil.rmtree(os.path.dirname(os.path.dirname(path)), ignore_errors=True) grinder_link = GrinderExecutor.DOWNLOAD_LINK grinder_version = GrinderExecutor.VERSION mirrors_source = GrinderExecutor.MIRRORS_SOURCE GrinderExecutor.DOWNLOAD_LINK = "file:///" + __dir__() + "/../data/grinder-{version}_{version}-binary.zip" GrinderExecutor.VERSION = "3.11" GrinderExecutor.MIRRORS_SOURCE = "file:///" + __dir__() + "/../data/unicode_file" self.assertFalse(os.path.exists(path)) obj = GrinderExecutor() obj.engine = EngineEmul() obj.settings.merge({"path": path}) obj.settings.merge({"properties-file": __dir__() + "/../grinder/grinder.base.properties", "properties": {"sample_prop": "some_val"}}) obj.execution.merge({"scenario": { "script": __dir__() + "/../grinder/helloworld.py", "properties-file": __dir__() + "/..//grinder/grinder.properties", "properties": {"grinder.useConsole": "false"}}}) obj.prepare() self.assertTrue(os.path.exists(path)) GrinderExecutor.DOWNLOAD_LINK = grinder_link GrinderExecutor.VERSION = grinder_version GrinderExecutor.MIRRORS_SOURCE = mirrors_source
def test_install_Grinder(self): path = os.path.abspath(__dir__() + "/../../build/tmp/grinder-taurus/lib/grinder.jar") shutil.rmtree(os.path.dirname(os.path.dirname(path)), ignore_errors=True) self.assertFalse(os.path.exists(path)) obj = GrinderExecutor() obj.engine = EngineEmul() obj.settings.merge({"path": path}) obj.settings.merge( { "properties-file": __dir__() + "/../grinder/grinder.base.properties", "properties": {"sample_prop": "some_val"}, } ) obj.execution.merge( { "scenario": { "script": __dir__() + "/../grinder/helloworld.py", "properties-file": __dir__() + "/..//grinder/grinder.properties", "properties": {"grinder.useConsole": "false"}, } } ) obj.prepare() self.assertTrue(os.path.exists(path))
def test_install_Grinder(self): path = os.path.abspath( __dir__() + "/../../build/tmp/grinder-taurus/lib/grinder.jar") shutil.rmtree(os.path.dirname(os.path.dirname(path)), ignore_errors=True) self.assertFalse(os.path.exists(path)) obj = GrinderExecutor() obj.engine = EngineEmul() obj.settings.merge({"path": path}) obj.settings.merge({ "properties-file": __dir__() + "/../grinder/grinder.base.properties", "properties": { "sample_prop": "some_val" } }) obj.execution.merge({ "scenario": { "script": __dir__() + "/../grinder/helloworld.py", "properties-file": __dir__() + "/..//grinder/grinder.properties", "properties": { "grinder.useConsole": "false" } } }) obj.prepare() self.assertTrue(os.path.exists(path))
def test_install_Grinder(self): path = os.path.abspath(__dir__() + "/../../build/tmp/grinder-taurus/lib/grinder.jar") shutil.rmtree(os.path.dirname(os.path.dirname(path)), ignore_errors=True) grinder_link = GrinderExecutor.DOWNLOAD_LINK grinder_version = GrinderExecutor.VERSION mirrors_source = GrinderExecutor.MIRRORS_SOURCE try: GrinderExecutor.DOWNLOAD_LINK = "file:///" + __dir__() + \ "/../resources/grinder/grinder-{version}_{version}-binary.zip" GrinderExecutor.VERSION = "3.11" GrinderExecutor.MIRRORS_SOURCE = "file:///" + __dir__() + "/../resources/jmeter/unicode_file" self.assertFalse(os.path.exists(path)) obj = GrinderExecutor() obj.engine = EngineEmul() obj.settings.merge({"path": path}) obj.settings.merge({"properties-file": __dir__() + "/../resources/grinder/grinder.base.properties", "properties": {"sample_prop": "some_val"}}) obj.execution.merge({"scenario": { "script": __dir__() + "/../resources/grinder/helloworld.py", "properties-file": __dir__() + "/..//resources/grinder/grinder.properties", "properties": {"grinder.useConsole": "false"}}}) obj.prepare() self.assertTrue(os.path.exists(path)) finally: GrinderExecutor.DOWNLOAD_LINK = grinder_link GrinderExecutor.VERSION = grinder_version GrinderExecutor.MIRRORS_SOURCE = mirrors_source
def test_full_Grinder(self): obj = GrinderExecutor() obj.kpi_file = os.path.abspath(__dir__() + '/../grinder/test.log') obj.engine = EngineEmul() obj.settings.merge( {'path': __dir__() + "/../grinder/fake_grinder.jar"}) obj.execution.merge({ "concurrency": { "local": 2 }, "hold-for": 5, "scenario": { "requests": ['http://blazedemo.com'] } }) obj.prepare() self.assertEqual(len(obj.cmd_line), 5) cmd_line = ' '.join(obj.cmd_line) self.assertTrue(cmd_line.startswith('java -classpath')) self.assertNotEqual(cmd_line.find('net.grinder.Grinder'), -1) try: obj.cmd_line = __dir__() + "/../grinder/grinder" + EXE_SUFFIX obj.startup() while not obj.check(): time.sleep(obj.engine.check_interval) finally: obj.shutdown() obj.post_process() self.assertFalse(obj.has_results())
def test_install_Grinder(self): path = os.path.abspath( __dir__() + "/../../build/tmp/grinder-taurus/lib/grinder.jar") shutil.rmtree(os.path.dirname(os.path.dirname(path)), ignore_errors=True) grinder_link = GrinderExecutor.DOWNLOAD_LINK grinder_version = GrinderExecutor.VERSION GrinderExecutor.DOWNLOAD_LINK = "file://" + __dir__( ) + "/../data/grinder-{version}_{version}-binary.zip" GrinderExecutor.VERSION = "3.11" self.assertFalse(os.path.exists(path)) obj = GrinderExecutor() obj.engine = EngineEmul() obj.settings.merge({"path": path}) obj.execution = BetterDict() obj.execution.merge({ "scenario": { "script": "tests/grinder/helloworld.py", "properties-file": "tests/grinder/grinder.properties", "properties": { "grinder.useConsole": "false" } } }) obj.prepare() self.assertTrue(os.path.exists(path)) obj.prepare() GrinderExecutor.DOWNLOAD_LINK = grinder_link GrinderExecutor.VERSION = grinder_version
def test_resource_files_collection_local(self): obj = GrinderExecutor() obj.engine = EngineEmul() obj.execution.merge({"scenario": {"script": __dir__() + "/../grinder/helloworld.py", "properties-file": __dir__() + "/../grinder/grinder.properties"}}) obj.prepare() artifacts = os.listdir(obj.engine.artifacts_dir) self.assertEqual(len(artifacts), 2)
def test_requests(self): obj = GrinderExecutor() obj.engine = EngineEmul() obj.execution.merge( {"scenario": { "requests": ['http://blazedemo.com'] }}) obj.prepare()
def test_resource_files_collection_local(self): obj = GrinderExecutor() obj.engine = EngineEmul() obj.execution.merge({"scenario": {"script": "tests/grinder/helloworld.py", "properties-file": "tests/grinder/grinder.properties"}}) obj.prepare() artifacts = os.listdir(obj.engine.artifacts_dir) self.assertEqual(len(artifacts), 2)
def test_resource_files_collection_noscript(self): obj = GrinderExecutor() obj.engine = EngineEmul() obj.execution.merge({"scenario": {"properties-file": "tests/grinder/grinder.properties"}}) res_files = obj.resource_files() artifacts = os.listdir(obj.engine.artifacts_dir) self.assertEqual(len(res_files), 2) self.assertEqual(len(artifacts), 2)
def test_resource_files_collection_noscript(self): obj = GrinderExecutor() obj.engine = EngineEmul() obj.execution.merge({"scenario": {"properties-file": __dir__() + "/../grinder/grinder.properties"}}) res_files = obj.resource_files() artifacts = os.listdir(obj.engine.artifacts_dir) self.assertEqual(len(res_files), 2) self.assertEqual(len(artifacts), 2)
def test_resource_files_collection_remote(self): obj = GrinderExecutor() obj.engine = EngineEmul() obj.execution.merge({"scenario": {"script": __dir__() + "/../grinder/helloworld.py", "properties-file": __dir__() + "/../grinder/grinder.properties"}}) res_files = obj.resource_files() artifacts = os.listdir(obj.engine.artifacts_dir) self.assertEqual(len(res_files), 2) self.assertEqual(len(artifacts), 2)
def test_resource_files_collection_basic(self): obj = GrinderExecutor() obj.engine = EngineEmul() obj.execution.merge( {"scenario": { "script": __dir__() + "/../grinder/helloworld.py" }}) res_files = obj.resource_files() self.assertEqual(len(res_files), 1)
def test_requests(self): obj = GrinderExecutor() obj.engine = EngineEmul() obj.settings.merge( {'path': __dir__() + "/../grinder/fake_grinder.jar"}) obj.execution.merge( {"scenario": { "requests": ['http://blazedemo.com'] }}) obj.prepare()
def test_grinder_widget(self): obj = GrinderExecutor() obj.engine = EngineEmul() obj.engine.config.merge({"provisioning": 'local'}) obj.execution.merge({"concurrency": {"local": 2}, "ramp-up": 2, "hold-for": 2, "scenario": {"script": __dir__() + "/../grinder/helloworld.py"}}) obj.prepare() obj.get_widget() self.assertEqual(obj.widget.widgets[0].text, "Script: helloworld.py")
def test_script_generation(self): obj = GrinderExecutor() obj.engine = EngineEmul() obj.settings.merge({'path': __dir__() + "/../resources/grinder/fake_grinder.jar"}) obj.execution.merge({ "scenario": { "default-address": "http://blazedemo.com", "headers": { "My-Header": "Its-Value", "Another-Header": "Another-Value", }, "timeout": "30s", "think-time": "2s", "store-cookie": True, "requests": [ '/', {'url': 'http://example.com/', 'method': 'POST', 'think-time': "1s", 'headers': { 'Custom': 'Header', }}, ] } }) obj.prepare() script = open(os.path.join(obj.engine.artifacts_dir, 'grinder_requests.py')).read() default_addr = re.findall(r"url='http://blazedemo.com'", script) self.assertEquals(1, len(default_addr)) requests = re.findall(r"request\.([A-Z]+)\('(.+?)'", script) self.assertEquals(2, len(requests)) self.assertEquals(requests[0], ('GET', '/')) self.assertEquals(requests[1], ('POST', 'http://example.com/')) sleeps = re.findall(r"grinder\.sleep\((.+)\)", script) self.assertEquals(3, len(sleeps)) self.assertEquals(sleeps[0], 'sleep_time, 0') self.assertEquals(sleeps[1], '2000') self.assertEquals(sleeps[2], '1000') headers = re.findall(r"NVPair\('(.+)', '(.+)'\)", script) self.assertEquals(3, len(headers)) self.assertIn(("My-Header", "Its-Value"), headers) self.assertIn(("Another-Header", "Another-Value"), headers) self.assertIn(("Custom", "Header"), headers) timeout = re.findall(r"defaults.setTimeout\((\d+)\)", script) self.assertEquals(1, len(timeout)) self.assertEquals(timeout[0], '30000') cookies = re.findall(r"defaults.setUseCookies\(1\)", script) self.assertEquals(1, len(cookies))
def test_grinder_widget(self): obj = GrinderExecutor() obj.engine = EngineEmul() obj.settings.merge({'path': __dir__() + "/../resources/grinder/fake_grinder.jar"}) obj.engine.config.merge({"provisioning": 'local'}) obj.execution.merge({"concurrency": {"local": 2}, "ramp-up": 2, "hold-for": 2, "scenario": {"script": __dir__() + "/../resources/grinder/helloworld.py"}}) obj.prepare() obj.get_widget() self.assertEqual(obj.widget.widgets[0].text, "Grinder: helloworld.py")
def test_resource_files_collection_invalid(self): obj = GrinderExecutor() obj.engine = EngineEmul() obj.execution.merge({"scenario": {"script": __dir__() + "/../grinder/helloworld.py", "properties-file": __dir__() + "/../grinder/grinder_invalid.properties"}}) res_files = obj.resource_files() artifacts = os.listdir(obj.engine.artifacts_dir) self.assertEqual(len(res_files), 2) self.assertEqual(len(artifacts), 2) self.assertIn("helloworld.py", open(os.path.join(obj.engine.artifacts_dir, "grinder_invalid.properties")).read())
def test_resource_files_collection_invalid(self): obj = GrinderExecutor() obj.engine = EngineEmul() obj.execution.merge({"scenario": {"script": "tests/grinder/helloworld.py", "properties-file": "tests/grinder/grinder_invalid.properties"}}) res_files = obj.resource_files() artifacts = os.listdir(obj.engine.artifacts_dir) self.assertEqual(len(res_files), 2) self.assertEqual(len(artifacts), 2) self.assertIn("helloworld.py", open(os.path.join(obj.engine.artifacts_dir, "grinder_invalid.properties")).read())
def test_script_generation(self): obj = GrinderExecutor() obj.engine = EngineEmul() obj.settings.merge({'path': __dir__() + "/../grinder/fake_grinder.jar"}) obj.execution.merge({ "scenario": { "default-address": "http://blazedemo.com", "headers": { "My-Header": "Its-Value", "Another-Header": "Another-Value", }, "timeout": "30s", "think-time": "2s", "store-cookie": True, "requests": [ '/', {'url': 'http://example.com/', 'method': 'POST', 'think-time': "1s", 'headers': { 'Custom': 'Header', }}, ] } }) obj.prepare() script = open(os.path.join(obj.engine.artifacts_dir, 'grinder_requests.py')).read() default_addr = re.findall(r"url='http://blazedemo.com'", script) self.assertEquals(1, len(default_addr)) requests = re.findall(r"request\.([A-Z]+)\('(.+?)'", script) self.assertEquals(2, len(requests)) self.assertEquals(requests[0], ('GET', '/')) self.assertEquals(requests[1], ('POST', 'http://example.com/')) sleeps = re.findall(r"grinder\.sleep\((.+)\)", script) self.assertEquals(2, len(sleeps)) self.assertEquals(sleeps[0], '2000') self.assertEquals(sleeps[1], '1000') headers = re.findall(r"NVPair\('(.+)', '(.+)'\)", script) self.assertEquals(3, len(headers)) self.assertIn(("My-Header", "Its-Value"), headers) self.assertIn(("Another-Header", "Another-Value"), headers) self.assertIn(("Custom", "Header"), headers) timeout = re.findall(r"defaults.setTimeout\((\d+)\)", script) self.assertEquals(1, len(timeout)) self.assertEquals(timeout[0], '30000') cookies = re.findall(r"defaults.setUseCookies\(1\)", script) self.assertEquals(1, len(cookies))
def test_fail_on_zero_results(self): obj = GrinderExecutor() obj.engine = EngineEmul() obj.settings.merge({'path': __dir__() + "/../grinder/fake_grinder.jar"}) obj.execution.merge({"concurrency": {"local": 2}, "scenario": {"script": __dir__() + "/../grinder/helloworld.py"}}) obj.prepare() obj.engine.prepared = [obj] obj.engine.started = [obj] obj.engine.provisioning = Local() obj.engine.provisioning.engine = obj.engine obj.engine.provisioning.executors = [obj] self.assertRaises(RuntimeWarning, obj.engine.provisioning.post_process)
def test_fail_on_zero_results(self): obj = GrinderExecutor() obj.engine = EngineEmul() obj.settings.merge({'path': __dir__() + "/../resources/grinder/fake_grinder.jar"}) obj.execution.merge({"concurrency": {"local": 2}, "scenario": {"script": __dir__() + "/../resources/grinder/helloworld.py"}}) obj.prepare() obj.engine.prepared = [obj] obj.engine.started = [obj] obj.engine.provisioning = Local() obj.engine.provisioning.engine = obj.engine obj.engine.provisioning.executors = [obj] self.assertRaises(ToolError, obj.engine.provisioning.post_process)
def test_resource_files_collection(self): obj = GrinderExecutor() obj.engine = EngineEmul() obj.execution.merge({ "scenario": { "script": "tests/grinder/helloworld.py", "properties-file": "tests/grinder/grinder.properties" } }) res_files = obj.resource_files() artifacts = os.listdir(obj.engine.artifacts_dir) self.assertEqual(len(res_files), 2) self.assertEqual(len(artifacts), 2)
def test_fail_on_zero_results(self): obj = GrinderExecutor() obj.engine = EngineEmul() obj.execution.merge({ "concurrency": { "local": 2 }, "scenario": { "script": __dir__() + "/../grinder/helloworld.py" } }) obj.prepare() self.assertRaises(RuntimeWarning, obj.post_process)
def test_with_results(self): obj = GrinderExecutor() obj.engine = EngineEmul() obj.settings.merge({'path': __dir__() + "/../resources/grinder/fake_grinder.jar"}) obj.execution.merge({ "concurrency": {"local": 2}, "scenario": {"script": __dir__() + "/../resources/grinder/helloworld.py"}}) obj.prepare() obj.engine.prepared = [obj] obj.engine.started = [obj] prov = Local() prov.engine = obj.engine prov.executors = [obj] obj.engine.provisioning = prov obj.reader.buffer = ['some info'] obj.engine.provisioning.post_process()
def test_diagnostics(self): obj = GrinderExecutor() obj.kpi_file = os.path.abspath(__dir__() + '/../resources/grinder/test.log') obj.engine = EngineEmul() obj.settings.merge({'path': __dir__() + "/../resources/grinder/fake_grinder.jar"}) obj.execution.merge({"hold-for": 2, "scenario": {"keepalive": False, "requests": ['http://blazedemo.com']}}) obj.prepare() try: obj.cmd_line = __dir__() + "/../resources/grinder/grinder" + EXE_SUFFIX obj.startup() while not obj.check(): time.sleep(obj.engine.check_interval) finally: obj.shutdown() obj.post_process() self.assertIsNotNone(obj.get_error_diagnostics())
def test_with_results(self): obj = GrinderExecutor() obj.engine = EngineEmul() obj.settings.merge({'path': __dir__() + "/../grinder/fake_grinder.jar"}) obj.execution.merge({ "concurrency": {"local": 2}, "scenario": {"script": __dir__() + "/../grinder/helloworld.py"}}) obj.prepare() obj.engine.prepared = [obj] obj.engine.started = [obj] prov = Local() prov.engine = obj.engine prov.executors = [obj] obj.engine.provisioning = prov obj.reader.buffer = ['some info'] obj.engine.provisioning.post_process()
def test_full_Grinder(self): obj = GrinderExecutor() obj.kpi_file = os.path.abspath(__dir__() + "/../grinder/test.log") obj.engine = EngineEmul() obj.execution.merge( {"concurrency": {"local": 2}, "hold-for": 5, "scenario": {"requests": ["http://blazedemo.com"]}} ) obj.prepare() try: obj.cmd_line = __dir__() + "/../grinder/grinder.sh" obj.startup() while not obj.check(): time.sleep(obj.engine.check_interval) finally: obj.shutdown() self.assertRaises(RuntimeWarning, obj.post_process)
def test_full_Grinder(self): obj = GrinderExecutor() obj.kpi_file = os.path.abspath(__dir__() + '/../grinder/test.log') obj.engine = EngineEmul() obj.execution.merge({"concurrency": {"local": 2}, "hold-for": 5, "scenario": {"requests": ['http://blazedemo.com']}}) obj.prepare() self.assertEqual(len(obj.cmd_line), 5) cmd_line = ' '.join(obj.cmd_line) self.assertTrue(cmd_line.startswith('java -classpath')) self.assertNotEqual(cmd_line.find('net.grinder.Grinder'), -1) try: obj.cmd_line = __dir__() + "/../grinder/grinder" + EXE_SUFFIX obj.startup() while not obj.check(): time.sleep(obj.engine.check_interval) finally: obj.shutdown() self.assertRaises(RuntimeWarning, obj.post_process)
def test_full_Grinder(self): obj = GrinderExecutor() obj.kpi_file = os.path.abspath(__dir__() + '/../grinder/test.log') obj.engine = EngineEmul() obj.execution.merge({ "concurrency": { "local": 2 }, "hold-for": 5, "scenario": { "requests": ['http://blazedemo.com'] } }) obj.prepare() try: obj.cmd_line = __dir__() + "/../grinder/grinder.sh" obj.startup() while not obj.check(): time.sleep(obj.engine.check_interval) finally: obj.shutdown() self.assertRaises(RuntimeWarning, obj.post_process)
def get_grinder(): obj = GrinderExecutor() obj.engine = EngineEmul() obj.env = obj.engine.env obj.settings.merge({'path': RESOURCES_DIR + "grinder/fake_grinder.jar"}) return obj
def test_requests(self): obj = GrinderExecutor() obj.engine = EngineEmul() obj.settings.merge({'path': __dir__() + "/../grinder/fake_grinder.jar"}) obj.execution.merge({"scenario": {"requests": ['http://blazedemo.com']}}) obj.prepare()
def test_resource_files_collection_basic(self): obj = GrinderExecutor() obj.engine = EngineEmul() obj.execution.merge({"scenario": {"script": __dir__() + "/../grinder/helloworld.py"}}) res_files = obj.resource_files() self.assertEqual(len(res_files), 1)
def get_grinder(): obj = GrinderExecutor() obj.engine = EngineEmul() obj.env = obj.engine.env obj.settings.merge({'path': RESOURCES_DIR + "grinder/fake_grinder.jar"}) return obj
def test_requests(self): obj = GrinderExecutor() obj.engine = EngineEmul() obj.execution.merge({"scenario": {"requests": ['http://blazedemo.com']}}) obj.prepare()