Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/clusterfuzz/_internal/base/feature_flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class FeatureFlags(Enum):

PREPROCESS_QUEUE_SIZE_LIMIT = 'preprocess_queue_size_limit'

SWARMING_REMOTE_EXECUTION = 'swarming_remote_execution'

@property
def flag(self):
"""Get the feature flag."""
Expand Down
5 changes: 4 additions & 1 deletion src/clusterfuzz/_internal/swarming/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from google.protobuf import json_format

from clusterfuzz._internal.base import utils
from clusterfuzz._internal.base.feature_flags import FeatureFlags
from clusterfuzz._internal.config import local_config
from clusterfuzz._internal.datastore import data_types
from clusterfuzz._internal.google_cloud_utils import credentials
Expand All @@ -33,8 +34,10 @@ def _requires_gpu() -> bool:
return bool(utils.string_is_true(requires_gpu))


def is_swarming_task(command: str, job_name: str):
def is_swarming_task(command: str, job_name: str) -> bool:
"""Returns True if the task is supposed to run on swarming."""
if not FeatureFlags.SWARMING_REMOTE_EXECUTION.enabled:
return False
job = data_types.Job.query(data_types.Job.name == job_name).get()
if not job or not _requires_gpu():
return False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,11 @@ def test_get_and_set(self):
self.assertEqual(feature_flags.FeatureFlags.TEST_FLOAT_FLAG.content, 1.23)
self.assertEqual(feature_flags.FeatureFlags.TEST_FLOAT_FLAG.string_value,
'checker')

def test_not_found_in_db(self):
"""Test that a feature flag returns empty or False values when not found in the DB."""
self.assertFalse(feature_flags.FeatureFlags.TEST_FLAG.enabled)
self.assertIsNone(feature_flags.FeatureFlags.TEST_FLAG.flag)
self.assertIsNone(feature_flags.FeatureFlags.TEST_FLAG.content)
self.assertEqual(feature_flags.FeatureFlags.TEST_FLAG.description, '')
self.assertEqual(feature_flags.FeatureFlags.TEST_FLAG.string_value, '')
Loading