Skip to content

Commit

Permalink
SNOW-1728000 Cloud platform tests filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-mbobowski committed Oct 22, 2024
1 parent 1302e36 commit 19bc224
Show file tree
Hide file tree
Showing 3 changed files with 652 additions and 248 deletions.
87 changes: 78 additions & 9 deletions test/test_selector.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,87 @@
from test_suites import create_end_to_end_test_suites
from collections import OrderedDict
from test_suites import EndToEndTestSuite
from cloud_platform import CloudPlatform
import test_suit


# TestSelector is responsible for selecting a subset of tests to be run
# It is meant to filter tests by platform, cloud vendor or any other predicate needed
class TestSelector:

def selectTestsToBeRun(self, driver, nameSalt, schemaRegistryAddress, testPlatform, allowedTestsCsv):
test_suites = create_end_to_end_test_suites(driver, nameSalt, schemaRegistryAddress, testPlatform, allowedTestsCsv)
def selectTestsToBeRun(
self,
driver,
nameSalt,
schemaRegistryAddress,
testPlatform,
cloud_platform: CloudPlatform,
allowedTestsCsv: str,
):
test_suites = create_end_to_end_test_suites(
driver, nameSalt, schemaRegistryAddress, testPlatform
)
test_suites = self.__filter_by_allow_list(allowedTestsCsv, test_suites)
test_suites = self.__filter_by_test_platform(testPlatform, test_suites)
test_suites = self.__filter_by_cloud_platform(cloud_platform, test_suites)

print("Running", len(test_suites), "tests")

return [
single_end_to_end_test.test_instance
for single_end_to_end_test in test_suites.values()
]

def __filter_by_allow_list(
self,
allowedTestsCsv: str,
tests_to_be_filtered: OrderedDict[str, EndToEndTestSuite],
) -> OrderedDict[str, EndToEndTestSuite]:
# Return all suites or only selected subset
if allowedTestsCsv is None or allowedTestsCsv == "":
return tests_to_be_filtered
else:
testsToRun = dict(
(k, v)
for k, v in tests_to_be_filtered.items()
if k in allowedTestsCsv.split(",")
)
return testsToRun

def __filter_by_test_platform(
self,
test_platform: str,
tests_to_be_filtered: OrderedDict[str, EndToEndTestSuite],
) -> OrderedDict[str, EndToEndTestSuite]:
if test_platform == "apache":
return dict(
(k, v)
for k, v in tests_to_be_filtered.items()
if v.run_in_apache == True
)
elif test_platform == "confluent":
return dict(
(k, v)
for k, v in tests_to_be_filtered.items()
if v.run_in_confluent == True
)
elif test_platform == "clean":
return tests_to_be_filtered
else:
raise test_suit.test_utils.NonRetryableError(
"unknown testPlatform={}".format(test_platform)
)

if testPlatform == "apache":
return [single_end_to_end_test.test_instance for single_end_to_end_test in test_suites.values() if single_end_to_end_test.run_in_apache == True]
elif testPlatform == "confluent":
return [single_end_to_end_test.test_instance for single_end_to_end_test in test_suites.values() if single_end_to_end_test.run_in_confluent == True]
elif testPlatform == "clean":
return [single_end_to_end_test.test_instance for single_end_to_end_test in test_suites.values()]
def __filter_by_cloud_platform(
self,
cloud_platform: CloudPlatform,
tests_to_be_filtered: OrderedDict[str, EndToEndTestSuite],
) -> OrderedDict[str, EndToEndTestSuite]:
if cloud_platform == CloudPlatform.ALL:
return tests_to_be_filtered
else:
raise test_suit.test_utils.NonRetryableError("unknown testPlatform={}".format(testPlatform))
return dict(
(k, v)
for k, v in tests_to_be_filtered.items()
if v.cloud_platform == cloud_platform
)
Loading

0 comments on commit 19bc224

Please sign in to comment.