@@ -44,34 +44,50 @@ class McastHearTestSuite(context.BasicUsageTestSuite):
44
44
45
45
@staticmethod
46
46
def get_default_ip ():
47
+ """Get the default IP address of the machine.
48
+
49
+ Returns:
50
+ str: The IP address of the default network interface.
51
+
52
+ Note:
53
+ Uses 203.0.113.1 (TEST-NET-3) for RFC 5737 compliance.
54
+ Port 59095 is chosen as an arbitrary high port number.
55
+ """
47
56
try :
48
57
# Create a socket connection to an external address
49
58
s = socket .socket (socket .AF_INET , socket .SOCK_DGRAM )
50
59
# Connect to a public non-routable IP
51
60
s .connect (("203.0.113.1" , 59095 ))
52
61
# Get the IP address of the default interface
53
62
ip = s .getsockname ()[0 ]
63
+ except socket .error as e :
64
+ raise RuntimeError ("Failed to determine default IP" ) from e
54
65
finally :
55
66
s .close ()
56
67
return ip
57
68
58
-
59
69
class McastServerTestSuite (McastHearTestSuite ):
60
70
61
71
__module__ = """tests.test_hear_server"""
62
72
63
73
__name__ = """tests.test_hear_server.McastServerTestSuite"""
64
74
65
75
def test_handle_error_without_stop_in_request (self ):
76
+ """
77
+ Test McastServer.handle_error with a non-STOP request.
78
+
79
+ Verifies that the server properly handles requests without
80
+ the STOP command and cleans up resources.
81
+ """
66
82
theResult = False
67
- fail_fixture = str ("""Mock(BLAH) --> Handller -HEAR == error""" )
83
+ fail_fixture = str ("""Mock(BLAH) --> Handler -HEAR == error""" )
68
84
_fixture_port_num = self ._the_test_port
69
85
try :
70
86
self .assertIsNotNone (_fixture_port_num )
71
87
self .assertIsInstance (_fixture_port_num , int )
72
88
# Create an instance of McastServer
73
- server_adddress = ('224.0.0.1' , _fixture_port_num )
74
- server = multicast .hear .McastServer (server_adddress , multicast .hear .HearUDPHandler )
89
+ server_address = ('224.0.0.1' , _fixture_port_num )
90
+ server = multicast .hear .McastServer (server_address , multicast .hear .HearUDPHandler )
75
91
client_address = (self .get_default_ip (), _fixture_port_num )
76
92
# Mock a request not containing "STOP"
77
93
request = (str ("Regular message" ), multicast .genSocket ())
@@ -89,14 +105,14 @@ def test_handle_error_without_stop_in_request(self):
89
105
90
106
def test_handle_error_with_none_request (self ):
91
107
theResult = False
92
- fail_fixture = str ("""Mock(EMPTY) --X Handller -HEAR != Safe""" )
108
+ fail_fixture = str ("""Mock(EMPTY) --X Handler -HEAR != Safe""" )
93
109
_fixture_port_num = self ._the_test_port
94
110
try :
95
111
self .assertIsNotNone (_fixture_port_num )
96
112
self .assertIsInstance (_fixture_port_num , int )
97
113
# Create an instance of McastServer
98
- server_adddress = ('224.0.0.1' , _fixture_port_num )
99
- server = multicast .hear .McastServer (server_adddress , multicast .hear .HearUDPHandler )
114
+ server_address = ('224.0.0.1' , _fixture_port_num )
115
+ server = multicast .hear .McastServer (server_address , multicast .hear .HearUDPHandler )
100
116
client_address = (self .get_default_ip (), _fixture_port_num )
101
117
# Mock None as a request
102
118
request = None
0 commit comments