|
4 | 4 |
|
5 | 5 | import errno
|
6 | 6 | import socket
|
| 7 | +import sys |
7 | 8 | import unittest
|
8 | 9 | from unittest.mock import MagicMock, Mock, patch
|
9 | 10 |
|
@@ -181,7 +182,7 @@ def test_set_mdns_port_socket_options_for_ip_version():
|
181 | 182 | netutils.set_mdns_port_socket_options_for_ip_version(sock, ("",), r.IPVersion.V4Only)
|
182 | 183 |
|
183 | 184 |
|
184 |
| -def test_add_multicast_member(): |
| 185 | +def test_add_multicast_member(caplog: pytest.LogCaptureFixture) -> None: |
185 | 186 | sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
186 | 187 | interface = "127.0.0.1"
|
187 | 188 |
|
@@ -221,6 +222,26 @@ def test_add_multicast_member():
|
221 | 222 | with patch("socket.socket.setsockopt"):
|
222 | 223 | assert netutils.add_multicast_member(sock, interface) is True
|
223 | 224 |
|
| 225 | + # Ran out of IGMP memberships is forgiving and logs about igmp_max_memberships on linux |
| 226 | + caplog.clear() |
| 227 | + with ( |
| 228 | + patch.object(sys, "platform", "linux"), |
| 229 | + patch("socket.socket.setsockopt", side_effect=OSError(errno.ENOBUFS, "No buffer space available")), |
| 230 | + ): |
| 231 | + assert netutils.add_multicast_member(sock, interface) is False |
| 232 | + assert "No buffer space available" in caplog.text |
| 233 | + assert "net.ipv4.igmp_max_memberships" in caplog.text |
| 234 | + |
| 235 | + # Ran out of IGMP memberships is forgiving and logs |
| 236 | + caplog.clear() |
| 237 | + with ( |
| 238 | + patch.object(sys, "platform", "darwin"), |
| 239 | + patch("socket.socket.setsockopt", side_effect=OSError(errno.ENOBUFS, "No buffer space available")), |
| 240 | + ): |
| 241 | + assert netutils.add_multicast_member(sock, interface) is False |
| 242 | + assert "No buffer space available" in caplog.text |
| 243 | + assert "net.ipv4.igmp_max_memberships" not in caplog.text |
| 244 | + |
224 | 245 |
|
225 | 246 | def test_bind_raises_skips_address():
|
226 | 247 | """Test bind failing in new_socket returns None on EADDRNOTAVAIL."""
|
|
0 commit comments