Esempio n. 1
0
    def test_status_result_is_set(self):
        class MyUser(User):
            wait_time = constant(1)

            @task(1)
            def my_task(self):
                pass

        self.environment.user_classes = [MyUser]

        response = requests.post(
            "http://127.0.0.1:%i/swarm" % self.web_port,
            data={
                'user_count': 5,
                'spawn_rate': 5
            },
        )
        self.assertEqual(200, response.status_code)

        reason = 'Oops'
        set_result(self.runner, RESULT_FAIL, reason)
        response = requests.get("http://127.0.0.1:%i/status" % self.web_port)
        print('response', response.text)
        self.assertEqual(200, response.status_code)

        result = response.json()['result']
        assert result['value'] == RESULT_FAIL
        assert result['reason'] == reason

        worker_count = response.json()['worker_count']
        assert worker_count == None
def test_set_result_again_warn_to_fail():
    mr = _MockRunner()

    set_result(mr, RESULT_WARN, "Up there")
    assert mr.result.value == RESULT_WARN
    assert mr.result.reason == "Up there"

    set_result(mr, RESULT_FAIL, "Out of bounds!")
    assert mr.result.value == RESULT_FAIL
    assert mr.result.reason == "Out of bounds!"
def test_set_non_standard_result_twice(caplog):
    mr = _MockRunner()
    set_result(mr, 'hip hip', "Lagkage")
    assert mr.result.value == 'hip hip'
    assert mr.result.reason == "Lagkage"

    set_result(mr, 'hurra', "Kagemand")
    assert mr.result.value == 'hurra'
    assert mr.result.reason == "Kagemand"

    assert _check_log_record(
        "Non standard result values in use: 'hip hip', 'hurra'. No check, we don't know the order.",
        caplog)
def test_set_result_again_fail_to_warn_ignored(caplog):
    mr = _MockRunner()

    set_result(mr, RESULT_FAIL, "Out of bounds!")
    assert mr.result.value == RESULT_FAIL
    assert mr.result.reason == "Out of bounds!"

    set_result(
        mr, RESULT_WARN, "Up there"
    )  # This will not change result as we do no go from worse to better
    assert mr.result.value == RESULT_FAIL
    assert mr.result.reason == "Out of bounds!"

    assert _check_log_record(
        "NOT changing result from 'fail' to 'warning': 'Up there', we will not go from worse to better!",
        caplog)
def test_set_first_result():
    mr = _MockRunner()
    set_result(mr, RESULT_PASS, "Nice")
    assert mr.result.value == RESULT_PASS
    assert mr.result.reason == "Nice"