From a63043f5eedef83e3587732fd4f41b4909adcb33 Mon Sep 17 00:00:00 2001 From: Jarkko Jaakola Date: Wed, 24 Jul 2024 12:30:04 +0300 Subject: [PATCH] test exc --- karapace/protobuf/io.py | 14 +++--- tests/unit/test_protobuf_serialization.py | 60 ----------------------- 2 files changed, 7 insertions(+), 67 deletions(-) diff --git a/karapace/protobuf/io.py b/karapace/protobuf/io.py index 3cc7445dc..6f4896a0b 100644 --- a/karapace/protobuf/io.py +++ b/karapace/protobuf/io.py @@ -256,13 +256,13 @@ def writer_process( # Writing happens in the forked process, catch is broad so exception will get communicated # back to calling process. except Exception as bare_exception: # pylint: disable=broad-exception-caught - try: - raise ProtobufTypeException(writer_schema, datum) from bare_exception - except ProtobufTypeException as protobuf_exception: - writer_queue.put(protobuf_exception) - raise protobuf_exception - except BaseException as base_exception: # pylint: disable=broad-exception-caught - writer_queue.put(base_exception) + #try: + # raise ProtobufTypeException(writer_schema, datum) from bare_exception + #except ProtobufTypeException as protobuf_exception: + # writer_queue.put(protobuf_exception) + # raise protobuf_exception + writer_queue.put(bare_exception) + raise bare_exception writer_queue.put(class_instance.SerializeToString()) diff --git a/tests/unit/test_protobuf_serialization.py b/tests/unit/test_protobuf_serialization.py index ee2586d63..03b2b623b 100644 --- a/tests/unit/test_protobuf_serialization.py +++ b/tests/unit/test_protobuf_serialization.py @@ -215,63 +215,3 @@ async def test_happy_flow_references_two(default_config_path: Path): assert 1 in serializer.ids_to_schemas assert mock_protobuf_registry_client.method_calls == [call.get_schema("top"), call.get_schema_for_id(1)] - - -async def test_serialization_fails(default_config_path: Path): - mock_protobuf_registry_client = Mock() - get_latest_schema_future = asyncio.Future() - get_latest_schema_future.set_result( - (1, ParsedTypedSchema.parse(SchemaType.PROTOBUF, trim_margin(schema_protobuf)), Versioner.V(1)) - ) - mock_protobuf_registry_client.get_schema.return_value = get_latest_schema_future - - serializer = await make_ser_deser(default_config_path, mock_protobuf_registry_client) - with pytest.raises(InvalidMessageSchema): - schema = await serializer.get_schema_for_subject("top") - await serializer.serialize(schema, test_fail_objects_protobuf[0]) - - assert mock_protobuf_registry_client.method_calls == [call.get_schema("top")] - mock_protobuf_registry_client.reset_mock() - - with pytest.raises(InvalidMessageSchema): - schema = await serializer.get_schema_for_subject("top") - await serializer.serialize(schema, test_fail_objects_protobuf[1]) - - assert mock_protobuf_registry_client.method_calls == [call.get_schema("top")] - - -async def test_deserialization_fails(default_config_path: Path): - mock_protobuf_registry_client = Mock() - - deserializer = await make_ser_deser(default_config_path, mock_protobuf_registry_client) - invalid_header_payload = struct.pack(">bII", 1, 500, 500) - with pytest.raises(InvalidMessageHeader): - await deserializer.deserialize(invalid_header_payload) - - assert mock_protobuf_registry_client.method_calls == [] - mock_protobuf_registry_client.reset_mock() - - # wrong schema id (500) - invalid_data_payload = struct.pack(">bII", START_BYTE, 500, 500) - with pytest.raises(InvalidPayload): - await deserializer.deserialize(invalid_data_payload) - - assert mock_protobuf_registry_client.method_calls == [call.get_schema_for_id(500)] - - -async def test_deserialization_fails2(default_config_path: Path): - mock_protobuf_registry_client = Mock() - - deserializer = await make_ser_deser(default_config_path, mock_protobuf_registry_client) - invalid_header_payload = struct.pack(">bII", 1, 500, 500) - with pytest.raises(InvalidMessageHeader): - await deserializer.deserialize(invalid_header_payload) - - assert mock_protobuf_registry_client.method_calls == [] - mock_protobuf_registry_client.reset_mock() - - enc_bytes = b"\x00\x00\x00\x00\x01\x00\x02\x05\0x12" # wrong schema data (2) - with pytest.raises(InvalidPayload): - await deserializer.deserialize(enc_bytes) - - assert mock_protobuf_registry_client.method_calls == [call.get_schema_for_id(1)]