File tree 1 file changed +40
-0
lines changed
simulation-system/libs/csle-common/tests
1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change
1
+ import grpc
2
+ from unittest .mock import patch , MagicMock
3
+ from csle_common .util .grpc_util import GrpcUtil
4
+
5
+
6
+ class TestGrpcUtilSuite :
7
+ """
8
+ Test suite for grpc_util
9
+ """
10
+
11
+ @patch ("grpc.channel_ready_future" )
12
+ def test_grpc_server_on (self , mock_channel_ready_future ) -> None :
13
+ """
14
+ Test utility function to test if a given gRPC channel is working or not
15
+
16
+ :param mock_channel_ready_future: mock_channel_ready_future
17
+
18
+ :return: None
19
+ """
20
+ mock_future = MagicMock ()
21
+ mock_channel_ready_future .return_value = mock_future
22
+ result = GrpcUtil .grpc_server_on (mock_channel_ready_future )
23
+ mock_future .result .assert_called ()
24
+ assert result
25
+
26
+ @patch ("grpc.channel_ready_future" )
27
+ def test_grpc_server_on_timeout (self , mock_channel_ready_future ) -> None :
28
+ """
29
+ Test utility function to test if a given gRPC channel is not working
30
+
31
+ :param mock_channel_ready_future: mock_channel_ready_future
32
+
33
+ :return: None
34
+ """
35
+ mock_future = MagicMock ()
36
+ mock_future .result .side_effect = grpc .FutureTimeoutError ()
37
+ mock_channel_ready_future .return_value = mock_future
38
+ result = GrpcUtil .grpc_server_on (mock_channel_ready_future )
39
+ mock_future .result .assert_called ()
40
+ assert not result
You can’t perform that action at this time.
0 commit comments