tests.test_hear_cleanup

Test module for verifying cleanup behavior of the multicast hearing mechanism.

This module contains test suites that verify proper resource cleanup and process termination when the multicast hearing process receives shutdown signals.

Module Contents

Classes

HearCleanupTestSuite

Test suite for verifying the cleanup behavior of the multicast hearing mechanism.

Data

__module__

API

tests.test_hear_cleanup.__module__[source]

‘tests’

class tests.test_hear_cleanup.HearCleanupTestSuite(methodName='runTest')[source][source]

Bases: context.BasicUsageTestSuite

Test suite for verifying the cleanup behavior of the multicast hearing mechanism.

This suite tests that the McastHEAR class correctly releases resources and terminates gracefully when the hearing process receives a “STOP Test” message. It ensures that sockets are properly closed and no lingering processes remain after execution, adhering to the expected cleanup protocols.

Initialization

Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.

__module__[source]

‘tests.test_hear_cleanup’

__name__[source]

‘tests.test_hear_cleanup.HearCleanupTestSuite’

STOP_DELAY_SECONDS: int[source]

1

Time to wait for server cleanup after sending STOP.

Must be > 0 to ensure server has an opportunity to handle messages.

KILL_DELAY_SECONDS: int[source]

3

Average time to wait for process completion after sending STOP before sending SIGKILL.

Should be sufficient for handling STOP messages but not too long.

PROCESS_TIMEOUT_SECONDS: int[source]

15

Maximum time to wait for process completion after sending STOP.

Should be sufficient for cleanup but not too long.

EXPECTED_STOP_EXIT_CODE: int[source]

0

Expected exit code when process receives STOP messages.

0 = success as per POSIX convention.

TEST_MULTICAST_GROUP: str[source]

‘224.0.0.1’

Standard multicast group address for testing.

test_cleanup_on_exit() None[source][source]

Test proper cleanup of McastHEAR when receiving STOP message.

Prerequisites: - Available test port (self._the_test_port) - Multicast group 224.0.0.1 accessible

Expected behavior: 1. Start McastHEAR process in daemon mode 2. Send “STOP Test” message 3. Verify process terminates cleanly 4. Ensure all resources are released

Success criteria: - Process exits with code 0 - No lingering processes or sockets

static get_default_ip() str[source][source]

Get the default IP address of the machine.

Determines the machine’s default IP address by creating a UDP socket connection to a reserved test IP address and retrieving the local socket address.

Uses 203.0.113.1 (TEST-NET-3) for RFC 5737 compliance. Port 59095 is chosen as an arbitrary high port number.

Args: None

Returns: str: The IP address of the default network interface.

Raises: CommandExecutionError: If the IP address cannot be determined.

Meta Testing:

    >>> ip = HearCleanupTestSuite.get_default_ip()
    >>> isinstance(ip, str)
    True
    >>> len(ip.split('.'))
    4
test_should_not_invoke_kill_func_when_handle_error_not_called() None[source][source]

Test that handle_error only conditionally calls kill_func on stop keyword.

Verifies that the server properly handles mocked requests without the STOP command and never calls the kill_func to free up server resources early.

Args: None (self is implicit)

Returns: None

Raises: AssertionError: If the test conditions are not met.

test_should_invoke_kill_func_when_handle_error_called() None[source][source]

Test that kill_func calls shutdown on the server instance.

Verifies that the server properly handles mocked requests with the STOP command and calls the kill_func to free up server resources.

Args: None (self is implicit)

Returns: None

Raises: AssertionError: If the test conditions are not met.