Skip to content

Commit

Permalink
fix: redefine should_read|write_flaky_tests
Browse files Browse the repository at this point in the history
we should write if:
FLAKY_SHADOW_MODE or FLAKE_DETECTION feature flags are enabled
AND the user has not disabled flake detection via the config

we should read if:
FLAKE_DETECTION feature flag is enabled
AND the user has not disabled flake detection via the config
  • Loading branch information
joseph-sentry committed Sep 3, 2024
1 parent 83357e6 commit 4e2ba9b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 26 deletions.
11 changes: 4 additions & 7 deletions services/test_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,14 +402,11 @@ def latest_test_instances_for_a_given_commit(db_session, commit_id):
def should_write_flaky_detection(repoid: int, commit_yaml: UserYaml) -> bool:
return (
FLAKY_TEST_DETECTION.check_value(identifier=repoid, default=False)
and read_yaml_field(commit_yaml, ("test_analytics", "flake_detection"), False)
or FLAKY_SHADOW_MODE.check_value(identifier=repoid, default=False)
)
) and read_yaml_field(commit_yaml, ("test_analytics", "flake_detection"), True)


def should_read_flaky_detection(repoid: int, commit_yaml: UserYaml) -> bool:
return (
FLAKY_TEST_DETECTION.check_value(identifier=repoid, default=False)
and read_yaml_field(commit_yaml, ("test_analytics", "flake_detection"), False)
or FLAKY_SHADOW_MODE.check_value(identifier=repoid, default=False)
)
return FLAKY_TEST_DETECTION.check_value(
identifier=repoid, default=False
) and read_yaml_field(commit_yaml, ("test_analytics", "flake_detection"), True)
16 changes: 9 additions & 7 deletions tasks/tests/unit/test_sync_pull.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,21 @@

class TestPullSyncTask(object):
@pytest.mark.parametrize(
"flake_detection,flaky_shadow_mode,tests_exist,outcome",
"flake_detection_config, flake_detection,flaky_shadow_mode,tests_exist,outcome",
[
(False, False, False, False),
(False, True, False, False),
(True, False, False, False),
(False, True, True, True),
(True, True, True, True),
(False, True, True, True, False),
(True, False, False, False, False),
(True, False, False, True, False),
(True, True, False, True, True),
(True, False, True, True, True),
(True, True, True, True, True),
],
)
def test_update_pull_commits_merged(
self,
dbsession,
mocker,
flake_detection_config,
flake_detection,
flaky_shadow_mode,
tests_exist,
Expand Down Expand Up @@ -108,7 +110,7 @@ def test_update_pull_commits_merged(
current_yaml = UserYaml.from_dict(
{
"test_analytics": {
"flake_detection": flake_detection,
"flake_detection": flake_detection_config,
}
}
)
Expand Down
32 changes: 20 additions & 12 deletions tasks/tests/unit/test_test_results_finisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ def test_upload_finisher_task_call_with_flaky(

@pytest.mark.integration
@pytest.mark.parametrize(
"flake_detection", ["FLAKY_TEST_DETECTION", "FLAKY_SHADOW_MODE"]
"flake_detection", [None, "FLAKY_TEST_DETECTION", "FLAKY_SHADOW_MODE"]
)
def test_upload_finisher_task_call_main_branch(
self,
Expand All @@ -919,13 +919,16 @@ def test_upload_finisher_task_call_main_branch(
test_results_setup,
flake_detection,
):
mock_feature = mocker.patch(f"services.test_results.{flake_detection}")
mock_feature.check_value.return_value = True
if flake_detection:
mock_feature = mocker.patch(f"services.test_results.{flake_detection}")
mock_feature.check_value.return_value = True

Check warning on line 924 in tasks/tests/unit/test_test_results_finisher.py

View check run for this annotation

Codecov Notifications / codecov/patch

tasks/tests/unit/test_test_results_finisher.py#L922-L924

Added lines #L922 - L924 were not covered by tests
commit_yaml = {
"codecov": {"max_report_age": False},
}
if flake_detection == "FLAKY_TEST_DETECTION":
commit_yaml["test_analytics"] = {"flake_detection": True}
elif flake_detection is None:
commit_yaml["test_analytics"] = {"flake_detection": False}

Check warning on line 931 in tasks/tests/unit/test_test_results_finisher.py

View check run for this annotation

Codecov Notifications / codecov/patch

tasks/tests/unit/test_test_results_finisher.py#L930-L931

Added lines #L930 - L931 were not covered by tests

repoid, commit, pull, test_instances = test_results_setup

Expand All @@ -949,12 +952,17 @@ def test_upload_finisher_task_call_main_branch(

assert expected_result == result

test_results_mock_app.tasks[
"app.tasks.flakes.ProcessFlakesTask"
].apply_async.assert_called_with(
kwargs={
"repo_id": repoid,
"commit_id_list": [commit.commitid],
"branch": "main",
},
)
if flake_detection is None:
test_results_mock_app.tasks[

Check warning on line 956 in tasks/tests/unit/test_test_results_finisher.py

View check run for this annotation

Codecov Notifications / codecov/patch

tasks/tests/unit/test_test_results_finisher.py#L955-L956

Added lines #L955 - L956 were not covered by tests
"app.tasks.flakes.ProcessFlakesTask"
].apply_async.assert_not_called()
else:
test_results_mock_app.tasks[

Check warning on line 960 in tasks/tests/unit/test_test_results_finisher.py

View check run for this annotation

Codecov Notifications / codecov/patch

tasks/tests/unit/test_test_results_finisher.py#L960

Added line #L960 was not covered by tests
"app.tasks.flakes.ProcessFlakesTask"
].apply_async.assert_called_with(
kwargs={
"repo_id": repoid,
"commit_id_list": [commit.commitid],
"branch": "main",
},
)

0 comments on commit 4e2ba9b

Please sign in to comment.