Skip to content

Commit

Permalink
add test_grpc_util
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuhu-kth committed Jul 16, 2024
1 parent e12c148 commit cf8a3e3
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions simulation-system/libs/csle-common/tests/test_grpc_util.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
import grpc
import pytest
from unittest.mock import patch, MagicMock
from csle_common.util.grpc_util import GrpcUtil


class TestGrpcUtilSuite:
"""
Test suite for grpc util
"""

@patch("grpc.channel_ready_future")
def test_grpc_server_on(self, mock_channel_ready_future) -> None:
"""
Test utility function to test if a given gRPC channel is working or not
:param mock_channel_ready_future: mock_channel_ready_future
:return: None
"""
mock_future = MagicMock()
mock_channel_ready_future.return_value = mock_future
result = GrpcUtil.grpc_server_on(mock_channel_ready_future)
mock_future.result.assert_called()
assert result

@patch("grpc.channel_ready_future")
def test_grpc_server_on_timeout(self, mock_channel_ready_future) -> None:
"""
Test utility function to test if a given gRPC channel is working or not
:param mock_channel_ready_future: mock_channel_ready_future
:return: None
"""
mock_future = MagicMock()
Expand All @@ -37,4 +38,3 @@ def test_grpc_server_on_timeout(self, mock_channel_ready_future) -> None:
result = GrpcUtil.grpc_server_on(mock_channel_ready_future)
mock_future.result.assert_called()
assert not result

0 comments on commit cf8a3e3

Please sign in to comment.