@@ -246,24 +246,24 @@ def load_buffer_size() -> int:
246246 """
247247 Load and validate the multicast buffer size from environment variable.
248248
249- This function attempts to load the buffer size from the MULTICAST_PORT
250- environment variable. If the value is valid, it updates the global
251- _MCAST_DEFAULT_PORT. Invalid values trigger warnings and fall back to
252- the default.
253-
254- Returns:
255- int: The validated port number to use for multicast operations.
256- Returns the default port if the environment value is invalid.
257-
258- Raises:
259- ImportError: If the multicast module cannot be imported.
260-
261- Load buffer size from environment variables.
262-
263249 This function attempts to load the buffer size from the MULTICAST_BUFFER_SIZE
264250 environment variable. If the value is valid, it returns the buffer size.
265251 Invalid values trigger warnings and fall back to the default.
266252
253+ MTU Considerations for Buffer Size:
254+ When setting a buffer size, consider the MTU of the underlying network:
255+ - Ethernet: 1500 bytes MTU → 1472 bytes max payload (1500 - 28 bytes overhead)
256+ - PPP: 296 bytes MTU → 268 bytes max payload
257+ - Wi-Fi (802.11): 2304 bytes MTU → 2276 bytes max payload
258+ - Frame Relay: 128 bytes MTU → 100 bytes max payload
259+
260+ The overhead consists of:
261+ - UDP header: 8 bytes
262+ - IP header: 20 bytes (without options)
263+
264+ Setting buffer sizes larger than the network's max payload may cause IP
265+ fragmentation, which can lead to performance issues and increased complexity.
266+
267267 Returns:
268268 int: The validated buffer size, or the default value if not set/invalid.
269269
@@ -274,19 +274,23 @@ def load_buffer_size() -> int:
274274 ImportError: If the multicast module cannot be imported.
275275
276276 Minimum Acceptance Testing:
277+
278+ Testcase 0: Setup test fixtures.
277279 >>> import os
278280 >>> from multicast import _MCAST_DEFAULT_BUFFER_SIZE
279281 >>> original_buffer = _MCAST_DEFAULT_BUFFER_SIZE
280282
281- >>> # Test with valid environment variable
283+ Testcase 1: Test with valid environment variable
282284 >>> os.environ["MULTICAST_BUFFER_SIZE"] = "2048"
283285 >>> buffer_size = load_buffer_size()
284286 >>> buffer_size
285287 2048
286- >>> _MCAST_DEFAULT_BUFFER_SIZE != 2048 # Global should not be updated by this function
288+ >>> # The function updates the global in the module's namespace, but this doesn't affect
289+ >>> # the imported value in the test namespace
290+ >>> _MCAST_DEFAULT_BUFFER_SIZE != 2048 # Global in test namespace is not updated
287291 True
288292
289- >>> # Test with invalid (negative) environment variable
293+ Testcase 2: Test with invalid (negative) environment variable
290294 >>> os.environ["MULTICAST_BUFFER_SIZE"] = "-100"
291295 >>> import warnings
292296 >>> with warnings.catch_warnings(record=True) as w:
@@ -297,7 +301,7 @@ def load_buffer_size() -> int:
297301 >>> buffer_size == 1316 # Falls back to default
298302 True
299303
300- >>> # Test with invalid (zero) environment variable
304+ Testcase 3: Test with invalid (zero) environment variable
301305 >>> os.environ["MULTICAST_BUFFER_SIZE"] = "0"
302306 >>> with warnings.catch_warnings(record=True) as w:
303307 ... warnings.simplefilter("always")
@@ -307,7 +311,7 @@ def load_buffer_size() -> int:
307311 >>> buffer_size == 1316 # Falls back to default
308312 True
309313
310- >>> # Test with invalid (non-integer) environment variable
314+ Testcase 4: Test with invalid (non-integer) environment variable
311315 >>> os.environ["MULTICAST_BUFFER_SIZE"] = 'not_an_integer'
312316 >>> with warnings.catch_warnings(record=True) as w:
313317 ... warnings.simplefilter("always")
@@ -317,7 +321,7 @@ def load_buffer_size() -> int:
317321 >>> buffer_size == 1316 # Falls back to default
318322 True
319323
320- >>> # Test with no environment variable
324+ Testcase 5: Test with no environment variable
321325 >>> if "MULTICAST_BUFFER_SIZE" in os.environ: os.environ.pop("MULTICAST_BUFFER_SIZE")
322326 'not_an_integer'
323327 >>> buffer_size = load_buffer_size()
@@ -580,13 +584,15 @@ def load_TTL() -> int:
580584 ImportError: If the multicast module cannot be imported.
581585
582586 Minimum Acceptance Testing:
587+
588+ Testcase 0: Setup
583589 >>> import os
584590 >>> import socket
585591 >>> from multicast import _MCAST_DEFAULT_TTL
586592 >>> original_ttl = _MCAST_DEFAULT_TTL
587593 >>> original_timeout = socket.getdefaulttimeout()
588594
589- # Test with valid TTL
595+ Testcase 1: Test with valid TTL
590596 >>> os.environ['MULTICAST_TTL'] = '2'
591597 >>> ttl = load_TTL()
592598 >>> ttl
@@ -596,7 +602,7 @@ def load_TTL() -> int:
596602 >>> socket.getdefaulttimeout() == 2 # Socket timeout was updated
597603 True
598604
599- # Test with invalid numeric TTL
605+ Testcase 2: Test with invalid numeric TTL
600606 >>> os.environ['MULTICAST_TTL'] = '127'
601607 >>> import warnings
602608 >>> with warnings.catch_warnings(record=True) as w:
@@ -607,7 +613,7 @@ def load_TTL() -> int:
607613 >>> ttl == original_ttl # Falls back to original default
608614 True
609615
610- # Test with non-numeric TTL
616+ Testcase 3: Test with non-numeric TTL
611617 >>> os.environ['MULTICAST_TTL'] = 'invalid'
612618 >>> with warnings.catch_warnings(record=True) as w:
613619 ... warnings.simplefilter("always")
@@ -620,7 +626,7 @@ def load_TTL() -> int:
620626 'invalid'
621627 >>>
622628
623- # Test with unset environment variable
629+ Testcase 4: Test with unset environment variable
624630 >>> os.environ.pop('MULTICAST_TTL', None)
625631 >>> ttl = load_TTL()
626632 >>> ttl == original_ttl # Uses default
@@ -840,8 +846,9 @@ def load_config() -> dict:
840846 ... config = load_config()
841847 ... except ValueError:
842848 ... print('ValueError raised')
843- >>> config is None
844- False
849+ >>> # Verify config is not None (load_config should handle the error and use default)
850+ >>> config is not None
851+ True
845852
846853 # Cleanup
847854 >>> os.environ.pop('MULTICAST_BUFFER_SIZE', None)
0 commit comments