|
20 | 20 | import grpc |
21 | 21 | from pydantic import BaseModel, ValidationError |
22 | 22 |
|
| 23 | +from dapr.conf import settings |
23 | 24 | from dapr.ext.workflow.dapr_workflow_context import DaprWorkflowContext |
24 | 25 | from dapr.ext.workflow.workflow_activity_context import WorkflowActivityContext |
25 | 26 | from dapr.ext.workflow.workflow_runtime import WorkflowRuntime, alternate_name |
@@ -830,3 +831,63 @@ def my_act(ctx, order: Optional[Order]): |
830 | 831 | wrapper = self.fake_registry._activity_fns['optional_no_default_act'] |
831 | 832 |
|
832 | 833 | self.assertIsNone(wrapper(mock.MagicMock(), None)) |
| 834 | + |
| 835 | + |
| 836 | +class WorkflowRuntimeChannelOptionsTest(unittest.TestCase): |
| 837 | + @mock.patch.object(settings, 'DAPR_GRPC_MAX_INBOUND_MESSAGE_SIZE_BYTES', 0) |
| 838 | + def test_explicit_kwarg_sets_symmetric_channel_options(self): |
| 839 | + with mock.patch( |
| 840 | + 'dapr.ext.workflow._durabletask.worker.TaskHubGrpcWorker' |
| 841 | + ) as mock_worker_cls: |
| 842 | + WorkflowRuntime(max_grpc_message_length=8 * 1024 * 1024) |
| 843 | + channel_options = mock_worker_cls.call_args[1]['channel_options'] |
| 844 | + self.assertEqual( |
| 845 | + [ |
| 846 | + ('grpc.max_send_message_length', 8 * 1024 * 1024), |
| 847 | + ('grpc.max_receive_message_length', 8 * 1024 * 1024), |
| 848 | + ], |
| 849 | + channel_options, |
| 850 | + ) |
| 851 | + |
| 852 | + @mock.patch.object(settings, 'DAPR_GRPC_MAX_INBOUND_MESSAGE_SIZE_BYTES', 16 * 1024 * 1024) |
| 853 | + def test_env_var_sets_symmetric_channel_options(self): |
| 854 | + with mock.patch( |
| 855 | + 'dapr.ext.workflow._durabletask.worker.TaskHubGrpcWorker' |
| 856 | + ) as mock_worker_cls: |
| 857 | + WorkflowRuntime() |
| 858 | + channel_options = mock_worker_cls.call_args[1]['channel_options'] |
| 859 | + self.assertEqual( |
| 860 | + [ |
| 861 | + ('grpc.max_send_message_length', 16 * 1024 * 1024), |
| 862 | + ('grpc.max_receive_message_length', 16 * 1024 * 1024), |
| 863 | + ], |
| 864 | + channel_options, |
| 865 | + ) |
| 866 | + |
| 867 | + @mock.patch.object(settings, 'DAPR_GRPC_MAX_INBOUND_MESSAGE_SIZE_BYTES', 16 * 1024 * 1024) |
| 868 | + def test_kwarg_takes_precedence_over_env_var(self): |
| 869 | + with mock.patch( |
| 870 | + 'dapr.ext.workflow._durabletask.worker.TaskHubGrpcWorker' |
| 871 | + ) as mock_worker_cls: |
| 872 | + WorkflowRuntime(max_grpc_message_length=8 * 1024 * 1024) |
| 873 | + channel_options = mock_worker_cls.call_args[1]['channel_options'] |
| 874 | + self.assertEqual( |
| 875 | + [ |
| 876 | + ('grpc.max_send_message_length', 8 * 1024 * 1024), |
| 877 | + ('grpc.max_receive_message_length', 8 * 1024 * 1024), |
| 878 | + ], |
| 879 | + channel_options, |
| 880 | + ) |
| 881 | + |
| 882 | + @mock.patch.object(settings, 'DAPR_GRPC_MAX_INBOUND_MESSAGE_SIZE_BYTES', 0) |
| 883 | + def test_neither_set_passes_none(self): |
| 884 | + with mock.patch( |
| 885 | + 'dapr.ext.workflow._durabletask.worker.TaskHubGrpcWorker' |
| 886 | + ) as mock_worker_cls: |
| 887 | + WorkflowRuntime() |
| 888 | + channel_options = mock_worker_cls.call_args[1]['channel_options'] |
| 889 | + self.assertIsNone(channel_options) |
| 890 | + |
| 891 | + |
| 892 | +if __name__ == '__main__': |
| 893 | + unittest.main() |
0 commit comments