Exemplo n.º 1
0
def test_index_auto(client, treatment, prefix=""):
    #takes the role assigned by the system and solves the corresponding tasks
    client = None
    job_id = "test_auto"
    for _ in range(TASK_REPETITION):
        auto_worker_id = generate_worker_id(f"{prefix}index_auto")
        path = f"/{treatment}/?worker_id={auto_worker_id}&job_id={job_id}"
        with app.test_request_context(path):
            client = get_client()
            res = client.get(path, follow_redirects=True)
            time.sleep(0.001)
            # Play as responder
            # print(res.data)
            if b"role of a RESPONDER" in res.data:
                # res = _process_resp(client, treatment, job_id=job_id, worker_id=auto_worker_id, min_offer=MIN_OFFER)
                # process_tasks(client, job_id=job_id, worker_id=auto_worker_id, bonus_mode="full", url_kwargs={"auto_finalize": 1, "treatment": treatment})
                res = _process_resp_tasks(client, treatment, job_id=job_id, worker_id=auto_worker_id, min_offer=get_min_offer())
                assert b"resp:" in res.data
                assert is_worker_available(auto_worker_id, get_table("resp", job_id=job_id, schema="result"))
            # Play a proposer
            elif b"role of a PROPOSER" in res.data:
                app.logger.warning("PROPOSER")
                res = client.get(path, follow_redirects=True)
                res = _process_prop_round(client, treatment, job_id=job_id, worker_id=auto_worker_id, offer=get_offer(), response_available=True)
                assert b"prop:" in res.data
                assert is_worker_available(auto_worker_id, get_table("resp", job_id=job_id, schema="result"))
            else:
                assert False, "Nooooooooooooooo"
            time.sleep(WEBHOOK_DELAY)
Exemplo n.º 2
0
def test_index(client, treatment, prefix="", completion_code_prefix="resp:", resp_feedback_fields=None):
    client = None
    job_id = "test"
    completion_code_prefix_bytes = completion_code_prefix.encode("utf-8") if completion_code_prefix else b"resp:"
    for _ in range(TASK_REPETITION):
        client = get_client()
        resp_worker_id = generate_worker_id(f"{prefix}index_resp")
        path = f"/{treatment}/?worker_id={resp_worker_id}"
        with app.test_request_context(path):
            res = client.get(path, follow_redirects=True)
            assert b"RESPONDER" in res.data
            # res = _process_resp_tasks(client, worker_id=worker_id)

            res = _process_resp(client, treatment, job_id=job_id, worker_id=resp_worker_id, min_offer=get_min_offer(), resp_feedback_fields=resp_feedback_fields)
            process_tasks(client, job_id=job_id, worker_id=resp_worker_id, bonus_mode="random", url_kwargs={"auto_finalize": 1, "treatment": treatment})
            assert completion_code_prefix_bytes in res.data
        time.sleep(WEBHOOK_DELAY)
        # let the auto-responder kick-in
        with app.app_context():
            # let the auto-responder kick-in
            for _ in range(NB_MAX_AUTO_PLAY_RETRIES):
                if is_resp_in_prop_result(resp_worker_id, job_id, treatment):
                    break
                time.sleep(AUTO_PROP_DELAY)
            assert is_resp_in_prop_result(resp_worker_id, job_id, treatment)
Exemplo n.º 3
0
def test_bonus_nodelay(client, treatment, synchron=True):
    # In real conditions, the tasks/webhook are delayed with +500 ms
    for _ in range(TASK_REPETITION):
        client = get_client()
        job_id = "test"
        resp_worker_id = generate_worker_id("bonus_resp")
        prop_worker_id = generate_worker_id("bonus_prop")
        _process_resp_tasks(client,
                            treatment,
                            worker_id=resp_worker_id,
                            min_offer=MIN_OFFER,
                            bonus_mode="random",
                            synchron=synchron)
        _process_prop_round(client,
                            treatment,
                            worker_id=prop_worker_id,
                            offer=OFFER,
                            response_available=True,
                            synchron=synchron)
        with app.app_context():
            bonus_resp = get_worker_bonus(job_id, resp_worker_id)
            assert MIN_OFFER <= bonus_resp
            assert bonus_resp <= tasks.MAX_BONUS + (MAX_GAIN - OFFER)
            bonus_prop = get_worker_bonus(job_id, prop_worker_id)
            assert bonus_prop == OFFER
Exemplo n.º 4
0
def test_index(client,
               treatment,
               prefix="",
               response_available=False,
               resp_feedback_fields=None):
    client = None
    job_id = "test"
    for _ in range(TASK_REPETITION):
        client = get_client()
        if not response_available:
            resp_worker_id = generate_worker_id(f"{prefix}index_resp")
            path = f"/{treatment}/?worker_id={resp_worker_id}"
            with app.test_request_context(path):
                res = client.get(path, follow_redirects=True)
                assert b"RESPONDER" in res.data
                # res = _process_resp_tasks(client, worker_id=worker_id)

                res = _process_resp(client,
                                    treatment,
                                    job_id=job_id,
                                    worker_id=resp_worker_id,
                                    min_offer=get_min_offer(),
                                    resp_feedback_fields=resp_feedback_fields)
                process_tasks(client,
                              job_id=job_id,
                              worker_id=resp_worker_id,
                              bonus_mode="random",
                              url_kwargs={
                                  "auto_finalize": 1,
                                  "treatment": treatment
                              })
                assert b"resp:" in res.data
        prop_worker_id = generate_worker_id(f"{prefix}index_prop")
        time.sleep(WEBHOOK_DELAY)
        path = f"/{treatment}/?worker_id={prop_worker_id}"
        with app.test_request_context(path):
            res = client.get(path, follow_redirects=True)
            # assert b"PROPOSER" in res.data
            res = _process_prop_round(client,
                                      treatment,
                                      worker_id=prop_worker_id,
                                      offer=get_offer(),
                                      response_available=True)
            assert b"prop:" in res.data
Exemplo n.º 5
0
def test_bonus_nodelay(client, treatment, synchron=True, resp_feedback_fields=None):
    # In real conditions, the tasks/webhook are delayed with +500 ms
    # we make sure the offer is accepted!
    min_offer = 0
    for _ in range(TASK_REPETITION):
        client = get_client()
        job_id = "test"
        resp_worker_id = generate_worker_id("bonus_resp")
        _process_resp_tasks(client, treatment, worker_id=resp_worker_id, min_offer=min_offer, bonus_mode="random", synchron=synchron, resp_feedback_fields=resp_feedback_fields)

        time.sleep(WEBHOOK_DELAY)
        with app.app_context():
            # let the auto-responder kick-in
            for _ in range(NB_MAX_AUTO_PLAY_RETRIES):
                if is_resp_in_prop_result(resp_worker_id, job_id, treatment):
                    break
                time.sleep(AUTO_PROP_DELAY)
            bonus_resp = get_worker_bonus(job_id, resp_worker_id)
            assert min_offer <= bonus_resp
            assert bonus_resp <=  tasks.MAX_BONUS + (MAX_GAIN - OFFER)
            assert is_resp_in_prop_result(resp_worker_id, job_id, treatment)
Exemplo n.º 6
0
def test_index_feedback(client,
                        treatment,
                        prefix="",
                        response_available=False,
                        resp_feedback_fields=None):
    client = None
    job_id = "test"
    for _ in range(TASK_REPETITION):
        client = get_client()
        if not response_available:
            resp_worker_id = generate_worker_id(f"{prefix}index_feedback_resp")
            path = f"/{treatment}/?worker_id={resp_worker_id}"
            with app.test_request_context(path):
                res = client.get(path, follow_redirects=True)
                assert b"RESPONDER" in res.data
                # res = _process_resp_tasks(client, worker_id=worker_id)

                res = _process_resp(client,
                                    treatment,
                                    job_id=job_id,
                                    worker_id=resp_worker_id,
                                    min_offer=get_min_offer(),
                                    resp_feedback_fields=resp_feedback_fields)
                assert b"resp:" in res.data
        else:
            prop_worker_id = generate_worker_id(f"{prefix}index_prop")
            path = f"/{treatment}/?worker_id={prop_worker_id}"
            with app.test_request_context(path):
                res = client.get(path, follow_redirects=True)
                res = _process_prop_round(client,
                                          treatment,
                                          worker_id=prop_worker_id,
                                          offer=get_offer(),
                                          response_available=True,
                                          finalize_round=False)
                assert b"prop:" in res.data