PYTHON-2512 Update Astrolabe's Workload Executor to use the unified test runner (#783)

This commit is contained in:
Julius Park 2021-11-11 15:00:17 -08:00 committed by GitHub
parent 99a413f81b
commit e1884b44df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 32 deletions

View File

@ -15,8 +15,6 @@ import unittest
from test.unified_format import UnifiedSpecTestMixinV1
from pymongo.monitoring import PoolCreatedEvent
class TestCreateEntities(unittest.TestCase):
def test_store_events_as_entities(self):
@ -53,7 +51,7 @@ class TestCreateEntities(unittest.TestCase):
self.assertIn("events1", final_entity_map)
self.assertGreater(len(final_entity_map["events1"]), 0)
for event in final_entity_map["events1"]:
self.assertEqual(type(event), PoolCreatedEvent)
self.assertIn("PoolCreatedEvent", event)
def test_store_all_others_as_entities(self):
self.scenario_runner = UnifiedSpecTestMixinV1()

View File

@ -226,7 +226,7 @@ class EventListenerUtil(CMAPListener, CommandListener):
if event_name in self._event_types:
super(EventListenerUtil, self).add_event(event)
for id in self._event_mapping[event_name]:
self.entity_map[id].append(event)
self.entity_map[id].append(str(event))
def _command_event(self, event):
if event.command_name.lower() not in self._ignore_commands:
@ -284,7 +284,7 @@ class EntityMapUtil(object):
self._entities[key] = value
def _create_entity(self, entity_spec):
def _create_entity(self, entity_spec, uri=None):
if len(entity_spec) != 1:
self.test.fail(
"Entity spec %s did not contain exactly one top-level key" % (
@ -315,6 +315,8 @@ class EntityMapUtil(object):
kwargs['server_api'] = ServerApi(
server_api['version'], strict=server_api.get('strict'),
deprecation_errors=server_api.get('deprecationErrors'))
if uri:
kwargs['h'] = uri
client = rs_or_single_client(**kwargs)
self[spec['id']] = client
self.test.addCleanup(client.close)
@ -366,9 +368,9 @@ class EntityMapUtil(object):
self.test.fail(
'Unable to create entity of unknown type %s' % (entity_type,))
def create_entities_from_spec(self, entity_spec):
def create_entities_from_spec(self, entity_spec, uri=None):
for spec in entity_spec:
self._create_entity(spec)
self._create_entity(spec, uri=uri)
def get_listener_for_client(self, client_name):
client = self[client_name]
@ -718,7 +720,6 @@ class UnifiedSpecTestMixinV1(IntegrationTest):
def setUpClass(cls):
# super call creates internal client cls.client
super(UnifiedSpecTestMixinV1, cls).setUpClass()
# process file-level runOnRequirements
run_on_spec = cls.TEST_SPEC.get('runOnRequirements', [])
if not cls.should_run_on(run_on_spec):
@ -733,7 +734,6 @@ class UnifiedSpecTestMixinV1(IntegrationTest):
def setUp(self):
super(UnifiedSpecTestMixinV1, self).setUp()
# process schemaVersion
# note: we check major schema version during class generation
# note: we do this here because we cannot run assertions in setUpClass
@ -1080,15 +1080,14 @@ class UnifiedSpecTestMixinV1(IntegrationTest):
successes_key = spec.get('storeSuccessesAsEntity')
iteration_key = spec.get('storeIterationsAsEntity')
iteration_limiter_key = spec.get('numIterations')
if failure_key:
self.entity_map[failure_key] = []
if error_key:
self.entity_map[error_key] = []
if successes_key:
self.entity_map[successes_key] = 0
if iteration_key:
self.entity_map[iteration_key] = 0
for i in [failure_key, error_key]:
if i:
self.entity_map[i] = []
for i in [successes_key, iteration_key]:
if i:
self.entity_map[i] = 0
i = 0
global IS_INTERRUPTED
while True:
if iteration_limiter_key and i >= iteration_limiter_key:
break
@ -1096,24 +1095,24 @@ class UnifiedSpecTestMixinV1(IntegrationTest):
if IS_INTERRUPTED:
break
try:
if iteration_key:
self.entity_map._entities[iteration_key] += 1
for op in spec["operations"]:
self.run_entity_operation(op)
if successes_key:
self.entity_map._entities[successes_key] += 1
if iteration_key:
self.entity_map._entities[iteration_key] += 1
except AssertionError as exc:
if failure_key or error_key:
self.entity_map[failure_key or error_key].append({
"error": exc, "time": time.time()})
else:
raise exc
except Exception as exc:
if error_key or failure_key:
self.entity_map[error_key or failure_key].append(
{"error": exc, "time": time.time()})
if isinstance(exc, AssertionError):
key = failure_key or error_key
else:
raise exc
key = error_key or failure_key
if not key:
raise
self.entity_map[key].append({
"error": str(exc),
"time": time.time(),
"type": type(exc).__name__
})
def run_special_operation(self, spec):
opname = spec['name']
@ -1174,7 +1173,7 @@ class UnifiedSpecTestMixinV1(IntegrationTest):
self.assertListEqual(sorted_expected_documents,
actual_documents)
def run_scenario(self, spec):
def run_scenario(self, spec, uri=None):
# maybe skip test manually
self.maybe_skip_test(spec)
@ -1191,8 +1190,7 @@ class UnifiedSpecTestMixinV1(IntegrationTest):
# process createEntities
self.entity_map = EntityMapUtil(self)
self.entity_map.create_entities_from_spec(
self.TEST_SPEC.get('createEntities', []))
self.TEST_SPEC.get('createEntities', []), uri=uri)
# process initialData
self.insert_initial_data(self.TEST_SPEC.get('initialData', []))