Flagsmith / flagsmith

Open Source Feature Flagging and Remote Config Service. Host on-prem or use our hosted version at https://flagsmith.com/
https://flagsmith.com/
BSD 3-Clause "New" or "Revised" License
4.95k stars 380 forks source link

Flaky unit test in LaunchDarkly importer #4082

Open matthewelwell opened 6 months ago

matthewelwell commented 6 months ago

I haven't invested any time in looking into this, but it looks like we have a flaky unit test in the LD importer functionality. See example below. This failed in CI but seems to pass every time locally.

https://github.com/Flagsmith/flagsmith/actions/runs/9351281565/job/25736647982

=================================== FAILURES ===================================
________________ test_process_import_request__segments_imported ________________
[gw2] linux -- Python 3.12.3 /home/runner/.cache/pypoetry/virtualenvs/flagsmith-api-h9Rv37Cj-py3.12/bin/python

project = <Project: Project Test Project>
import_request = <LaunchDarklyImportRequest: LaunchDarklyImportRequest object (9)>

    def test_process_import_request__segments_imported(
        project: Project,
        import_request: LaunchDarklyImportRequest,
    ):
        # When
        process_import_request(import_request)

        # Then
        segments = Segment.objects.filter(project=project, feature_id=None)

        assert set(segments.values_list("name", flat=True)) == {
            # Segments
            "User List (Override for test)",
            "User List (Override for production)",
            "Dynamic List (Override for test)",
            "Dynamic List (Override for production)",
            "Dynamic List 2 (Override for test)",
            "Dynamic List 2 (Override for production)",
        }

        # Tests for "Dynamic List (Override for test)"
        dynamic_list_test_segment = Segment.objects.get(
            name="Dynamic List (Override for test)"
        )
        dynamic_list_test_segment_rule = SegmentRule.objects.get(
            segment=dynamic_list_test_segment
        )
        # Parents are always "ALL" rules.
        assert dynamic_list_test_segment_rule.type == SegmentRule.ALL_RULE

        dynamic_list_test_segment_subrules = SegmentRule.objects.filter(
            rule=dynamic_list_test_segment_rule
        )
        assert dynamic_list_test_segment_subrules.count() == 1
        # UI needs to have subrules as `ANY_RULE` to display properly.
        assert list(dynamic_list_test_segment_subrules)[0].type == SegmentRule.ANY_RULE

        dynamic_list_test_segment_subrule_conditions = Condition.objects.filter(
            rule=dynamic_list_test_segment_subrules[0]
        )
        assert set(
            dynamic_list_test_segment_subrule_conditions.values_list(
                "property", "operator", "value"
            )
        ) == {
            ("email", segment_constants.REGEX, ".*@gmail\\.com"),
        }

        # Tests for "Dynamic List 2 (Override for production)"
        dynamic_list_2_production_segment = Segment.objects.get(
            name="Dynamic List 2 (Override for production)"
        )
        dynamic_list_2_production_segment_rule = SegmentRule.objects.get(
            segment=dynamic_list_2_production_segment
        )
        # Parents are always "ALL" rules.
        assert dynamic_list_2_production_segment_rule.type == SegmentRule.ALL_RULE

        dynamic_list_2_production_segment_subrules = SegmentRule.objects.filter(
            rule=dynamic_list_2_production_segment_rule
        )
        assert dynamic_list_2_production_segment_subrules.count() == 5
        # UI needs to have subrules as `ANY_RULE` to display properly.
>       assert (
            list(dynamic_list_2_production_segment_subrules)[0].type == SegmentRule.ANY_RULE
        )
E       AssertionError: assert 'NONE' == 'ANY'
E         - ANY
E         + NONE

tests/unit/integrations/launch_darkly/test_services.py:308: AssertionError

---------- coverage: platform linux, python 3.12.3-final-0 -----------
Coverage XML written to file coverage.xml

=========================== short test summary info ============================
FAILED tests/unit/integrations/launch_darkly/test_services.py::test_process_import_request__segments_imported - AssertionError: assert 'NONE' == 'ANY'
  - ANY
  + NONE
matthewelwell commented 1 month ago

Closed as we haven't seen any further occurrences of this.

matthewelwell commented 1 month ago

Coincidentally, I think we saw another occurrence of this today, here.