39
39
@context .markWithMetaTag ("mat" , "hear" )
40
40
class RecvDataProcessingTestSuite (context .BasicUsageTestSuite ):
41
41
"""
42
- A test suite that checks empty data with the multicast sender and receiver.
42
+ A test suite that validates the multicast sender and receiver's handling of empty data .
43
43
44
+ Test cases:
45
+ - Sending empty binary data.
46
+ - Sending empty data followed by a stop command.
44
47
"""
45
48
46
49
__module__ = "tests.test_hear_data_processing"
@@ -55,16 +58,18 @@ def test_multicast_sender_with_no_data(self) -> None:
55
58
theResult = False
56
59
fail_fixture = "SAY -X] RECV? != error"
57
60
_fixture_port_num = self ._always_generate_random_port_WHEN_called ()
61
+ _fixture_mcast_addr = "224.0.0.1"
58
62
try :
59
63
self .assertIsNotNone (_fixture_port_num )
60
64
self .assertIsInstance (_fixture_port_num , int )
65
+ self .assertIsNotNone (_fixture_mcast_addr )
61
66
_fixture_HEAR_args = [
62
67
"--port" ,
63
68
str (_fixture_port_num ),
64
69
"--groups" ,
65
- "'224.0.0.1 '" ,
70
+ f"' { _fixture_mcast_addr } '" ,
66
71
"--group" ,
67
- "'224.0.0.1 '" ,
72
+ f"' { _fixture_mcast_addr } '" ,
68
73
]
69
74
p = Process (
70
75
target = multicast .__main__ .main , name = "RECV" , args = (
@@ -77,7 +82,7 @@ def test_multicast_sender_with_no_data(self) -> None:
77
82
try :
78
83
sender = multicast .send .McastSAY ()
79
84
self .assertIsNotNone (sender )
80
- sender (group = '224.0.0.1' , port = _fixture_port_num , ttl = 1 , data = b'' )
85
+ sender (group = _fixture_mcast_addr , port = _fixture_port_num , ttl = 1 , data = b'' )
81
86
self .assertIsNotNone (p )
82
87
self .assertTrue (p .is_alive (), fail_fixture )
83
88
except Exception as _cause :
@@ -105,16 +110,17 @@ def test_multicast_sender_with_no_data_before_follow_by_stop(self) -> None:
105
110
theResult = False
106
111
fail_fixture = "SAY -X] HEAR? != error"
107
112
_fixture_port_num = self ._always_generate_random_port_WHEN_called ()
113
+ _fixture_mcast_addr = "224.0.0.1"
108
114
try :
109
115
self .assertIsNotNone (_fixture_port_num )
110
116
self .assertIsInstance (_fixture_port_num , int )
111
117
_fixture_HEAR_args = [
112
118
"--port" ,
113
119
str (_fixture_port_num ),
114
120
"--groups" ,
115
- "'224.0.0.1 '" ,
121
+ f"' { _fixture_mcast_addr } '" ,
116
122
"--group" ,
117
- "'224.0.0.1 '" ,
123
+ f"' { _fixture_mcast_addr } '" ,
118
124
]
119
125
p = Process (
120
126
target = multicast .__main__ .main ,
@@ -130,11 +136,11 @@ def test_multicast_sender_with_no_data_before_follow_by_stop(self) -> None:
130
136
try :
131
137
sender = multicast .send .McastSAY ()
132
138
self .assertIsNotNone (sender )
133
- sender (group = '224.0.0.1' , port = _fixture_port_num , ttl = 1 , data = b'' )
139
+ sender (group = _fixture_mcast_addr , port = _fixture_port_num , ttl = 1 , data = b'' )
134
140
self .assertIsNotNone (p )
135
141
self .assertTrue (p .is_alive (), fail_fixture )
136
142
while p .is_alive ():
137
- sender (group = "224.0.0.1" , port = _fixture_port_num , data = ["STOP" ])
143
+ sender (group = _fixture_mcast_addr , port = _fixture_port_num , data = ["STOP" ])
138
144
p .join (1 )
139
145
self .assertFalse (p .is_alive (), "HEAR ignored STOP" )
140
146
except Exception as _cause :
@@ -208,11 +214,20 @@ def test_handle_with_invalid_utf8_data(self) -> None:
208
214
request = (data , sock ), client_address = _fixture_client_addr , server = None
209
215
)
210
216
try :
217
+ # Mock the processing method
218
+ handler ._process = MagicMock ()
211
219
# Should silently ignore invalid UTF-8 data
212
220
handler .handle () # If no exception is raised, the test passes
213
221
# Verify handler state after processing invalid data
214
222
self .assertIsNone (handler .server ) # Server should remain None
215
223
self .assertEqual (handler .client_address , _fixture_client_addr )
224
+ # Verify no data was processed
225
+ handler ._process .assert_not_called ()
226
+ # Test with different invalid UTF-8 sequences
227
+ for invalid_data in [b'\xff ' , b'\xfe \xff ' , b'\xff \xff \xff ' ]:
228
+ handler .request = (invalid_data , sock )
229
+ handler .handle ()
230
+ handler ._process .assert_not_called ()
216
231
except Exception as e :
217
232
self .fail (f"Handler raised an unexpected exception: { e } " )
218
233
finally :
0 commit comments