ab ovo
This commit is contained in:
238
tests/test_main.zig
Normal file
238
tests/test_main.zig
Normal file
@@ -0,0 +1,238 @@
|
||||
//! Main test runner for the complete networking system
|
||||
//!
|
||||
//! This file imports and runs all core and network tests to provide
|
||||
//! comprehensive test coverage for the entire networking stack.
|
||||
|
||||
const std = @import("std");
|
||||
const testing = std.testing;
|
||||
|
||||
// Import core networking tests
|
||||
const CoreTests = @import("core/test_main.zig");
|
||||
|
||||
// Import network tests
|
||||
const NetworkTests = @import("network/test_main.zig");
|
||||
|
||||
pub fn main() !void {
|
||||
std.debug.print("Running Complete Networking System Tests...\n", .{});
|
||||
std.debug.print("=============================================\n", .{});
|
||||
|
||||
// Run core networking tests
|
||||
std.debug.print("\n--- Running Core Networking Tests ---\n", .{});
|
||||
try testCoreNetworking();
|
||||
|
||||
// Run network layer tests
|
||||
std.debug.print("\n--- Running Network Layer Tests ---\n", .{});
|
||||
try testNetworkLayer();
|
||||
|
||||
std.debug.print("\n=============================================\n", .{});
|
||||
std.debug.print("All Tests Completed Successfully!\n", .{});
|
||||
}
|
||||
|
||||
fn testCoreNetworking() !void {
|
||||
// Test error module integration
|
||||
try CoreTests.test_error_basic_operations();
|
||||
try CoreTests.test_error_context_operations();
|
||||
try CoreTests.test_error_stats_operations();
|
||||
std.debug.print("✓ Error module tests passed\n", .{});
|
||||
|
||||
// Test address module integration
|
||||
try CoreTests.test_ipv4_address_creation_and_parsing();
|
||||
try CoreTests.test_ipv4_address_properties();
|
||||
try CoreTests.test_ipv6_address_creation_and_operations();
|
||||
try CoreTests.test_unix_socket_address();
|
||||
try CoreTests.test_address_parsing_various_formats();
|
||||
try CoreTests.test_address_validation();
|
||||
try CoreTests.test_address_list_operations();
|
||||
try CoreTests.test_address_system_conversion();
|
||||
std.debug.print("✓ Address module tests passed\n", .{});
|
||||
|
||||
// Test buffer module integration
|
||||
try CoreTests.test_buffer_pool_configuration();
|
||||
try CoreTests.test_buffer_pool_creation_and_basic_operations();
|
||||
try CoreTests.test_stream_buffer_creation_and_operations();
|
||||
try CoreTests.test_packet_buffer_operations();
|
||||
try CoreTests.test_message_buffer_operations();
|
||||
try CoreTests.test_buffer_manager_operations();
|
||||
std.debug.print("✓ Buffer module tests passed\n", .{});
|
||||
|
||||
// Test socket module integration
|
||||
try CoreTests.test_socket_factory_creation();
|
||||
try CoreTests.test_socket_creation_with_config();
|
||||
try CoreTests.test_socket_state_management();
|
||||
try CoreTests.test_socket_binding();
|
||||
try CoreTests.test_socket_listening();
|
||||
try CoreTests.test_socket_options();
|
||||
try CoreTests.test_socket_statistics();
|
||||
try CoreTests.test_socket_manager_operations();
|
||||
std.debug.print("✓ Socket module tests passed\n", .{});
|
||||
|
||||
// Test connection module integration
|
||||
try CoreTests.test_connection_configuration();
|
||||
try CoreTests.test_connection_creation();
|
||||
try CoreTests.test_connection_statistics_tracking();
|
||||
try CoreTests.test_connection_state_transitions();
|
||||
try CoreTests.test_connection_health_checking();
|
||||
try CoreTests.test_connection_pool_operations();
|
||||
std.debug.print("✓ Connection module tests passed\n", .{});
|
||||
}
|
||||
|
||||
fn testNetworkLayer() !void {
|
||||
// Test peer management
|
||||
try NetworkTests.testPeerIdCreationAndManipulation();
|
||||
try NetworkTests.testPeerCreationAndInitialization();
|
||||
try NetworkTests.testPeerManagerBasicOperations();
|
||||
try NetworkTests.testPeerManagerConnectionStateTracking();
|
||||
std.debug.print("✓ Peer management tests passed\n", .{});
|
||||
|
||||
// Test discovery system
|
||||
try NetworkTests.testDiscoveryRequestCreationAndEncoding();
|
||||
try NetworkTests.testDiscoveryResponseCreationAndEncoding();
|
||||
try NetworkTests.testDiscoveryManagerInitialization();
|
||||
try NetworkTests.testDiscoveryManagerLifecycle();
|
||||
try NetworkTests.testMulticastDiscoveryConfiguration();
|
||||
std.debug.print("✓ Discovery system tests passed\n", .{});
|
||||
|
||||
// Test topology management
|
||||
try NetworkTests.testNetworkTopologyInitialization();
|
||||
try NetworkTests.testNodeAdditionToTopology();
|
||||
try NetworkTests.testConnectionManagementInTopology();
|
||||
try NetworkTests.testShortestPathFinding();
|
||||
try NetworkTests.testTopologyAnalysisMetrics();
|
||||
std.debug.print("✓ Topology management tests passed\n", .{});
|
||||
|
||||
// Test node management
|
||||
try NetworkTests.testNodeCreationAndInitialization();
|
||||
try NetworkTests.testNodeLifecycleManagement();
|
||||
try NetworkTests.testMessageProcessingAndRoutingDecisions();
|
||||
try NetworkTests.testRoutingInformationUpdates();
|
||||
std.debug.print("✓ Node management tests passed\n", .{});
|
||||
|
||||
// Test routing table
|
||||
try NetworkTests.testXORDistanceCalculation();
|
||||
try NetworkTests.testKademliaRoutingTableInitialization();
|
||||
try NetworkTests.testClosestPeersFinding();
|
||||
try NetworkTests.testRoutingTablePeerOperations();
|
||||
std.debug.print("✓ Routing table tests passed\n", .{});
|
||||
|
||||
// Run integration tests
|
||||
try NetworkTests.testNetworkIntegrationCompletePeerDiscoveryWorkflow();
|
||||
std.debug.print("✓ Integration tests passed\n", .{});
|
||||
|
||||
// Run stress tests
|
||||
try NetworkTests.testNetworkStressTestHighPeerCount();
|
||||
std.debug.print("✓ Stress tests passed\n", .{});
|
||||
}
|
||||
|
||||
// Test all modules together
|
||||
test "complete networking system integration" {
|
||||
// This test ensures that all modules work together correctly
|
||||
|
||||
// Test that core and network modules can be imported together
|
||||
const Address = @import("../src/core/address.zig").Address;
|
||||
const PeerId = @import("../src/network/peer.zig").PeerId;
|
||||
const DiscoveryManager = @import("../src/network/discovery.zig").DiscoveryManager;
|
||||
const NetworkTopology = @import("../src/network/topology.zig").NetworkTopology;
|
||||
|
||||
// Create instances from different modules
|
||||
const address = Address.init();
|
||||
const peer_id = PeerId.init();
|
||||
|
||||
try testing.expect(address.port == 0); // Default port
|
||||
try testing.expect(peer_id.bytes.len == 32); // Peer ID should be 32 bytes
|
||||
|
||||
// Test that topology can use peer IDs
|
||||
const allocator = testing.allocator;
|
||||
var topology = NetworkTopology.init(allocator, .Mesh);
|
||||
defer topology.deinit();
|
||||
|
||||
const node = try topology.addNode(peer_id, .Regular);
|
||||
try testing.expectEqual(peer_id, node.peer_id);
|
||||
|
||||
std.debug.print("Complete networking system integration test passed\n", .{});
|
||||
}
|
||||
|
||||
test "performance benchmarks" {
|
||||
// Benchmark key operations to ensure they meet performance requirements
|
||||
|
||||
const allocator = testing.allocator;
|
||||
|
||||
// Benchmark peer creation
|
||||
var start_time = std.time.timestamp();
|
||||
for (0..1000) |_| {
|
||||
const peer_id = PeerId.init();
|
||||
_ = peer_id;
|
||||
}
|
||||
var end_time = std.time.timestamp();
|
||||
try testing.expect(end_time - start_time < 2); // Should create 1000 peer IDs in < 2 seconds
|
||||
|
||||
// Benchmark address parsing
|
||||
start_time = std.time.timestamp();
|
||||
for (0..1000) |_| {
|
||||
const address = Address.init();
|
||||
_ = address;
|
||||
}
|
||||
end_time = std.time.timestamp();
|
||||
try testing.expect(end_time - start_time < 1); // Should create 1000 addresses in < 1 second
|
||||
|
||||
// Benchmark topology operations
|
||||
var topology = NetworkTopology.init(allocator, .Mesh);
|
||||
defer topology.deinit();
|
||||
|
||||
start_time = std.time.timestamp();
|
||||
for (0..100) |i| {
|
||||
const peer_id = PeerId.init();
|
||||
var address = Address.init();
|
||||
address.port = @as(u16, 8000 + i);
|
||||
_ = try topology.addNode(peer_id, .Regular);
|
||||
}
|
||||
end_time = std.time.timestamp();
|
||||
try testing.expect(end_time - start_time < 5); // Should add 100 nodes in < 5 seconds
|
||||
|
||||
std.debug.print("Performance benchmarks completed successfully\n", .{});
|
||||
}
|
||||
|
||||
test "memory usage validation" {
|
||||
// Ensure memory usage is reasonable and no leaks
|
||||
|
||||
const allocator = testing.allocator;
|
||||
|
||||
// Test peer manager memory usage
|
||||
{
|
||||
var manager = PeerModule.PeerManager.init(allocator);
|
||||
defer manager.deinit();
|
||||
|
||||
// Add and remove peers to test memory management
|
||||
for (0..100) |i| {
|
||||
var address = Address.init();
|
||||
address.port = @as(u16, 8000 + i);
|
||||
const peer = try manager.addPeer(address);
|
||||
peer.setState(.Connected);
|
||||
}
|
||||
|
||||
try testing.expectEqual(@as(usize, 100), manager.getPeerCount());
|
||||
|
||||
// Remove half the peers
|
||||
for (0..50) |i| {
|
||||
var address = Address.init();
|
||||
address.port = @as(u16, 8000 + i);
|
||||
_ = try manager.removePeerByAddress(address);
|
||||
}
|
||||
|
||||
try testing.expectEqual(@as(usize, 50), manager.getPeerCount());
|
||||
}
|
||||
|
||||
// Test topology memory usage
|
||||
{
|
||||
var topology = NetworkTopology.init(allocator, .Mesh);
|
||||
defer topology.deinit();
|
||||
|
||||
for (0..50) |i| {
|
||||
const peer_id = PeerId.init();
|
||||
_ = try topology.addNode(peer_id, .Regular);
|
||||
}
|
||||
|
||||
try testing.expectEqual(@as(usize, 50), topology.nodes.size());
|
||||
}
|
||||
|
||||
std.debug.print("Memory usage validation completed successfully\n", .{});
|
||||
}
|
||||
Reference in New Issue
Block a user