Skip to content

[CT-2026] Add proto serialization to automated event testing #6852

@jtcohen6

Description

@jtcohen6

Let's extend this test, so it validates serialization to proto (and thereby our proto schema definitions) in addition to JSON:

class TestEventJSONSerialization:
# attempts to test that every event is serializable to json.
# event types that take `Any` are not possible to test in this way since some will serialize
# just fine and others won't.
def test_all_serializable(self):
all_non_abstract_events = set(
get_all_subclasses(BaseEvent),
)
all_event_values_list = list(map(lambda x: x.__class__, sample_values))
diff = all_non_abstract_events.difference(set(all_event_values_list))
assert (
not diff
), f"test is missing concrete values in `sample_values`. Please add the values for the aforementioned event classes"
# make sure everything in the list is a value not a type
for event in sample_values:
assert type(event) != type
# if we have everything we need to test, try to serialize everything
for event in sample_values:
msg = msg_from_base_event(event)
msg_dict = msg_to_dict(msg)
try:
msg_json = msg_to_json(msg)
except Exception as e:
raise Exception(f"{event} is not serializable to json. Originating exception: {e}")

Metadata

Metadata

Assignees

Labels

repo ci/cdTesting and continuous integration for dbt-core + adapter pluginstech_debtBehind-the-scenes changes, with little direct impact on end-user functionality

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions