Binary Options Tools - Core Pre - Testing Framework
A comprehensive WebSocket testing and monitoring framework for the binary-options-tools-core-pre crate.
Overview
This framework provides advanced statistics tracking, connection monitoring, and testing capabilities for WebSocket-based applications. It wraps around the existing Client and ClientRunner architecture to provide detailed insights into connection performance and reliability.
Quick Start
1. Basic Usage
use ;
use ClientBuilder;
use Duration;
// Create your client and runner as usual
let = new
.
.build
.await?;
// Wrap with testing capabilities
let mut testing_wrapper = new
.with_stats_interval
.with_log_stats
.with_connection_timeout
.build;
// Start the wrapper (this will run the ClientRunner and begin collecting statistics)
testing_wrapper.start.await?;
// Use the client through the wrapper
let client = testing_wrapper.client;
// ... use client as normal ...
// Get statistics
let stats = testing_wrapper.get_stats.await;
println!;
// Stop the wrapper (graceful shutdown)
testing_wrapper.stop_and_shutdown.await?;
2. Run the Example
3. Run Tests
Features
✅ Currently Implemented
- Connection Statistics: Track attempts, successes, failures, disconnections
- Performance Metrics: Latency, uptime, throughput measurements
- Message Tracking: Count and data volume of sent/received messages
- Event History: Detailed log of connection events with timestamps
- Statistics Export: JSON and CSV export formats
- Real-time Monitoring: Configurable periodic statistics logging
- Testing Configuration: Flexible configuration for different testing scenarios
Statistics Collected
- Connection attempts, successes, failures, disconnections
- Average and last connection latency
- Total and current connection uptime
- Time since last disconnection
- Message counts and data volumes
- Throughput rates (messages/second, bytes/second)
- Connection success rate
- Event history with timestamps
Configuration Options
- Stats Interval: How often to collect and log statistics
- Log Stats: Whether to log statistics to console
- Track Events: Whether to track detailed connection events
- Max Reconnect Attempts: Maximum number of reconnection attempts
- Reconnect Delay: Delay between reconnection attempts
- Connection Timeout: Connection timeout duration
- Auto Reconnect: Whether to automatically reconnect on disconnection
API Reference
TestingWrapper
The main wrapper class that provides testing capabilities:
TestingWrapperBuilder
Builder pattern for creating testing wrappers:
ConnectionStats
Statistics structure with comprehensive metrics:
Advanced Usage
Creating a Custom Testing Platform
Exporting Statistics
// Export to JSON
let json_stats = testing_wrapper.export_stats_json.await?;
println!;
// Export to CSV
let csv_stats = testing_wrapper.export_stats_csv.await?;
println!;
Examples
docs/examples/testing_echo_client.rs- Complete example with performance testingtests/testing_wrapper_tests.rs- Unit tests demonstrating usage
Future Enhancements
See docs/testing-framework.md for planned features including:
- Scheduled function calls
- Advanced monitoring capabilities
- Performance benchmarking
- Enhanced kanal integration
- Reporting and visualization
- Configuration management
Contributing
When adding new features:
- Update the statistics structures if new metrics are needed
- Add appropriate tracking in the
StatisticsTracker - Update the documentation
- Add examples demonstrating new features
- Consider backward compatibility
License
This framework is part of the binary-options-tools-core-pre crate and follows the same license.