예제 #1
0
 def test_can_get_load_test_by_test_result_uuid(self):
     self.load_test.results.append(TestResultFactory.build())
     self.load_test.save()
     result = self.load_test.results[0]
     load_test, test_result = LoadTest.get_test_result(str(result.uuid))
     expect(str(test_result.uuid)).to_equal(str(result.uuid))
     expect(str(load_test.uuid)).to_equal(str(self.load_test.uuid))
예제 #2
0
 def test_get_last_20_tests_for_a_team_and_project_ordered_by_date_created_desc(self):
     LoadTestFactory.add_to_project(25, user=self.user, team=self.team, project=self.project)
     LoadTestFactory.add_to_project(5, user=self.user, team=self.team, project=self.team.projects[1])
     loaded_tests = list(LoadTest.get_by_team_and_project_name(self.team, self.project.name))
     expect(loaded_tests).to_length(20)
     for load_tests in loaded_tests:
         expect(load_tests.project_name).to_equal(self.project.name)
예제 #3
0
    def _run_config_tests(self, cfg, base_path, load_test, workers, cycles, duration):
        logging.debug("running tests")
        for test in cfg.tests:
            kw = dict(
                root_path=base_path,
                test=test,
                base_url=load_test.base_url,
                cycles=cycles,
                duration=duration
            )

            if workers:
                kw['workers'] = workers

            fl_result = FunkLoadBenchRunner.run(**kw)

            if fl_result.exit_code != 0:
                load_test.status = "Failed"
                load_test.error = fl_result.text
                load_test.save()
                return

            logging.debug("create result for %s" % test.test_name)
            result = LoadTest.get_data_from_funkload_results(fl_result.config, fl_result.result)

            load_test.add_result(result, log=fl_result.text)
예제 #4
0
    def test_can_get_config_in_json_from_funkload_result(self):
        config = FunkLoadTestResultFactory.get_config()
        cycles = FunkLoadTestResultFactory.get_result(4)

        result_json = LoadTest.get_data_from_funkload_results(config, cycles)

        expect(result_json['config']).not_to_be_null()

        cfg = result_json['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'][:20]).to_equal(config['time'][:20])
        expect(cfg['funkload_version']).to_equal(config['version'])
예제 #5
0
    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)
예제 #6
0
    def test_can_run_funkload(self):
        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)
        load_test.pressure = "small"

        conf = WightConfig.load(join(root_path, 'bench', 'wight.yml'))
        test = conf.tests[0]

        DEFAULT_CYCLES = {
            "small": [10, 20],
            "medium": [10, 20, 30],
            "large": [30, 75, 100],
        }

        fl_result = FunkLoadBenchRunner.run(root_path, test, self.base_url, cycles=DEFAULT_CYCLES, duration=5)

        expect(fl_result).not_to_be_null()
        expect(fl_result.exit_code).to_equal(0)

        expect(fl_result.text).to_include("SUCCESSFUL")

        expect(fl_result.log).to_be_empty()

        expect(fl_result.result).not_to_be_null()
        expect(fl_result.config).not_to_be_null()

        result = LoadTest.get_data_from_funkload_results(fl_result.config, fl_result.result)

        load_test.add_result(result, fl_result.text)

        expect(load_test.results).to_length(1)
예제 #7
0
    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")
예제 #8
0
    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")
예제 #9
0
    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)
예제 #10
0
 def get(self, team, project_name):
     quantity = self.get_argument("quantity").strip()
     quantity = int(quantity) if quantity else 20
     load_tests = LoadTest.get_sliced_by_team_and_project_name(team, project_name, quantity)
     self.set_status(200)
     response = dumps([load_test.to_dict() for load_test in load_tests])
     self.write(response)
     self.finish()
예제 #11
0
 def test_get_last_3_load_tests_for_all_projects_when_owner(self):
     LoadTestFactory.add_to_project(4, user=self.user, team=self.team, project=self.project)
     LoadTestFactory.add_to_project(4, user=self.user, team=self.team, project=self.team.projects[1])
     team = TeamFactory.create(owner=self.user)
     TeamFactory.add_projects(team, 1)
     LoadTestFactory.add_to_project(4, user=self.user, team=team, project=team.projects[0])
     LoadTestFactory.add_to_project(4, user=UserFactory.create())
     loaded_tests = list(LoadTest.get_by_user(self.user))
     expect(loaded_tests).to_length(9)
예제 #12
0
    def test_list_load_tests_by_user_only(self):
        team1 = TeamFactory.create(owner=self.user)
        team2 = TeamFactory.create(owner=self.user)
        TeamFactory.add_projects(team1, 2)
        TeamFactory.add_projects(team2, 3)

        project1 = team1.projects[0]
        project2 = team1.projects[1]

        project3 = team2.projects[0]
        project4 = team2.projects[1]
        project5 = team2.projects[2]

        LoadTestFactory.add_to_project(4, user=self.user, team=team1, project=project1)
        LoadTestFactory.add_to_project(4, user=self.user, team=team1, project=project2)

        LoadTestFactory.add_to_project(4, user=self.user, team=team2, project=project3)
        LoadTestFactory.add_to_project(4, user=self.user, team=team2, project=project4)
        LoadTestFactory.add_to_project(4, user=self.user, team=team2, project=project5)

        load_tests1 = LoadTest.get_sliced_by_team_and_project_name(team1, project1.name, 3)
        load_tests2 = LoadTest.get_sliced_by_team_and_project_name(team1, project2.name, 3)

        load_tests3 = LoadTest.get_sliced_by_team_and_project_name(team2, project3.name, 3)
        load_tests4 = LoadTest.get_sliced_by_team_and_project_name(team2, project4.name, 3)
        load_tests5 = LoadTest.get_sliced_by_team_and_project_name(team2, project5.name, 3)

        uuids1 = _get_print_lines_for_load_tests(load_tests1)
        uuids2 = _get_print_lines_for_load_tests(load_tests2)

        uuids3 = _get_print_lines_for_load_tests(load_tests3)
        uuids4 = _get_print_lines_for_load_tests(load_tests4)
        uuids5 = _get_print_lines_for_load_tests(load_tests5)

        result = self.execute("list")

        expect(result).to_be_like((BASE_LOAD_TESTS_TABLE_PRINT * 5) % (
            team1.name, project1.name, "".join(uuids1),
            team1.name, project2.name, "".join(uuids2),
            team2.name, project3.name, "".join(uuids3),
            team2.name, project4.name, "".join(uuids4),
            team2.name, project5.name, "".join(uuids5)
        ))
예제 #13
0
    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)
예제 #14
0
    def test_list_load_tests_by_team_and_project(self):
        team = TeamFactory.create(owner=self.user)
        TeamFactory.add_projects(team, 1)
        project = team.projects[0]
        LoadTestFactory.add_to_project(25, user=self.user, team=team, project=project)

        load_tests = LoadTest.get_sliced_by_team_and_project_name(team, project.name, 20)
        uuids = _get_print_lines_for_load_tests(load_tests)

        result = self.execute("list", team=team.name, project=project.name)
        expect(result).to_be_like(BASE_LOAD_TESTS_TABLE_PRINT % (team.name, project.name, "".join(uuids)))
예제 #15
0
 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()
예제 #16
0
 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()
예제 #17
0
 def test_get_last_5_tests_for_a_team_ordered_by_date_created_desc(self):
     LoadTestFactory.add_to_project(7, user=self.user, team=self.team, project=self.project)
     LoadTestFactory.add_to_project(6, user=self.user, team=self.team, project=self.team.projects[1])
     LoadTestFactory.add_to_project(6, user=self.user)
     loaded_tests = list(LoadTest.get_by_team(self.team))
     expect(loaded_tests).to_length(10)
     load_tests_for_project1 = [load_test for load_test in loaded_tests if load_test.project_name == self.project.name]
     expect(load_tests_for_project1).to_length(5)
     another_project_name = self.team.projects[1].name
     load_tests_for_project2 = [load_test for load_test in loaded_tests if load_test.project_name == another_project_name]
     expect(load_tests_for_project2).to_length(5)
예제 #18
0
    def test_list_load_tests_by_team_only(self):
        team = TeamFactory.create(owner=self.user)
        TeamFactory.add_projects(team, 2)
        project1 = team.projects[0]
        project2 = team.projects[1]
        LoadTestFactory.add_to_project(7, user=self.user, team=team, project=project1)
        LoadTestFactory.add_to_project(7, user=self.user, team=team, project=project2)

        load_tests1 = LoadTest.get_sliced_by_team_and_project_name(team, project1.name, 5)
        load_tests2 = LoadTest.get_sliced_by_team_and_project_name(team, project2.name, 5)

        uuids1 = _get_print_lines_for_load_tests(load_tests1)
        uuids2 = _get_print_lines_for_load_tests(load_tests2)

        result = self.execute("list", team=team.name)

        expect(result).to_be_like((BASE_LOAD_TESTS_TABLE_PRINT * 2) % (
            team.name, project1.name, "".join(uuids1),
            team.name, project2.name, "".join(uuids2)
        ))
예제 #19
0
    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'])
예제 #20
0
 def get(self, uuid):
     self.set_status(200)
     try:
         last_result = LoadTest.get_last_result_for(uuid)
         if last_result:
             self.write(dumps(last_result.to_dict()))
         else:
             self.set_status(404)
     except DoesNotExist:
         self.set_status(404)
     finally:
         self.finish()
예제 #21
0
 def get(self, uuid):
     self.set_status(200)
     try:
         last_result = LoadTest.get_last_result_for(uuid)
         if last_result:
             self.write(dumps(last_result.to_dict()))
         else:
             self.set_status(404)
     except DoesNotExist:
         self.set_status(404)
     finally:
         self.finish()
예제 #22
0
 def get(self, team_name, project_name, module, class_name, test_name):
     self.set_status(200)
     try:
         team = Team.objects(name=team_name).first()
         results = LoadTest.get_same_results_for_all_load_tests_from_project(team, project_name, module, class_name, test_name)
         response = []
         for result in results:
             response.append(result.to_dict())
         self.write(dumps(response))
     except DoesNotExist:
         self.set_status(404)
     finally:
         self.finish()
예제 #23
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.")
예제 #24
0
 def get(self, team_name, project_name, module, class_name, test_name):
     self.set_status(200)
     try:
         team = Team.objects(name=team_name).first()
         results = LoadTest.get_same_results_for_all_load_tests_from_project(
             team, project_name, module, class_name, test_name)
         response = []
         for result in results:
             response.append(result.to_dict())
         self.write(dumps(response))
     except DoesNotExist:
         self.set_status(404)
     finally:
         self.finish()
예제 #25
0
    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())
예제 #26
0
    def test_schedule_a_test_in_a_specific_branch(self):
        url = "/teams/%s/projects/%s/load_tests/" % (self.team.name, self.project.name)
        response = self.post(url, **{
            "base_url": "http://www.globo.com",
            "branch": "test-branch"
        })
        expect(response.code).to_equal(200)
        expect(response.body).to_equal("OK")

        tests = list(LoadTest.get_by_team_and_project_name(self.team, self.project.name))
        expect(tests).not_to_be_null()
        expect(tests).to_length(1)
        expect(tests[0].base_url).to_equal("http://www.globo.com")
        expect(tests[0].git_branch).to_equal("test-branch")
예제 #27
0
    def post(self, team, project_name):
        base_url = self.get_argument("base_url").strip()
        branch = self.get_argument("branch", strip=True, default=None)
        simple = self.get_argument("simple", "false") == "true"

        if not base_url or not URL_RE.match(base_url):
            self.set_status(400)
            self.finish()
            return

        project = [project for project in team.projects if project.name.lower().strip() == project_name.lower().strip()] or None
        if not project:
            self.set_status(404)
            self.finish()
            return

        project = project[0]

        test = LoadTest(
            status="Scheduled",
            base_url=base_url,
            team=team,
            created_by=self.current_user,
            project_name=project.name,
            simple=simple
        )

        if branch:
            test.git_branch = branch

        test.save()

        self.application.resq.enqueue(WorkerJob, str(test.uuid))

        self.set_status(200)
        self.write("OK")
        self.finish()
예제 #28
0
 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)
예제 #29
0
    def get(self, team, project_name, test_uuid, result_uuid=None):
        project = [project for project in team.projects if project.name == project_name]
        if not project:
            self.set_status(404)
            self.finish()
            return
        load_test = [
            load_test
            for load_test in
            LoadTest.get_sliced_by_team_and_project_name(team, project_name, 1)
            if str(load_test.uuid) == test_uuid
        ]
        if not load_test:
            self.set_status(404)
            self.finish()
            return

        try:
            load_test, test_result = LoadTest.get_test_result(result_uuid)
            self.write(dumps(test_result.to_dict()))
            self.set_status(200)
        except DoesNotExist:
            self.set_status(404)
        self.finish()
예제 #30
0
    def test_get_last_result_for_diff(self):
        config = TestConfigurationFactory.build()
        self.load_test.results.append(TestResultFactory.build(config=config))
        self.load_test.results.append(TestResultFactory.build())
        self.load_test.save()
        load_test2 = LoadTestFactory.add_to_project(1, user=self.user, team=self.team, project=self.project, status="Finished")
        load_test2.results.append(TestResultFactory.build())
        load_test2.results.append(TestResultFactory.build(config=config))
        load_test2.save()

        result1 = self.load_test.results[0]
        result2 = load_test2.results[1]

        test_result = LoadTest.get_last_result_for(str(result2.uuid))
        expect(str(test_result.uuid)).to_equal(str(result1.uuid))
예제 #31
0
    def test_schedule_test(self):
        url = "/teams/%s/projects/%s/load_tests/" % (self.team.name, self.project.name)
        response = self.post(url, **{
            "base_url": "http://www.globo.com"
        })
        expect(response.code).to_equal(200)
        expect(response.body).to_equal("OK")

        tests = list(LoadTest.get_by_team_and_project_name(self.team, self.project.name))
        expect(tests).not_to_be_null()
        expect(tests).to_length(1)
        expect(tests[0].created_by.id).to_equal(self.user.id)
        expect(tests[0].project_name).to_equal(self.project.name)
        expect(tests[0].base_url).to_equal("http://www.globo.com")
        expect(tests[0].simple).to_be_false()
예제 #32
0
    def test_schedule_test(self):
        url = "/teams/%s/projects/%s/load_tests/" % (self.team.name,
                                                     self.project.name)
        response = self.post(url, **{"base_url": "http://www.globo.com"})
        expect(response.code).to_equal(200)
        expect(response.body).to_equal("OK")

        tests = list(
            LoadTest.get_by_team_and_project_name(self.team,
                                                  self.project.name))
        expect(tests).not_to_be_null()
        expect(tests).to_length(1)
        expect(tests[0].created_by.id).to_equal(self.user.id)
        expect(tests[0].project_name).to_equal(self.project.name)
        expect(tests[0].base_url).to_equal("http://www.globo.com")
        expect(tests[0].simple).to_be_false()
예제 #33
0
    def test_schedule_a_test_in_a_specific_branch(self):
        url = "/teams/%s/projects/%s/load_tests/" % (self.team.name,
                                                     self.project.name)
        response = self.post(
            url, **{
                "base_url": "http://www.globo.com",
                "branch": "test-branch"
            })
        expect(response.code).to_equal(200)
        expect(response.body).to_equal("OK")

        tests = list(
            LoadTest.get_by_team_and_project_name(self.team,
                                                  self.project.name))
        expect(tests).not_to_be_null()
        expect(tests).to_length(1)
        expect(tests[0].base_url).to_equal("http://www.globo.com")
        expect(tests[0].git_branch).to_equal("test-branch")
예제 #34
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."
        )
예제 #35
0
    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()
예제 #36
0
    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())
예제 #37
0
    def test_can_run_funkload(self):
        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)
        load_test.pressure = "small"

        conf = WightConfig.load(join(root_path, 'bench', 'wight.yml'))
        test = conf.tests[0]

        DEFAULT_CYCLES = {
            "small": [10, 20],
            "medium": [10, 20, 30],
            "large": [30, 75, 100],
        }

        fl_result = FunkLoadBenchRunner.run(root_path,
                                            test,
                                            self.base_url,
                                            cycles=DEFAULT_CYCLES,
                                            duration=5)

        expect(fl_result).not_to_be_null()
        expect(fl_result.exit_code).to_equal(0)

        expect(fl_result.text).to_include("SUCCESSFUL")

        expect(fl_result.log).to_be_empty()

        expect(fl_result.result).not_to_be_null()
        expect(fl_result.config).not_to_be_null()

        result = LoadTest.get_data_from_funkload_results(
            fl_result.config, fl_result.result)

        load_test.add_result(result, fl_result.text)

        expect(load_test.results).to_length(1)
예제 #38
0
    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")
예제 #39
0
    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")
예제 #40
0
 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": []
         }
     )
예제 #41
0
    def test_get_results_for_team_project_and_test_get_finished_only(self):
        config = TestConfigurationFactory.build()
        self.load_test.results.append(TestResultFactory.build(config=config))
        self.load_test.results.append(TestResultFactory.build())
        self.load_test.results.append(TestResultFactory.build(config=config))
        self.load_test.save()
        load_test2 = LoadTestFactory.add_to_project(1, user=self.user, team=self.team, project=self.project, status="Failed")
        load_test2.results.append(TestResultFactory.build())
        load_test2.results.append(TestResultFactory.build(config=config))
        load_test2.save()
        load_test3 = LoadTestFactory.add_to_project(1, user=self.user, team=self.team, project=self.project)
        load_test3.results.append(TestResultFactory.build())
        load_test3.results.append(TestResultFactory.build(config=config))
        load_test3.save()

        results = [str(result.uuid) for result in LoadTest.get_same_results_for_all_load_tests_from_project(self.team, self.project.name, config.module, config.class_name, config.test_name)]

        expected_results = [
            str(self.load_test.results[0].uuid),
            str(self.load_test.results[2].uuid),
        ]

        expect(results).to_be_like(expected_results)
예제 #42
0
 def test_should_raise_not_found_if_no_load_test_found(self):
     try:
         LoadTest.get_test_result(uuid4())
         assert False, "Should have raise NotFound in mongo"
     except DoesNotExist:
         assert True
예제 #43
0
 def test_get_results_for_team_project_and_test_raise_does_not_exists_if_not_found(self):
     try:
         LoadTest.get_same_results_for_all_load_tests_from_project(self.team, "no-project", "module", "class_name", "test_name")
         assert False, "Should have raise NotFound in mongo"
     except DoesNotExist:
         assert True
예제 #44
0
    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")