Search documentation of snmpkit

# SnmpKit.SnmpSim.TestHelpers (snmpkit v1.3.17)

Comprehensive SNMP testing utilities for SnmpSim.

This module provides a rich set of testing utilities for SNMP simulation, performance testing, stability testing, and production validation.

# Summary

## Functions

analyze_response_times(response_times)

Analyzes response time statistics.

calculate_error_rate(error_count, total_count)

Calculates error rate as a percentage.

check_system_health()

Monitors system health metrics.

cleanup_devices(devices)

Cleans up test devices and resources with enhanced error handling.

cleanup_monitored_devices(monitored_devices)

Cleanup monitored devices with enhanced tracking.

cleanup_single_device(device)

Cleanup a single device with robust error handling.

create_monitored_test_devices(opts \\ [])

Create test devices with monitoring and automatic cleanup tracking. Returns devices with monitor references for better cleanup handling.

create_test_devices(opts \\ [])

Creates test devices with various configurations.

create_test_walk_data(oid_count \\ 100)

Creates test SNMP walk data for testing.

generate_bulk_test_data(device_count, operations_per_device)

Generates test data for bulk operations.

inject_delay(delay_ms)

Injects artificial delays for testing timeout scenarios.

measure_response_time(fun)

Measures the response time of an operation.

perform_test_operations(device, operations \\ [:get, :get_next, :get_bulk, :walk])

Performs various SNMP operations on a device for testing.

reset_system_state()

Resets system state for testing.

run_load_test(devices, opts \\ [])

Runs a load test against a set of devices.

simulate_network_conditions(opts \\ [])

Simulates network conditions (packet loss, delays).

validate_snmp_response(other)

Validates SNMP response format.

validate_system_invariants()

Validates system invariants during testing.

wait_for_condition(condition_fun, timeout_ms \\ 30000)

Waits for a condition to be met within a timeout.

# Functions

# analyze_response_times(response_times)

Analyzes response time statistics.

# calculate_error_rate(error_count, total_count)

Calculates error rate as a percentage.

# check_system_health()

Monitors system health metrics.

# cleanup_devices(devices)

Cleans up test devices and resources with enhanced error handling.

# cleanup_monitored_devices(monitored_devices)

Cleanup monitored devices with enhanced tracking.

# cleanup_single_device(device)

Cleanup a single device with robust error handling.

# create_monitored_test_devices(opts \\ [])

Create test devices with monitoring and automatic cleanup tracking. Returns devices with monitor references for better cleanup handling.

# create_test_devices(opts \\ [])

Creates test devices with various configurations.

## Options

- `:count` - Number of devices to create (default: 10)
- `:community` - SNMP community string (default: "public")
- `:host` - Host address (default: "127.0.0.1")
- `:port_start` - Starting port number (default: 30000)
- `:walk_file` - SNMP walk file to use (default: "priv/walks/cable_modem.walk")
- `:batch_size` - Create devices in batches (default: 10)
- `:delay_between_batches` - Delay between batches in ms (default: 100)

## Examples

    devices = TestHelpers.create_test_devices(count: 50)
    devices = TestHelpers.create_test_devices(count: 100, community: "private")

# create_test_walk_data(oid_count \\ 100)

Creates test SNMP walk data for testing.

# generate_bulk_test_data(device_count, operations_per_device)

Generates test data for bulk operations.

# inject_delay(delay_ms)

Injects artificial delays for testing timeout scenarios.

# measure_response_time(fun)

Measures the response time of an operation.

# perform_test_operations(device, operations \\ [:get, :get_next, :get_bulk, :walk])

Performs various SNMP operations on a device for testing.

# reset_system_state()

Resets system state for testing.

# run_load_test(devices, opts \\ [])

Runs a load test against a set of devices.

## Options

- `:duration_ms` - Test duration in milliseconds
- `:requests_per_second` - Target requests per second
- `:operation` - SNMP operation to perform (:get, :get_next, :get_bulk, :walk)
- `:monitor_memory` - Whether to monitor memory usage
- `:monitor_processes` - Whether to monitor process count

# simulate_network_conditions(opts \\ [])

Simulates network conditions (packet loss, delays).

# validate_snmp_response(other)

Validates SNMP response format.

# validate_system_invariants()

Validates system invariants during testing.

# wait_for_condition(condition_fun, timeout_ms \\ 30000)

Waits for a condition to be met within a timeout.