Clean up some radically dirty global state pollition to fix a flaky test
This commit is contained in:
committed by
Calen Pennington
parent
4a120a9e26
commit
0aa2edbc37
@@ -5,6 +5,7 @@ Module for running content split tests
|
||||
|
||||
import json
|
||||
import logging
|
||||
import threading
|
||||
from functools import reduce
|
||||
from operator import itemgetter
|
||||
from uuid import uuid4
|
||||
@@ -32,31 +33,41 @@ _ = lambda text: text
|
||||
DEFAULT_GROUP_NAME = _(u'Group ID {group_id}')
|
||||
|
||||
|
||||
class SplitTestFields(object):
|
||||
"""Fields needed for split test module"""
|
||||
has_children = True
|
||||
class UserPartitionValues(threading.local):
|
||||
"""
|
||||
A thread-local storage for available user_partitions
|
||||
"""
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.values = []
|
||||
|
||||
# All available user partitions (with value and display name). This is updated each time
|
||||
# editable_metadata_fields is called.
|
||||
user_partition_values = []
|
||||
# Default value used for user_partition_id
|
||||
no_partition_selected = {'display_name': _("Not Selected"), 'value': -1}
|
||||
|
||||
@staticmethod
|
||||
def build_partition_values(all_user_partitions, selected_user_partition):
|
||||
def build_partition_values(self, all_user_partitions, selected_user_partition):
|
||||
"""
|
||||
This helper method builds up the user_partition values that will
|
||||
be passed to the Studio editor
|
||||
"""
|
||||
SplitTestFields.user_partition_values = []
|
||||
self.values = []
|
||||
# Add "No selection" value if there is not a valid selected user partition.
|
||||
if not selected_user_partition:
|
||||
SplitTestFields.user_partition_values.append(SplitTestFields.no_partition_selected)
|
||||
self.values.append(SplitTestFields.no_partition_selected)
|
||||
for user_partition in get_split_user_partitions(all_user_partitions):
|
||||
SplitTestFields.user_partition_values.append(
|
||||
self.values.append(
|
||||
{"display_name": user_partition.name, "value": user_partition.id}
|
||||
)
|
||||
return SplitTestFields.user_partition_values
|
||||
return self.values
|
||||
|
||||
|
||||
# All available user partitions (with value and display name). This is updated each time
|
||||
# editable_metadata_fields is called.
|
||||
user_partition_values = UserPartitionValues()
|
||||
|
||||
|
||||
class SplitTestFields(object):
|
||||
"""Fields needed for split test module"""
|
||||
has_children = True
|
||||
|
||||
# Default value used for user_partition_id
|
||||
no_partition_selected = {'display_name': _("Not Selected"), 'value': -1}
|
||||
|
||||
display_name = String(
|
||||
display_name=_("Display Name"),
|
||||
@@ -77,7 +88,7 @@ class SplitTestFields(object):
|
||||
scope=Scope.content,
|
||||
display_name=_("Group Configuration"),
|
||||
default=no_partition_selected["value"],
|
||||
values=lambda: SplitTestFields.user_partition_values # Will be populated before the Studio editor is shown.
|
||||
values=lambda: user_partition_values.values # Will be populated before the Studio editor is shown.
|
||||
)
|
||||
|
||||
# group_id is an int
|
||||
@@ -478,7 +489,7 @@ class SplitTestDescriptor(SplitTestFields, SequenceDescriptor, StudioEditableDes
|
||||
@property
|
||||
def editable_metadata_fields(self):
|
||||
# Update the list of partitions based on the currently available user_partitions.
|
||||
SplitTestFields.build_partition_values(self.user_partitions, self.get_selected_partition())
|
||||
user_partition_values.build_partition_values(self.user_partitions, self.get_selected_partition())
|
||||
|
||||
editable_fields = super(SplitTestDescriptor, self).editable_metadata_fields
|
||||
|
||||
|
||||
Reference in New Issue
Block a user