From d07e72748b4b2b9e866ae848cb03cf22df03b3d1 Mon Sep 17 00:00:00 2001 From: Matthew Elwell Date: Wed, 4 Mar 2026 20:38:35 +0000 Subject: [PATCH 1/4] Fix flaky integration test that was reliant on non-deterministic ordering --- .../identities/test_integration_identities.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/api/tests/integration/environments/identities/test_integration_identities.py b/api/tests/integration/environments/identities/test_integration_identities.py index ae16baa46445..34e3d0343b68 100644 --- a/api/tests/integration/environments/identities/test_integration_identities.py +++ b/api/tests/integration/environments/identities/test_integration_identities.py @@ -75,7 +75,7 @@ def test_get_feature_states_for_identity( # type: ignore[no-untyped-def] variant_1_percentage_allocation, variant_1_value, ) - create_mv_option_with_api( + variant_2_mvfo_id = create_mv_option_with_api( admin_client, project, multivariate_feature_id, # type: ignore[arg-type] @@ -125,9 +125,11 @@ def test_get_feature_states_for_identity( # type: ignore[no-untyped-def] feature_state_data = retrieve_feature_state_response.json() # now let's amend the data so that all identities should receive variant 2 - mv_values = feature_state_data["multivariate_feature_state_values"] - mv_values[0]["percentage_allocation"] = 0 - mv_values[1]["percentage_allocation"] = 100 + for mv_value in feature_state_data["multivariate_feature_state_values"]: + if mv_value["id"] == variant_2_mvfo_id: + mv_value["percentage_allocation"] = 100 + else: + mv_value["percentage_allocation"] = 0 # and PUT the data back update_feature_state_response = admin_client.put( From 646aef312d59bd6b1bd3b1b1f998f31738d70d22 Mon Sep 17 00:00:00 2001 From: Matthew Elwell Date: Wed, 4 Mar 2026 20:43:59 +0000 Subject: [PATCH 2/4] Fix flaky unit test that failed if the hashed percentage was 99 --- .../identities/test_unit_identities_views.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/api/tests/unit/environments/identities/test_unit_identities_views.py b/api/tests/unit/environments/identities/test_unit_identities_views.py index dff9ed67bead..57efb0b4bed1 100644 --- a/api/tests/unit/environments/identities/test_unit_identities_views.py +++ b/api/tests/unit/environments/identities/test_unit_identities_views.py @@ -1,4 +1,5 @@ import json +import logging import urllib from typing import Any from unittest import mock @@ -38,6 +39,9 @@ from projects.models import Project, UserProjectPermission from segments.models import Condition, Segment, SegmentRule +logger = logging.getLogger(__name__) +logger.setLevel(logging.DEBUG) + def test_should_return_identities_list_when_requested( environment: Environment, @@ -598,14 +602,9 @@ def test_identities_endpoint_returns_value_for_segment_if_rule_type_percentage_s segment=segment, type=SegmentRule.ALL_RULE ) - identity_percentage_value = get_hashed_percentage_for_object_ids( - [segment.id, identity.id] - ) Condition.objects.create( operator=PERCENTAGE_SPLIT, - value=int( - (identity_percentage_value + (1 - identity_percentage_value) / 2) * 100.0 - ), + value=100, rule=segment_rule, ) feature_segment = FeatureSegment.objects.create( From 691b894da5cbb8164d60f031bb4b81b6169990f7 Mon Sep 17 00:00:00 2001 From: Matthew Elwell Date: Wed, 4 Mar 2026 20:50:47 +0000 Subject: [PATCH 3/4] Use mvfo instead of value id --- .../environments/identities/test_integration_identities.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/tests/integration/environments/identities/test_integration_identities.py b/api/tests/integration/environments/identities/test_integration_identities.py index 34e3d0343b68..6657d7366be6 100644 --- a/api/tests/integration/environments/identities/test_integration_identities.py +++ b/api/tests/integration/environments/identities/test_integration_identities.py @@ -126,7 +126,7 @@ def test_get_feature_states_for_identity( # type: ignore[no-untyped-def] # now let's amend the data so that all identities should receive variant 2 for mv_value in feature_state_data["multivariate_feature_state_values"]: - if mv_value["id"] == variant_2_mvfo_id: + if mv_value["multivariate_feature_option"] == variant_2_mvfo_id: mv_value["percentage_allocation"] = 100 else: mv_value["percentage_allocation"] = 0 From 47c6c524729cdfb6f469c71aea0cf2eee97497f4 Mon Sep 17 00:00:00 2001 From: Matthew Elwell Date: Thu, 5 Mar 2026 09:11:33 +0000 Subject: [PATCH 4/4] Remove logging --- .../environments/identities/test_unit_identities_views.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/api/tests/unit/environments/identities/test_unit_identities_views.py b/api/tests/unit/environments/identities/test_unit_identities_views.py index 57efb0b4bed1..86d2d6f2ecb6 100644 --- a/api/tests/unit/environments/identities/test_unit_identities_views.py +++ b/api/tests/unit/environments/identities/test_unit_identities_views.py @@ -1,5 +1,4 @@ import json -import logging import urllib from typing import Any from unittest import mock @@ -39,9 +38,6 @@ from projects.models import Project, UserProjectPermission from segments.models import Condition, Segment, SegmentRule -logger = logging.getLogger(__name__) -logger.setLevel(logging.DEBUG) - def test_should_return_identities_list_when_requested( environment: Environment,