diff --git a/services/test_results.py b/services/test_results.py index 5811a4c6f..d934096f9 100644 --- a/services/test_results.py +++ b/services/test_results.py @@ -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) diff --git a/tasks/tests/unit/test_sync_pull.py b/tasks/tests/unit/test_sync_pull.py index b28dacdff..614cd9065 100644 --- a/tasks/tests/unit/test_sync_pull.py +++ b/tasks/tests/unit/test_sync_pull.py @@ -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, @@ -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, } } ) diff --git a/tasks/tests/unit/test_test_results_finisher.py b/tasks/tests/unit/test_test_results_finisher.py index 2032e27e8..9b20970a1 100644 --- a/tasks/tests/unit/test_test_results_finisher.py +++ b/tasks/tests/unit/test_test_results_finisher.py @@ -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, @@ -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 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} repoid, commit, pull, test_instances = test_results_setup @@ -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[ + "app.tasks.flakes.ProcessFlakesTask" + ].apply_async.assert_not_called() + else: + 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", + }, + )