Example #1
0
def test_simple_schedule(
    labels_to_choose,
    groups_to_choose,
    monkeypatch,
    mock_hgmo,
    mock_repo,
    mock_component_taskcluster_artifact,
    mock_schedule_tests_classify,
):
    # The repo should be almost empty at first
    repo_dir, _ = mock_repo
    repo = hglib.open(str(repo_dir))
    assert len(repo.log()) == 4
    test_txt = repo_dir / "test.txt"
    assert test_txt.exists()
    assert test_txt.read_text("utf-8") == "Version 3"

    mock_schedule_tests_classify(labels_to_choose, groups_to_choose)

    # Scheduling a test on a revision should apply changes in the repo
    assert models.schedule_tests("mozilla-central", "12345deadbeef") == "OK"

    # Check changes have been applied
    assert len(repo.log()) == 5
    assert test_txt.read_text("utf-8") == "Version 3\nThis is a new line\n"

    # Assert the test selection result is stored in Redis.
    assert json.loads(
        models.redis.get(
            "bugbug:job_result:schedule_tests:mozilla-central_12345deadbeef")
    ) == {
        "tasks": labels_to_choose,
        "groups": groups_to_choose,
    }
Example #2
0
def test_simple_schedule(
    labels_to_choose: dict[str, float],
    groups_to_choose: dict[str, float],
    reduced_labels: dict[str, float],
    config_groups: dict[str, list[str]],
    mock_hgmo: None,
    mock_repo: tuple[str, str],
    mock_component_taskcluster_artifact: None,
    mock_coverage_mapping_artifact: None,
    mock_schedule_tests_classify: Callable[
        [dict[str, float], dict[str, float]], None],
) -> None:
    # The repo should be almost empty at first
    repo_dir, remote_repo_dir = mock_repo
    with hglib.open(str(repo_dir)) as hg:
        logs = hg.log()
        assert len(logs) == 4
        assert [log.desc.decode("utf-8") for log in logs] == [
            "Base history 3",
            "Base history 2",
            "Base history 1",
            "Base history 0",
        ]
    with hglib.open(str(remote_repo_dir)) as hg:
        rev = hg.log()[0].node.decode("ascii")[:12]

    mock_schedule_tests_classify(labels_to_choose, groups_to_choose)

    # Scheduling a test on a revision should apply changes in the repo
    assert models.schedule_tests("mozilla-central", rev) == "OK"

    # Check changes have been applied
    with hglib.open(str(repo_dir)) as hg:
        assert len(hg.log()) == 5
        assert [log.desc.decode("utf-8") for log in hg.log()] == [
            "Pulled from remote",
            "Base history 3",
            "Base history 2",
            "Base history 1",
            "Base history 0",
        ]

    # Assert the test selection result is stored in Redis.
    value = models.redis.get(
        f"bugbug:job_result:schedule_tests:mozilla-central_{rev}")
    assert value is not None
    result = orjson.loads(zstandard.ZstdDecompressor().decompress(value))
    assert len(result) == 6
    assert result["tasks"] == labels_to_choose
    assert result["groups"] == groups_to_choose
    assert result["reduced_tasks"] == reduced_labels
    assert result["reduced_tasks_higher"] == reduced_labels
    assert result["known_tasks"] == ["prova"]
    assert {k: set(v)
            for k, v in result["config_groups"].items()
            } == {k: set(v)
                  for k, v in config_groups.items()}
Example #3
0
def test_simple_schedule(
    labels_to_choose: Dict[str, float],
    groups_to_choose: Dict[str, float],
    reduced_labels: Dict[str, float],
    config_groups: Dict[str, List[str]],
    mock_hgmo: None,
    mock_repo: Tuple[str, str],
    mock_component_taskcluster_artifact: None,
    mock_schedule_tests_classify: Callable[
        [Dict[str, float], Dict[str, float]], None],
) -> None:
    # The repo should be almost empty at first
    repo_dir, remote_repo_dir = mock_repo
    with hglib.open(str(repo_dir)) as hg:
        logs = hg.log()
        assert len(logs) == 4
        assert [log.desc.decode("utf-8") for log in logs] == [
            "Base history 3",
            "Base history 2",
            "Base history 1",
            "Base history 0",
        ]
    with hglib.open(str(remote_repo_dir)) as hg:
        rev = hg.log()[0].node.decode("ascii")[:12]

    mock_schedule_tests_classify(labels_to_choose, groups_to_choose)

    # Scheduling a test on a revision should apply changes in the repo
    assert models.schedule_tests("mozilla-central", rev) == "OK"

    # Check changes have been applied
    with hglib.open(str(repo_dir)) as hg:
        assert len(hg.log()) == 5
        assert [log.desc.decode("utf-8") for log in hg.log()] == [
            "Pulled from remote",
            "Base history 3",
            "Base history 2",
            "Base history 1",
            "Base history 0",
        ]

    # Assert the test selection result is stored in Redis.
    assert json.loads(
        models.redis.get(
            f"bugbug:job_result:schedule_tests:mozilla-central_{rev}")) == {
                "tasks": labels_to_choose,
                "groups": groups_to_choose,
                "reduced_tasks": reduced_labels,
                "reduced_tasks_higher": reduced_labels,
                "known_tasks": ["prova"],
                "config_groups": config_groups,
            }
Example #4
0
def test_simple_schedule(patch_resources, mock_hgmo, mock_repo):

    # The repo should be almost empty at first
    repo_dir, repo = mock_repo
    assert len(repo.log()) == 4
    test_txt = repo_dir / "test.txt"
    assert test_txt.exists()
    assert test_txt.read_text("utf-8") == "Version 3"

    # Scheduling a test on a revision should apply changes in the repo
    assert schedule_tests("mozilla-central", "12345deadbeef") == "OK"

    # Check changes have been applied
    assert len(repo.log()) == 5
    assert test_txt.read_text("utf-8") == "Version 3\nThis is a new line\n"
def test_simple_schedule(
    labels_to_choose,
    groups_to_choose,
    reduced_labels,
    monkeypatch,
    mock_hgmo,
    mock_repo,
    mock_component_taskcluster_artifact,
    mock_schedule_tests_classify,
):
    # The repo should be almost empty at first
    repo_dir, remote_repo_dir = mock_repo
    with hglib.open(str(repo_dir)) as hg:
        logs = hg.log()
        assert len(logs) == 4
        assert [l.desc.decode("utf-8") for l in logs] == [
            "Base history 3",
            "Base history 2",
            "Base history 1",
            "Base history 0",
        ]
    with hglib.open(str(remote_repo_dir)) as hg:
        rev = hg.log()[-1].node.decode("ascii")[:12]

    mock_schedule_tests_classify(labels_to_choose, groups_to_choose)

    # Scheduling a test on a revision should apply changes in the repo
    assert models.schedule_tests("mozilla-central", rev) == "OK"

    # Check changes have been applied
    with hglib.open(str(repo_dir)) as hg:
        assert len(hg.log()) == 5
        assert [l.desc.decode("utf-8") for l in hg.log()] == [
            "Bug 1 - Pulled from remote",
            "Base history 3",
            "Base history 2",
            "Base history 1",
            "Base history 0",
        ]

    # Assert the test selection result is stored in Redis.
    assert json.loads(
        models.redis.get(
            f"bugbug:job_result:schedule_tests:mozilla-central_{rev}")) == {
                "tasks": labels_to_choose,
                "groups": groups_to_choose,
                "reduced_tasks": reduced_labels,
            }
Example #6
0
def test_schedule(
    branch,
    revision,
    result,
    final_log,
    patch_resources,
    mock_hgmo,
    mock_repo,
    mock_component_taskcluster_artifact,
    mock_schedule_tests_classify,
):

    # The repo should only have the base commits
    repo_dir, _ = mock_repo
    repo = hglib.open(str(repo_dir))
    logs = repo.log(follow=True)
    assert len(logs) == 4
    assert [l.desc.decode("utf-8") for l in logs] == [
        "Base history 3",
        "Base history 2",
        "Base history 1",
        "Base history 0",
    ]

    mock_schedule_tests_classify({"test-label1": 0.9}, {"test-group2": 0.9})

    # Schedule tests for parametrized revision
    assert models.schedule_tests(branch, revision) == result

    # Now check the log has evolved
    assert final_log == [l.desc.decode("utf-8") for l in repo.log(follow=True)]

    if result == "OK":
        # Assert the test selection result is stored in Redis.
        assert json.loads(
            models.redis.get(
                f"bugbug:job_result:schedule_tests:{branch}_{revision}")) == {
                    "tasks": {
                        "test-label1": 0.9
                    },
                    "groups": {
                        "test-group2": 0.9
                    },
                    "reduced_tasks": {
                        "test-label1": 0.9
                    },
                }
Example #7
0
def test_schedule(branch, revision, result, final_log, patch_resources,
                  mock_hgmo, mock_repo):

    # The repo should only have the base commits
    repo_dir, repo = mock_repo
    logs = repo.log(follow=True)
    assert len(logs) == 4
    assert [l.desc.decode("utf-8") for l in logs] == [
        "Base history 3",
        "Base history 2",
        "Base history 1",
        "Base history 0",
    ]

    # Schedule tests for parametrized revision
    assert schedule_tests(branch, revision) == result

    # Now check the log has evolved
    assert final_log == [l.desc.decode("utf-8") for l in repo.log(follow=True)]