import pytest
import asyncio
from hypothesis import given, strategies as st
from robobench.core.integration import IntegrationBenchmark, APIMetrics
from unittest.mock import patch, MagicMock

@pytest.fixture
def integration_benchmark(mock_model_name):
    return IntegrationBenchmark(mock_model_name)

@pytest.mark.asyncio
async def test_websocket_connection(integration_benchmark):
    with patch('websockets.connect') as mock_connect:
        mock_ws = MagicMock()
        mock_ws.__aenter__.return_value = mock_ws
        mock_ws.recv.return_value = '{"type": "message"}'
        mock_connect.return_value = mock_ws

        metrics = await integration_benchmark._measure_websocket_performance()
        assert metrics["latency"] > 0
        assert metrics["throughput"] >= 0

@given(st.integers(min_value=1, max_value=100))
@pytest.mark.asyncio
async def test_concurrent_requests(integration_benchmark, num_requests):
    with patch('aiohttp.ClientSession') as mock_session:
        mock_response = MagicMock()
        mock_response.status = 200
        mock_response.__aenter__.return_value = mock_response

        results = await integration_benchmark._send_concurrent_requests(
            "model:quant",
            num_requests
        )
        assert len(results) == num_requests
