Пример #1
0
 def test_increments_count_if_not_set(self, redis_conn):
     """ Increments count when not set """
     redis_conn.return_value.hdel(config["redis", "_pop_interval_hash"],
                                  "a_count")
     rm.update_pop_interval_stat("a")
     assert redis_conn.return_value.hget(
         config["redis", "_pop_interval_hash"], "a_count") == b"1"
Пример #2
0
 def test_no_overwrite_existing_start_value(self, redis_conn):
     """ Does not overwrite an existing start value """
     redis_conn.return_value.hset(config["redis", "_pop_interval_hash"],
                                  "a_start", "a")
     rm.update_pop_interval_stat("a")
     assert redis_conn.return_value.hget(
         config["redis", "_pop_interval_hash"], "a_start") == b"a"
Пример #3
0
def run_test(client_type: str, test_data: Dict, enqueue_time: int,
             test_categories: List[str]) -> None:
    """
    Run autotesting tests using the tests in the test_specs json file on the files in files_path.

    This function should be used by an rq worker.
    """
    results = []
    error = None
    hooks_error = None
    time_to_service = int(round(time.time() - enqueue_time, 3) * 1000)
    client = get_client(client_type, test_data)

    try:
        job = rq.get_current_job()
        update_pop_interval_stat(job.origin)
        test_username, tests_path = tester_user()
        try:
            _setup_files(client, tests_path, test_username)
            cmd = _run_test_command(test_username=test_username)
            results, hooks_error = _run_test_specs(cmd, client,
                                                   test_categories, tests_path,
                                                   test_username)
        finally:
            _stop_tester_processes(test_username)
            _clear_working_directory(tests_path, test_username)
    except Exception as e:
        error = str(e)
    finally:
        results_data = _finalize_results_data(results, error, hooks_error,
                                              time_to_service)
        _store_results(client, results_data)
        client.send_test_results(results_data)
Пример #4
0
 def test_updates_last_value_if_set(self, redis_conn):
     """ Sets the last value if it does exist """
     redis_conn.return_value.hset(config["redis", "_pop_interval_hash"],
                                  "a_last", "a")
     rm.update_pop_interval_stat("a")
     assert float(
         redis_conn.return_value.hget(config["redis", "_pop_interval_hash"],
                                      "a_last")) < float(time.time())
Пример #5
0
 def test_creates_start_value(self, redis_conn):
     """ Sets the start value if it does not exist """
     redis_conn.return_value.hdel(config["redis", "_pop_interval_hash"],
                                  "a_start")
     rm.update_pop_interval_stat("a")
     start_val = float(
         redis_conn.return_value.hget(config["redis", "_pop_interval_hash"],
                                      "a_start"))
     assert start_val < float(time.time())
Пример #6
0
def run_test(
    markus_address,
    server_api_key,
    test_categories,
    files_path,
    assignment_id,
    group_id,
    group_repo_name,
    submission_id,
    run_id,
    enqueue_time,
):
    """
    Run autotesting tests using the tests in the test_specs json file on the files in files_path.

    This function should be used by an rq worker.
    """
    results = []
    error = None
    hooks_error = None
    time_to_service = int(round(time.time() - enqueue_time, 3) * 1000)

    test_script_path = test_script_directory(markus_address, assignment_id)
    hooks_script_path = os.path.join(test_script_path, HOOKS_FILENAME)
    test_specs_path = os.path.join(test_script_path, SETTINGS_FILENAME)
    api = Markus(server_api_key, markus_address)

    with open(test_specs_path) as f:
        test_specs = json.load(f)

    try:
        job = rq.get_current_job()
        update_pop_interval_stat(job.origin)
        test_username, tests_path = tester_user()
        hooks_kwargs = {
            "api": api,
            "assignment_id": assignment_id,
            "group_id": group_id,
        }
        testers = {
            settings["tester_type"]
            for settings in test_specs["testers"]
        }
        hooks = Hooks(hooks_script_path,
                      testers,
                      cwd=tests_path,
                      kwargs=hooks_kwargs)
        try:
            setup_files(files_path, tests_path, markus_address, assignment_id)
            cmd = run_test_command(test_username=test_username)
            results, hooks_error = run_test_specs(cmd, test_specs,
                                                  test_categories, tests_path,
                                                  test_username, hooks)
        finally:
            stop_tester_processes(test_username)
            clear_working_directory(tests_path, test_username)
    except Exception as e:
        error = str(e)
    finally:
        results_data = finalize_results_data(results, error, hooks_error,
                                             time_to_service)
        store_results(results_data, markus_address, assignment_id, group_id,
                      submission_id)
        report(results_data, api, assignment_id, group_id, run_id)