def test_can_create_commit(self): load_test = LoadTestFactory.create() retrieved = LoadTest.objects(id=load_test.id).first() commit = retrieved.last_commit expect(commit).not_to_be_null() expect(commit.hex).to_equal(load_test.last_commit.hex)
def test_can_run_project(self): temp_path = mkdtemp() team = TeamFactory.create(name="teste") TeamFactory.add_projects(team, 1) user = team.owner project = team.projects[0] project.repository = "git://github.com/heynemann/wight.git" load_test = LoadTestFactory.add_to_project(1, user=user, team=team, project=project, base_url=self.base_url) runner = BenchRunner() runner.run_project_tests(temp_path, str(load_test.uuid), duration=1) loaded = LoadTest.objects(uuid=load_test.uuid).first() expect(loaded).not_to_be_null() expect(loaded.status).to_equal("Finished") expect(loaded.results).to_length(2) expect(loaded.results[0].log).not_to_be_null() expect(loaded.results[0].status).to_equal("Successful")
def test_can_run_simple_project(self): temp_path = mkdtemp() team = TeamFactory.create() TeamFactory.add_projects(team, 1) user = team.owner project = team.projects[0] load_test = LoadTestFactory.add_to_project(1, user=user, team=team, project=project, base_url="%s/healthcheck" % self.base_url, simple=True) runner = BenchRunner() runner.run_project_tests(temp_path, str(load_test.uuid), duration=1) loaded = LoadTest.objects(uuid=load_test.uuid).first() expect(loaded).not_to_be_null() expect(loaded.status).to_equal("Finished") expect(loaded.results).to_length(1) expect(loaded.results[0].log).not_to_be_null() expect(loaded.results[0].status).to_equal("Successful") expect(loaded.results[0].config.module).to_equal("test_simple") expect(loaded.results[0].config.class_name).to_equal("SimpleTestTest") expect(loaded.results[0].config.test_name).to_equal("test_simple")
def test_fail_if_yaml_not_exists(self, clone_repo_mock): clone_repo_mock.return_value = None temp_path = mkdtemp() os.mkdir(os.path.join(temp_path, "bench")) load_test = LoadTestFactory.add_to_project(1, base_url=self.base_url) runner = BenchRunner() runner.run_project_tests(temp_path, str(load_test.uuid), cycles=[1, 2], duration=1) loaded = LoadTest.objects(uuid=load_test.uuid).first() expect(loaded).not_to_be_null() expect(loaded.status).to_equal("Failed") expect(loaded.error).to_equal("The wight.yml file was not found in project repository bench folder.")
def test_get_load_tests_with_20_by_default_if_quantity_was_empty(self): LoadTestFactory.add_to_project(24, user=self.user, team=self.team, project=self.project) url = "/teams/%s/projects/%s/load_tests/?quantity=" % (self.team.name, self.project.name) response = self.fetch_with_headers(url) expect(response.code).to_equal(200) obj = response.body if isinstance(obj, six.binary_type): obj = obj.decode('utf-8') obj = loads(obj) expect(obj).to_length(20) load_test = LoadTest.objects(team=self.team, project_name=self.project.name).first() expect(obj[0]).to_be_like(load_test.to_dict())
def test_can_create_a_load_test_if_team_owner(self): test = LoadTestFactory.create( created_by=self.user, team=self.team, project_name=self.project.name ) retrieveds = LoadTest.objects(id=test.id) expect(retrieveds.count()).to_equal(1) retrieved = retrieveds.first() expect(retrieved.status).to_equal("Scheduled") expect(retrieved.created_by.email).to_equal(self.user.email) expect(retrieved.team.name).to_equal(self.team.name) expect(retrieved.project_name).to_equal(self.project.name) expect(retrieved.date_created).to_be_like(test.date_created) expect(retrieved.date_modified).to_be_like(test.date_modified)
def test_can_parse_stats_from_funkload_result(self): test = LoadTestFactory.add_to_project(1, user=self.user, team=self.team, project=self.project) config = FunkLoadTestResultFactory.get_config() cycles = FunkLoadTestResultFactory.get_result(4) result = LoadTest.get_data_from_funkload_results(config, cycles) test.add_result(result, "log") loaded_test = LoadTest.objects(uuid=test.uuid).first() expect(loaded_test).not_to_be_null() expect(loaded_test.results).to_length(1) result = loaded_test.results[0] expect(result.cycles).to_length(4) cycle = result.cycles[0] expect(cycle.test.successful_tests_per_second).to_equal(20.30394) expect(cycle.test.total_tests).to_equal(200) expect(cycle.test.successful_tests).to_equal(300) expect(cycle.test.failed_tests).to_equal(0) expect(cycle.test.failed_tests_percentage).to_equal(0) expect(cycle.page.apdex).to_equal(0.993) expect(cycle.page.successful_pages_per_second).to_equal(35.2) expect(cycle.page.maximum_successful_pages_per_second).to_equal(44.0) expect(cycle.page.total_pages).to_equal(200) expect(cycle.page.successful_pages).to_equal(300) expect(cycle.page.failed_pages).to_equal(0) expect(cycle.page.minimum).to_equal(0.123) expect(cycle.page.average).to_equal(0.234) expect(cycle.page.maximum).to_equal(0.384) expect(cycle.page.p10).to_equal(1.0) expect(cycle.page.p50).to_equal(1.0) expect(cycle.page.p90).to_equal(1.0) expect(cycle.page.p95).to_equal(1.0)
def test_fail_if_yaml_not_exists(self, clone_repo_mock): clone_repo_mock.return_value = None temp_path = mkdtemp() os.mkdir(os.path.join(temp_path, "bench")) load_test = LoadTestFactory.add_to_project(1, base_url=self.base_url) runner = BenchRunner() runner.run_project_tests(temp_path, str(load_test.uuid), cycles=[1, 2], duration=1) loaded = LoadTest.objects(uuid=load_test.uuid).first() expect(loaded).not_to_be_null() expect(loaded.status).to_equal("Failed") expect(loaded.error).to_equal( "The wight.yml file was not found in project repository bench folder." )
def test_get_load_tests_with_20_by_default_if_quantity_was_empty(self): LoadTestFactory.add_to_project(24, user=self.user, team=self.team, project=self.project) url = "/teams/%s/projects/%s/load_tests/?quantity=" % ( self.team.name, self.project.name) response = self.fetch_with_headers(url) expect(response.code).to_equal(200) obj = response.body if isinstance(obj, six.binary_type): obj = obj.decode('utf-8') obj = loads(obj) expect(obj).to_length(20) load_test = LoadTest.objects(team=self.team, project_name=self.project.name).first() expect(obj[0]).to_be_like(load_test.to_dict())
def run_project_tests(self, base_path, load_test_uuid, workers=[], cycles=DEFAULT_CYCLES, duration=10): logging.debug("loading test") load_test = LoadTest.objects(uuid=UUID(load_test_uuid)).first() load_test.status = "Running" load_test.running_since = datetime.utcnow() load_test.save() logging.debug("test saved") try: cfg = self._build_test_config(base_path, load_test) self._run_config_tests(cfg, base_path, load_test, workers, cycles, duration) load_test.status = "Finished" load_test.save() except Exception: err = sys.exc_info()[1] logging.error(err) load_test.status = "Failed" load_test.error = str(err) load_test.save()
def get(self, uuid): self.set_status(200) try: load_test, test_result = LoadTest.get_test_result(uuid) return_value = { "team": load_test.team.name, "project": load_test.project_name, "result": test_result.to_dict(), "createdBy": load_test.created_by.email, "lastModified": load_test.date_modified.isoformat()[:19] } self.write(dumps(return_value)) except DoesNotExist: load_test = LoadTest.objects(uuid=uuid) if not load_test.count(): self.set_status(404) return self.write(dumps(load_test.first().to_dict())) finally: self.finish()
def test_can_parse_configuration_from_funkload_result(self): test = LoadTestFactory.add_to_project(1, user=self.user, team=self.team, project=self.project) config = FunkLoadTestResultFactory.get_config() cycles = FunkLoadTestResultFactory.get_result(4) result = LoadTest.get_data_from_funkload_results(config, cycles) test.add_result(result, "log") loaded_test = LoadTest.objects(uuid=test.uuid).first() expect(loaded_test).not_to_be_null() expect(loaded_test.results).to_length(1) result = loaded_test.results[0] expect(result.log).to_equal("log") cfg = result.config expect(cfg.title).to_equal(config['class_title']) expect(cfg.description).to_equal(config['class_description']) expect(cfg.module).to_equal(config['module']) expect(cfg.class_name).to_equal(config['class']) expect(cfg.test_name).to_equal(config['method']) expect(cfg.target_server).to_equal(config['server_url']) expect(cfg.cycles).to_equal(config['cycles']) expect(cfg.cycle_duration).to_equal(int(config['duration'])) expect(cfg.sleep_time).to_equal(float(config['sleep_time'])) expect(cfg.sleep_time_min).to_equal(float(config['sleep_time_min'])) expect(cfg.sleep_time_max).to_equal(float(config['sleep_time_max'])) expect(cfg.startup_delay).to_equal(float(config['startup_delay'])) expect(cfg.test_date.isoformat()[:20]).to_equal(config['time'][:20]) expect(cfg.funkload_version).to_equal(config['version'])
def test_can_run_project(self): temp_path = mkdtemp() team = TeamFactory.create() TeamFactory.add_projects(team, 1) user = team.owner project = team.projects[0] project.repository = "git://github.com/heynemann/wight.git" load_test = LoadTestFactory.add_to_project(1, user=user, team=team, project=project, base_url=self.base_url) runner = BenchRunner() runner.run_project_tests(temp_path, str(load_test.uuid), duration=1) loaded = LoadTest.objects(uuid=load_test.uuid).first() expect(loaded).not_to_be_null() expect(loaded.status).to_equal("Finished") expect(loaded.results).to_length(1) expect(loaded.results[0].log).not_to_be_null() expect(loaded.results[0].status).to_equal("Successful")
def test_to_dict(self): test = LoadTestFactory.create( created_by=self.user, team=self.team, project_name=self.project.name, base_url="http://some-server.com/some-url" ) retrieved = LoadTest.objects(id=test.id).first() expect(retrieved.to_dict()).to_be_like( { "baseUrl": "http://some-server.com/some-url", "uuid": str(test.uuid), "createdBy": self.user.email, "team": self.team.name, "project": self.project.name, "status": test.status, "created": test.date_created.isoformat()[:19], "lastModified": test.date_modified.isoformat()[:19], "lastCommit": test.last_commit.to_dict(), "gitBranch": test.git_branch, "results": [] } )
def test_can_run_project_with_two_test(self, build_mock): simple_test_content = """ import unittest from funkload.FunkLoadTestCase import FunkLoadTestCase class SimpleTestTest(FunkLoadTestCase): def setUp(self): self.server_url = '%s/healthcheck' % (self.conf_get('main', 'url').rstrip('/'),) def test_simple(self): self.get(self.server_url, description='Get url') if __name__ == '__main__': unittest.main() """ healthcheck_content = """ import unittest from funkload.FunkLoadTestCase import FunkLoadTestCase class HealthCheckTest(FunkLoadTestCase): def setUp(self): self.server_url = '%s/healthcheck' % (self.conf_get('main', 'url').rstrip('/'),) def test_healthcheck(self): self.get(self.server_url, description='Get url') if __name__ == '__main__': unittest.main() """ cfg_text = """ tests: - module: test_healthcheck.py class: HealthCheckTest test: test_healthcheck - module: test_simple.py class: SimpleTestTest test: test_simple """ build_mock.return_value = WightConfig(cfg_text) team = TeamFactory.create() TeamFactory.add_projects(team, 1) user = team.owner project = team.projects[0] load_test = LoadTestFactory.add_to_project(1, user=user, team=team, project=project, base_url=self.base_url, simple=True) temp_path = mkdtemp() mkdir(join(temp_path, "bench")) init_file = open(join(temp_path, "bench/__init__.py"), "w") init_file.close() wight_file = open(join(temp_path, "bench/wight.yml"), "w") wight_file.write(cfg_text) wight_file.close() simple_file = open(join(temp_path, "bench/test_simple.py"), "w") simple_file.write(simple_test_content) simple_file.close() healthcheck_file = open(join(temp_path, "bench/test_healthcheck.py"), "w") healthcheck_file.write(healthcheck_content) healthcheck_file.close() runner = BenchRunner() runner.run_project_tests(temp_path, str(load_test.uuid), duration=1) loaded = LoadTest.objects(uuid=load_test.uuid).first() expect(loaded).not_to_be_null() expect(loaded.status).to_equal("Finished") expect(loaded.results).to_length(2) expect(loaded.results[0].log).not_to_be_null() expect(loaded.results[0].status).to_equal("Successful") expect(loaded.results[0].config.module).to_equal("test_healthcheck") expect(loaded.results[1].log).not_to_be_null() expect(loaded.results[1].status).to_equal("Successful") expect(loaded.results[1].config.module).to_equal("test_simple")